2

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.

dashman
  • 2,858
  • 3
  • 29
  • 51
  • I've just learned something new, and to my surprise, it appears that indeed you can not override the default action for the NavigationBar in iOS. see the updated answer for details. – Nick Iliev Jan 27 '17 at 11:03
  • Thanks for the response. I just wanted to make sure I or my pc wasn't stir crazy since you had originally posted it should work. – dashman Jan 27 '17 at 11:41

2 Answers2

2

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.

Nick Iliev
  • 9,610
  • 3
  • 35
  • 89
  • 1
    Pretty sure I'm making the right call because it's working as expected on Android - but I will double check and get back in few hrs. As for the behavior of IOS BACK button - understood and makes sense. – dashman Jan 26 '17 at 13:25
  • Just tried it on the macOS - and it's not calling. I copied your secondary page verbatim and also copied the initiation of the navigation. The goBack function is not being called. I'd be more than happy to clone your project and try it - but I didn't see that option. Next step, I'll create a template project and start up. The only difference I saw was the config_bundle - I don't have that. – dashman Jan 26 '17 at 15:40
  • have you tried to run my application. The config_bundle should not be related to this one. Check the versions of your runtime and module in the package.json https://github.com/NickIliev/NativeScript-Issues-2017/blob/master/stackoverflow/navigationButtonIOS/package.json#L8-L15 – Nick Iliev Jan 26 '17 at 15:52
  • Ok I created a dummy app and copied your code over - BACK doesn't get called. If you have the time, can you please take a quick look - here's the zipped file https://drive.google.com/open?id=0B-uWY0k-Uw5iVVNsb2pvVFZYd3c. – dashman Jan 26 '17 at 17:36
  • For s&g I added ``. That works - goBack() gets called. – dashman Jan 26 '17 at 20:06
  • Thanks for your project! It helped me learn something new (see updated answer) about NavButton - as a workaround perhaps you can use ActionItem and hide the navigationButton with coming from page with `clearHistory:true` – Nick Iliev Jan 27 '17 at 11:04
2

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.

dashman
  • 2,858
  • 3
  • 29
  • 51