Skip to content

Commit 4a67a3b

Browse files
authored
fix: dont create an actionbar if not necessary (#8402)
* fix: dont create an actionbar if not necessary For now i kept the commented code so that you can see the change. Also i changed the android check to behave like iOS * rollback. we now try an make sure the actionbar is created only if needed * actually we should check for false
1 parent 89ee60b commit 4a67a3b

2 files changed

Lines changed: 17 additions & 4 deletions

File tree

nativescript-core/ui/page/page-common.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ export class PageBase extends ContentView implements PageDefinition {
138138

139139
public eachChildView(callback: (child: View) => boolean) {
140140
super.eachChildView(callback);
141-
if (this.actionBar) {
141+
if (this.hasActionBar) {
142142
callback(this.actionBar);
143143
}
144144
}

nativescript-core/ui/page/page.android.ts

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,17 +45,30 @@ export class Page extends PageBase {
4545
@profile
4646
public onLoaded() {
4747
super.onLoaded();
48-
if (this.actionBarHidden !== undefined) {
48+
if (!this.hasActionBar && this.actionBarHidden !== true) {
49+
// ensure actionBar is created
50+
// but we only need to do that if the actionBarHidden is not hidden
51+
this.actionBar = new ActionBar();
52+
}
53+
if (this.hasActionBar) {
4954
this.updateActionBar();
5055
}
5156
}
5257

5358
private updateActionBar() {
54-
this.actionBar.update();
59+
// the test is actually to ensure the actionBar is created
60+
// it will be created if not
61+
if (this.actionBar) {
62+
this.actionBar.update();
63+
}
5564
}
5665

5766
[actionBarHiddenProperty.setNative](value: boolean) {
58-
this.updateActionBar();
67+
// in case the actionBar is not created and actionBarHidden is changed to true
68+
// the actionBar will be created by updateActionBar
69+
if (!value || this.hasActionBar) {
70+
this.updateActionBar();
71+
}
5972
}
6073

6174
[statusBarStyleProperty.getDefault](): { color: number, systemUiVisibility: number } {

0 commit comments

Comments
 (0)