From 982acdc168789d87b74cf4324963d2231ec509aa Mon Sep 17 00:00:00 2001 From: Vasil Chimev Date: Fri, 28 Sep 2018 18:21:50 +0300 Subject: [PATCH] feat(iOS): Safe Area Support (#6230) --- .gitignore | 3 +- apps/app/ui-tests-app/button/background.xml | 2 +- apps/app/ui-tests-app/button/issue-4287.xml | 2 +- apps/app/ui-tests-app/css/clip-path.xml | 2 +- .../css/margins-paddings-with-percentage.ts | 4 +- apps/app/ui-tests-app/issues/issue-1639.xml | 4 +- apps/app/ui-tests-app/issues/issue-3007.xml | 2 +- package.json | 2 +- tests/app/testRunner.ts | 12 +- tests/app/ui/helper.ts | 51 +- tests/app/ui/layouts/flexbox-layout-tests.ts | 459 ++--- tests/app/ui/layouts/grid-layout-tests.ts | 1 - tests/app/ui/layouts/layout-tests-helper.ts | 98 ++ tests/app/ui/layouts/safe-area-tests.ts | 1482 +++++++++++++++++ .../ui/list-view/list-view-safe-area-tests.ts | 225 +++ .../app/ui/list-view/list-view-view-model.ts | 19 + tests/app/ui/page/page-tests-common.ts | 46 +- tests/app/ui/page/page-tests.ios.ts | 442 ++--- .../scroll-view-safe-area-tests.ts | 461 +++++ tests/app/ui/styling/style-tests.ts | 108 +- tests/app/ui/view/view-tests-common.ts | 6 +- tests/package.json | 6 +- tns-core-modules/ui/core/view/view-common.ts | 10 +- tns-core-modules/ui/core/view/view.android.ts | 6 +- tns-core-modules/ui/core/view/view.d.ts | 33 +- tns-core-modules/ui/core/view/view.ios.ts | 327 ++-- .../absolute-layout/absolute-layout.ios.ts | 5 +- .../ui/layouts/dock-layout/dock-layout.ios.ts | 11 +- .../flexbox-layout/flexbox-layout.ios.ts | 59 +- .../ui/layouts/grid-layout/grid-layout.ios.ts | 6 +- .../ui/layouts/layout-base.ios.ts | 8 +- .../layouts/stack-layout/stack-layout.ios.ts | 26 +- .../ui/layouts/wrap-layout/wrap-layout.ios.ts | 46 +- .../ui/list-view/list-view-common.ts | 4 +- .../ui/list-view/list-view.ios.ts | 2 + tns-core-modules/ui/page/page.ios.ts | 13 +- tns-core-modules/ui/repeater/repeater.ts | 7 +- .../ui/scroll-view/scroll-view.ios.ts | 48 +- .../ui/web-view/web-view-common.ts | 4 +- 39 files changed, 3189 insertions(+), 863 deletions(-) create mode 100644 tests/app/ui/layouts/layout-tests-helper.ts create mode 100644 tests/app/ui/layouts/safe-area-tests.ts create mode 100644 tests/app/ui/list-view/list-view-safe-area-tests.ts create mode 100644 tests/app/ui/list-view/list-view-view-model.ts create mode 100644 tests/app/ui/scroll-view/scroll-view-safe-area-tests.ts diff --git a/.gitignore b/.gitignore index 6cd38c8e6..279bb0b08 100644 --- a/.gitignore +++ b/.gitignore @@ -36,6 +36,7 @@ e2e/**/test-results.xml # Webpack configuration files webpack.config.js tsconfig.esm.json +tsconfig.tns.json # Generated files *.map @@ -65,4 +66,4 @@ TestRunResult.txt tns-core-modules.base.d.ts tns-core-modules.d.ts -tns-core-modules.es6.d.ts \ No newline at end of file +tns-core-modules.es6.d.ts diff --git a/apps/app/ui-tests-app/button/background.xml b/apps/app/ui-tests-app/button/background.xml index 498a79b6a..7783eefeb 100644 --- a/apps/app/ui-tests-app/button/background.xml +++ b/apps/app/ui-tests-app/button/background.xml @@ -1,6 +1,6 @@ - + + + + `; + + this.executeSnippet( + this.getViews(snippet), + this.noop, + ({ root, child0, child1 }) => { + const insets = root.getSafeAreaInsets(); + equal(left(child0), insets.left, `${child0}.left - actual: ${left(child0)} expected: ${insets.left}`); + equal(top(child0), insets.top, `${child0}.top - actual: ${top(child0)} expected: ${insets.top}`); + equal(right(child0), width(root) - insets.right, `${child0}.right - actual: ${right(child0)} expected: ${width(root) - insets.right}`); + equal(bottom(child0), height(root) - insets.bottom, `${child0}.bottom - actual: ${bottom(child0)} expected: ${height(root) - insets.bottom}`); + equal(height(child1), 0, `${child1} has been laid out, but should not`); + equal(width(child1), 0, `${child1} has been laid out, but should not`); + }, + pageOptions + ); + } + + public test_wrap_horizontal_children_components_in_safe_area_action_bar() { + this.wrap_horizontal_children_components_in_safe_area({ actionBar: true }); + } + + public test_wrap_horizontal_children_components_in_safe_area_action_bar_hidden() { + this.wrap_horizontal_children_components_in_safe_area({ actionBarHidden: true }); + } + + public test_wrap_horizontal_children_components_in_safe_area_tab_bar() { + this.wrap_horizontal_children_components_in_safe_area({ tabBar: true }); + } + + private wrap_vertical_children_components_in_safe_area(pageOptions?: helper.PageOptions) { + const snippet = ` + + + + + `; + + this.executeSnippet( + this.getViews(snippet), + this.noop, + ({ root, child0, child1 }) => { + const insets = root.getSafeAreaInsets(); + equal(left(child0), insets.left, `${child0}.left - actual: ${left(child0)} expected: ${insets.left}`); + equal(top(child0), insets.top, `${child0}.top - actual: ${top(child0)} expected: ${insets.top}`); + equal(right(child0), width(root) - insets.right, `${child0}.right - actual: ${right(child0)} expected: ${width(root) - insets.right}`); + equal(bottom(child0), height(root) - insets.bottom, `${child0}.bottom - actual: ${bottom(child0)} expected: ${height(root) - insets.bottom}`); + equal(height(child1), 0, `${child1} has been laid out, but should not`); + equal(width(child1), 0, `${child1} has been laid out, but should not`); + }, + pageOptions + ); + } + + public test_wrap_vertical_children_components_in_safe_area_action_bar() { + this.wrap_vertical_children_components_in_safe_area({ actionBar: true }); + } + + public test_wrap_vertical_children_components_in_safe_area_action_bar_hidden() { + this.wrap_vertical_children_components_in_safe_area({ actionBarHidden: true }); + } + + public test_wrap_vertical_children_components_in_safe_area_tab_bar() { + this.wrap_vertical_children_components_in_safe_area({ tabBar: true }); + } + + private wrap_nested_layouts_beyond_safe_area(pageOptions?: helper.PageOptions) { + const snippet = ` + + +