Skip to content

Commit c54e069

Browse files
ADjenkovAlexander Vakrilov
authored andcommitted
fix(ios-action-bar): NavigationButton cannot be hidden if navigating with transition (NativeScript#5451)
1 parent 4898c33 commit c54e069

File tree

4 files changed

+27
-5
lines changed

4 files changed

+27
-5
lines changed

tns-core-modules/ui/action-bar/action-bar-common.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -299,6 +299,12 @@ export class ActionItemBase extends ViewBase implements ActionItemDefinition {
299299
this.actionView = value;
300300
}
301301

302+
public _onVisibilityChanged(visibility: string) {
303+
if (this.actionBar) {
304+
this.actionBar.update();
305+
}
306+
}
307+
302308
public eachChild(callback: (child: ViewBase) => boolean) {
303309
if (this._actionView) {
304310
callback(this._actionView);
@@ -323,13 +329,17 @@ function onItemChanged(item: ActionItemBase, oldValue: string, newValue: string)
323329
}
324330
}
325331

332+
function onVisibilityChanged(item: ActionItemBase, oldValue: string, newValue: string) {
333+
item._onVisibilityChanged(newValue);
334+
}
335+
326336
export const textProperty = new Property<ActionItemBase, string>({ name: "text", defaultValue: "", valueChanged: onItemChanged });
327337
textProperty.register(ActionItemBase);
328338

329339
export const iconProperty = new Property<ActionItemBase, string>({ name: "icon", valueChanged: onItemChanged });
330340
iconProperty.register(ActionItemBase);
331341

332-
export const visibilityProperty = new Property({ name: "visibility", defaultValue: "visible", valueChanged: onItemChanged });
342+
export const visibilityProperty = new Property({ name: "visibility", defaultValue: "visible", valueChanged: onVisibilityChanged });
333343
visibilityProperty.register(ActionItemBase);
334344

335345
export const flatProperty = new Property<ActionBarBase, boolean>({ name: "flat", defaultValue: false, valueConverter: booleanConverter });

tns-core-modules/ui/action-bar/action-bar.android.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,6 @@ export class AndroidActionBarSettings implements AndroidActionBarSettingsDefinit
103103
}
104104

105105
export class NavigationButton extends ActionItem {
106-
//
107106
}
108107

109108
export class ActionBar extends ActionBarBase {

tns-core-modules/ui/action-bar/action-bar.d.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,12 @@ export interface AndroidActionBarSettings {
239239
* Represents the navigation (a.k.a. "back") button.
240240
*/
241241
export class NavigationButton extends ActionItem {
242-
242+
//@private
243+
/**
244+
* @private
245+
*/
246+
_navigationItem?: any
247+
//@endprivate
243248
}
244249

245250
/** @internal */

tns-core-modules/ui/action-bar/action-bar.ios.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,14 @@ export class ActionItem extends ActionItemBase {
4444
}
4545

4646
export class NavigationButton extends ActionItem {
47+
_navigationItem: UINavigationItem;
4748

49+
public _onVisibilityChanged(visibility: string): void {
50+
if (this._navigationItem) {
51+
const visible: boolean = visibility === "visible";
52+
this._navigationItem.setHidesBackButtonAnimated(!visible, true);
53+
}
54+
}
4855
}
4956

5057
export class ActionBar extends ActionBarBase {
@@ -82,7 +89,7 @@ export class ActionBar extends ActionBarBase {
8289
if (!navBar) {
8390
return { width: 0, height: 0 };
8491
}
85-
92+
8693
const frame = navBar.frame;
8794
const size = frame.size;
8895
const width = layout.toDevicePixels(size.width);
@@ -158,7 +165,8 @@ export class ActionBar extends ActionBarBase {
158165

159166
// Set back button visibility
160167
if (this.navigationButton) {
161-
navigationItem.setHidesBackButtonAnimated(!isVisible(this.navigationButton), true);
168+
this.navigationButton._navigationItem = navigationItem;
169+
navigationItem.setHidesBackButtonAnimated(!isVisible(this.navigationButton), false);
162170
}
163171

164172
// Populate action items

0 commit comments

Comments
 (0)