[iOS] Navigation back button appears when the app reloads


#1

Hi there, I am having an issue when my app reloads because of a change in the code, or just simply close the app and open it back, the navigation back button appears along with the drawer button. I have added my code below and attached a screenshot to show the issue.

<ActionBar class="action-bar" title="">
    <NavigationButton ios:visibility="collapsed" icon="res://menu" (tap)="onDrawerButtonTap()"></NavigationButton>
    <ActionItem icon="res://navigation/menu" android:visibility="collapsed" (tap)="onDrawerButtonTap()" ios.position="left"></ActionItem>
    <Label class="action-bar-title" text="Dashboard"></Label>
</ActionBar>

Any suggestion? Thanks…


#2

You can hide the iOS back button, like this

if (page.ios) {
        const controller = frameModule.topmost().ios.controller;
        // get the view controller navigation item
        const navigationItem = controller.visibleViewController.navigationItem;
        // hide back button
        navigationItem.setHidesBackButtonAnimated(true, false);
}

You have to do this in the onNavigatingTo handler

Cheers!

Happy NativeScripting


#3

Is that code only for Nativescript framework? I am using Angular.


#4

you should be able to use the same code in Angular as well.

you can do it in ngAfterViewInit

import * as frameModule from "ui/frame";

and I assume you already know to check if the platform is iOS


#5

You may consider bringing NavigationButton into picture only in case of Android using directives.


#6

Its not working for me, I have added the ngAfterViewInit method with the following data:

ngAfterViewInit() : void {
    if (isIOS) {
        const controller = frameModule.topmost().ios.controller;
        // get the view controller navigation item
       const navigationItem = controller.visibleViewController.navigationItem;
        // hide back button
        navigationItem.setHidesBackButtonAnimated(true, false);
    }
}

Also, my class is implementing both interfaces:

export class DashboardComponent implements OnInit, AfterViewInit {
...
}

I still see the back button and the drawer button. Curious thing is that after I updated to iOS 11.2 the issue appeared.

I just installed iOS 11.1 on my Mac and I can confirm that the issue is only on iOS 11.2. Seems like its a bug, can you confirm that?

Thanks!