FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

fix safe area calculations with flat action bar · NativeScript/NativeScript@2d2144f · GitHub

Commit 2d2144f

Browse files
committed
fix safe area calculations with flat action bar
1 parent c3ee667 commit 2d2144f

3 files changed

Lines changed: 26 additions & 80 deletions

File tree

‎tests/app/ui/layouts/safe-area-tests.ts‎

Lines changed: 17 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -57,13 +57,22 @@ export class SafeAreaTests extends testModule.UITest<any> {
5757
};
5858
};
5959

60-
private layout_in_full_screen_test(layout: view.View) {
60+
private layout_in_full_screen_test(layout: view.View, pageOptions?: helper.PageOptions) {
61+
let expectedTop = 0;
62+
if (pageOptions && pageOptions.actionBarFlat) {
63+
const actionBarHeight = round(dipToDp(layout.page.actionBar.nativeViewProtected.frame.size.height));
64+
const app = iosUtils.getter(UIApplication, UIApplication.sharedApplication);
65+
const statusBarHeight = round(dipToDp(app.statusBarFrame.size.height));
66+
67+
expectedTop = actionBarHeight + statusBarHeight;
68+
}
69+
6170
const l = left(layout);
6271
const t = top(layout);
6372
const r = right(layout);
6473
const b = bottom(layout);
6574
equal(l, 0, `${layout}.left - actual:${l}; expected: ${0}`);
66-
equal(t, 0, `${layout}.top - actual:${t}; expected: ${0}`);
75+
equal(t, expectedTop, `${layout}.top - actual:${t}; expected: ${expectedTop}`);
6776
equal(r, platform.screen.mainScreen.widthPixels, `${layout}.right - actual:${r}; expected: ${platform.screen.mainScreen.widthPixels}`);
6877
equal(b, platform.screen.mainScreen.heightPixels, `${layout}.bottom - actual:${b}; expected: ${platform.screen.mainScreen.heightPixels}`);
6978
}
@@ -78,7 +87,7 @@ export class SafeAreaTests extends testModule.UITest<any> {
7887
this.getViews(snippet),
7988
this.noop,
8089
({ root }) => {
81-
this.layout_in_full_screen_test(root);
90+
this.layout_in_full_screen_test(root, pageOptions);
8291
},
8392
pageOptions
8493
);
@@ -130,10 +139,6 @@ export class SafeAreaTests extends testModule.UITest<any> {
130139
this.absolute_children_components_in_safe_area({ actionBarHidden: true });
131140
}
132141

133-
public test_absolute_children_components_in_safe_area_action_bar_flat() {
134-
this.absolute_children_components_in_safe_area({ actionBarFlat: true });
135-
}
136-
137142
public test_absolute_children_components_in_safe_area_tab_bar() {
138143
this.absolute_children_components_in_safe_area({ tabBar: true });
139144
}
@@ -175,10 +180,6 @@ export class SafeAreaTests extends testModule.UITest<any> {
175180
this.absolute_nested_layouts_beyond_safe_area({ actionBarHidden: true });
176181
}
177182

178-
public test_absolute_nested_layouts_beyond_safe_area_action_bar_flat() {
179-
this.absolute_nested_layouts_beyond_safe_area({ actionBarFlat: true });
180-
}
181-
182183
public test_absolute_nested_layouts_beyond_safe_area_tab_bar() {
183184
this.absolute_nested_layouts_beyond_safe_area({ tabBar: true });
184185
}
@@ -205,7 +206,7 @@ export class SafeAreaTests extends testModule.UITest<any> {
205206
this.getDockViews(snippet),
206207
this.noop,
207208
({ root }) => {
208-
this.layout_in_full_screen_test(root);
209+
this.layout_in_full_screen_test(root, pageOptions);
209210
},
210211
pageOptions
211212
);
@@ -272,10 +273,6 @@ export class SafeAreaTests extends testModule.UITest<any> {
272273
this.dock_children_components_in_safe_area({ actionBarHidden: true });
273274
}
274275

275-
public test_dock_children_components_in_safe_area_action_bar_flat() {
276-
this.dock_children_components_in_safe_area({ actionBarFlat: true });
277-
}
278-
279276
public test_dock_children_components_in_safe_area_tab_bar() {
280277
this.dock_children_components_in_safe_area({ tabBar: true });
281278
}
@@ -334,10 +331,6 @@ export class SafeAreaTests extends testModule.UITest<any> {
334331
this.dock_nested_layouts_beyond_safe_area({ actionBarHidden: true });
335332
}
336333

337-
public test_dock_nested_layouts_beyond_safe_area_action_bar_flat() {
338-
this.dock_nested_layouts_beyond_safe_area({ actionBarFlat: true });
339-
}
340-
341334
public test_dock_nested_layouts_beyond_safe_area_tab_bar() {
342335
this.dock_nested_layouts_beyond_safe_area({ tabBar: true });
343336
}
@@ -352,7 +345,7 @@ export class SafeAreaTests extends testModule.UITest<any> {
352345
this.getViews(snippet),
353346
this.noop,
354347
({ root }) => {
355-
this.layout_in_full_screen_test(root);
348+
this.layout_in_full_screen_test(root, pageOptions);
356349
},
357350
pageOptions
358351
);
@@ -409,10 +402,6 @@ export class SafeAreaTests extends testModule.UITest<any> {
409402
this.flex_column_children_components_in_safe_area({ actionBarHidden: true });
410403
}
411404

412-
public test_flex_column_children_components_in_safe_area_action_bar_flat() {
413-
this.flex_column_children_components_in_safe_area({ actionBarFlat: true });
414-
}
415-
416405
public test_flex_column_children_components_in_safe_area_tab_bar() {
417406
this.flex_column_children_components_in_safe_area({ tabBar: true });
418407
}
@@ -452,10 +441,6 @@ export class SafeAreaTests extends testModule.UITest<any> {
452441
this.flex_row_children_components_in_safe_area({ actionBarHidden: true });
453442
}
454443

455-
public test_flex_row_children_components_in_safe_area_action_bar_flat() {
456-
this.flex_row_children_components_in_safe_area({ actionBarFlat: true });
457-
}
458-
459444
public test_flex_row_children_components_in_safe_area_tab_bar() {
460445
this.flex_row_children_components_in_safe_area({ tabBar: true });
461446
}
@@ -502,10 +487,6 @@ export class SafeAreaTests extends testModule.UITest<any> {
502487
this.flex_column_nested_layouts_beyond_safe_area({ actionBarHidden: true });
503488
}
504489

505-
public test_flex_column_nested_layouts_beyond_safe_area_action_bar_flat() {
506-
this.flex_column_nested_layouts_beyond_safe_area({ actionBarFlat: true });
507-
}
508-
509490
public test_flex_column_nested_layouts_beyond_safe_area_tab_bar() {
510491
this.flex_column_nested_layouts_beyond_safe_area({ tabBar: true });
511492
}
@@ -552,10 +533,6 @@ export class SafeAreaTests extends testModule.UITest<any> {
552533
this.flex_row_nested_layouts_beyond_safe_area({ actionBarHidden: true });
553534
}
554535

555-
public test_flex_row_nested_layouts_beyond_safe_area_action_bar_flat() {
556-
this.flex_row_nested_layouts_beyond_safe_area({ actionBarFlat: true });
557-
}
558-
559536
public test_flex_row_nested_layouts_beyond_safe_area_tab_bar() {
560537
this.flex_row_nested_layouts_beyond_safe_area({ tabBar: true });
561538
}
@@ -583,7 +560,7 @@ export class SafeAreaTests extends testModule.UITest<any> {
583560
this.getGridViews(snippet),
584561
this.noop,
585562
({ root }) => {
586-
this.layout_in_full_screen_test(root);
563+
this.layout_in_full_screen_test(root, pageOptions);
587564
},
588565
pageOptions
589566
);
@@ -664,10 +641,6 @@ export class SafeAreaTests extends testModule.UITest<any> {
664641
this.grid_component_cells_layout_in_safe_area({ actionBarHidden: true });
665642
}
666643

667-
public test_grid_component_cells_layout_in_safe_area_action_bar_flat() {
668-
this.grid_component_cells_layout_in_safe_area({ actionBarFlat: true });
669-
}
670-
671644
public test_grid_component_cells_layout_in_safe_area_tab_bar() {
672645
this.grid_component_cells_layout_in_safe_area({ tabBar: true });
673646
}
@@ -729,10 +702,6 @@ export class SafeAreaTests extends testModule.UITest<any> {
729702
this.grid_nested_grid_cells_layout_beyond_safe_area({ actionBarHidden: true });
730703
}
731704

732-
public test_grid_nested_grid_cells_layout_beyond_safe_area_action_bar_flat() {
733-
this.grid_nested_grid_cells_layout_beyond_safe_area({ actionBarFlat: true });
734-
}
735-
736705
public test_grid_nested_grid_cells_layout_beyond_safe_area_tab_bar() {
737706
this.grid_nested_grid_cells_layout_beyond_safe_area({ tabBar: true });
738707
}
@@ -747,7 +716,7 @@ export class SafeAreaTests extends testModule.UITest<any> {
747716
this.getViews(snippet),
748717
this.noop,
749718
({ root }) => {
750-
this.layout_in_full_screen_test(root);
719+
this.layout_in_full_screen_test(root, pageOptions);
751720
},
752721
pageOptions
753722
);
@@ -799,10 +768,6 @@ export class SafeAreaTests extends testModule.UITest<any> {
799768
this.stack_horizontal_children_components_in_safe_area({ actionBarHidden: true });
800769
}
801770

802-
public test_stack_horizontal_children_components_in_safe_area_action_bar_flat() {
803-
this.stack_horizontal_children_components_in_safe_area({ actionBarFlat: true });
804-
}
805-
806771
public test_stack_horizontal_children_components_in_safe_area_tab_bar() {
807772
this.stack_horizontal_children_components_in_safe_area({ tabBar: true });
808773
}
@@ -837,10 +802,6 @@ export class SafeAreaTests extends testModule.UITest<any> {
837802
this.stack_vertical_children_components_in_safe_area({ actionBarHidden: true });
838803
}
839804

840-
public test_stack_vertical_children_components_in_safe_area_action_bar_flat() {
841-
this.stack_vertical_children_components_in_safe_area({ actionBarFlat: true });
842-
}
843-
844805
public test_stack_vertical_children_components_in_safe_area_tab_bar() {
845806
this.stack_vertical_children_components_in_safe_area({ tabBar: true });
846807
}
@@ -876,10 +837,6 @@ export class SafeAreaTests extends testModule.UITest<any> {
876837
this.stack_nested_layouts_beyond_safe_area({ actionBarHidden: true });
877838
}
878839

879-
public test_stack_nested_layouts_beyond_safe_area_action_bar_flat() {
880-
this.stack_nested_layouts_beyond_safe_area({ actionBarFlat: true });
881-
}
882-
883840
public test_stack_nested_layouts_beyond_safe_area_tab_bar() {
884841
this.stack_nested_layouts_beyond_safe_area({ tabBar: true });
885842
}
@@ -894,7 +851,7 @@ export class SafeAreaTests extends testModule.UITest<any> {
894851
this.getViews(snippet),
895852
this.noop,
896853
({ root }) => {
897-
this.layout_in_full_screen_test(root);
854+
this.layout_in_full_screen_test(root, pageOptions);
898855
},
899856
pageOptions
900857
);
@@ -948,10 +905,6 @@ export class SafeAreaTests extends testModule.UITest<any> {
948905
this.wrap_horizontal_children_components_in_safe_area({ actionBarHidden: true });
949906
}
950907

951-
public test_wrap_horizontal_children_components_in_safe_area_action_bar_flat() {
952-
this.wrap_horizontal_children_components_in_safe_area({ actionBarFlat: true });
953-
}
954-
955908
public test_wrap_horizontal_children_components_in_safe_area_tab_bar() {
956909
this.wrap_horizontal_children_components_in_safe_area({ tabBar: true });
957910
}
@@ -988,10 +941,6 @@ export class SafeAreaTests extends testModule.UITest<any> {
988941
this.wrap_vertical_children_components_in_safe_area({ actionBarHidden: true });
989942
}
990943

991-
public test_wrap_vertical_children_components_in_safe_area_action_bar_flat() {
992-
this.wrap_vertical_children_components_in_safe_area({ actionBarFlat: true });
993-
}
994-
995944
public test_wrap_vertical_children_components_in_safe_area_tab_bar() {
996945
this.wrap_vertical_children_components_in_safe_area({ tabBar: true });
997946
}
@@ -1025,10 +974,6 @@ export class SafeAreaTests extends testModule.UITest<any> {
1025974
this.wrap_nested_layouts_beyond_safe_area({ actionBarHidden: true });
1026975
}
1027976

1028-
public test_wrap_nested_layouts_beyond_safe_area_action_bar_flat() {
1029-
this.wrap_nested_layouts_beyond_safe_area({ actionBarFlat: true });
1030-
}
1031-
1032977
public test_wrap_nested_layouts_beyond_safe_area_tab_bar() {
1033978
this.wrap_nested_layouts_beyond_safe_area({ tabBar: true });
1034979
}

‎tns-core-modules/ui/core/view/view.ios.ts‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -780,12 +780,12 @@ export namespace ios {
780780
adjustedPosition.top = fullscreenPosition.top;
781781
}
782782

783-
if (inWindowRight < fullscreenPosition.right && inWindowRight >= safeAreaPosition.right) {
784-
adjustedPosition.right = fullscreenPosition.right;
783+
if (inWindowRight < fullscreenPosition.right && inWindowRight >= safeAreaPosition.right + fullscreenPosition.left) {
784+
adjustedPosition.right = fullscreenPosition.right - fullscreenPosition.left;
785785
}
786786

787-
if (inWindowBottom < fullscreenPosition.bottom && inWindowBottom >= safeAreaPosition.bottom) {
788-
adjustedPosition.bottom = fullscreenPosition.bottom;
787+
if (inWindowBottom < fullscreenPosition.bottom && inWindowBottom >= safeAreaPosition.bottom + fullscreenPosition.top) {
788+
adjustedPosition.bottom = fullscreenPosition.bottom - fullscreenPosition.top;
789789
}
790790

791791
const adjustedFrame = CGRectMake(layout.toDeviceIndependentPixels(adjustedPosition.left), layout.toDeviceIndependentPixels(adjustedPosition.top), layout.toDeviceIndependentPixels(adjustedPosition.right - adjustedPosition.left), layout.toDeviceIndependentPixels(adjustedPosition.bottom - adjustedPosition.top));

‎tns-core-modules/ui/page/page.ios.ts‎

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -311,10 +311,11 @@ export class Page extends PageBase {
311311
View.layoutChild(this, this.actionBar, 0, 0, actionBarWidth, actionBarHeight);
312312

313313
const insets = this.getSafeAreaInsets();
314-
const childLeft = left + insets.left;
315-
const childTop = top + insets.top;
316-
const childRight = right - insets.right;
317-
const childBottom = bottom - insets.bottom;
314+
315+
const childLeft = 0 + insets.left;
316+
const childTop = 0 + insets.top;
317+
const childRight = right - left - insets.right;
318+
const childBottom = bottom - top - insets.bottom;
318319
View.layoutChild(this, this.layoutView, childLeft, childTop, childRight, childBottom);
319320
}
320321

0 commit comments

Comments
 (0)

Back | FazBrowse Home | New Git URL