dashman
dashman

Reputation: 3018

Nativescript behavior of the '< Go Back' button

I've got the following ActionBar definition

<ActionBar class="action-bar" title="Settings"> <NavigationButton text="Go Back" android.systemIcon="ic_menu_back" tap="onBackTap"/> </ActionBar>

The Android version does get called.

In the iOS version - the onBackTap method is never called.

Also it seems in iOS version, even if the NavigationButton entry is not there, {N} inserts one automatically.

Upvotes: 2

Views: 8528

Answers (2)

dashman
dashman

Reputation: 3018

So as @nick verified, on iOS version of {N} one cannot get the tap event of the Navigation button. I understand why {N} has to add the BACK button automatically if the navigation button is not there (because iPhones don't have a physical BACK button), but not calling an existing tap event is, IMHO, adding unnecessary differences in the framework. Here's the proposed logic for iOS.

if NavigationButton present then if tap event handler set by user then use it else auto-gen a tap event handler else auto-gen a back-button and a tap event handler

Anyway here's how I'm getting around this issue for my app.

<NavigationButton visibility="collapse"/> <ActionItem ios.position="left" text="< Back" tap="onBack"/>

This gets the behavior I expect and is cross-platform compatible with the Android version.

Upvotes: 2

Nick Iliev
Nick Iliev

Reputation: 9670

UPDATE: Indeed, it appears that the NavigationButton in iOS can only be used to navigate back and can not be overridden with tap action. Reference from the NativeScript documentation

In iOS, the back button is used explicitly for navigation. It navigates to the previous page and you cannot handle the tap event to override this behaviour.

As for the appearing NavigationButton for iOS - it is by design just as in native iOS app. If you do not want to have back navigation you can force it with

clearHistory: true

Uncomment this line in the test application and delete the navigationButton from the sub-page and when navigation from main-page to sub-page the NavButton won't appear.

Upvotes: 2

Related Questions