Skip to content

<ios> and <android> tags do not work inside ActionBar #350

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
mishapinky opened this issue Jul 15, 2016 · 16 comments
Closed

<ios> and <android> tags do not work inside ActionBar #350

mishapinky opened this issue Jul 15, 2016 · 16 comments
Labels

Comments

@mishapinky
Copy link

There seems to be an issue when trying to use <ios> and <android> tags inside of an ActionBar that cause the app to crash.

 <ActionBar title="test">
      <ios>
          <ActionItem icon="res://ic_menu" ios.position="left" (tap)="openDrawer()"></ActionItem>
      </ios>
      <android>
          <NavigationButton icon="res://ic_menu" (tap)="openDrawer()"></NavigationButton>
      </android>
 </ActionBar>

However, outside of ActionBar this works.

<StackLayout class="mainStackLayout">
    <android>
        <Label [text]="mainContentText" textWrap="true" class="drawerContentText"></Label>
        <Button text="OPEN DRAWER" (tap)=openDrawer()></Button>
        <Button text="LIST VIEW" [nsRouterLink]="['/list']"></Button>
    </android>
    <ios>
        <Button text="ACCOUNT VIEW" [nsRouterLink]="['/account']"></Button>
    </ios>
</StackLayout>
@NickIliev
Copy link

NickIliev commented Jul 22, 2016

@vakrilov platform-specific attribute visibility is also not working (for both Android and iOS)
e.g.

<ActionBar title="Hello">
    <NavigationButton icon="res://icon" ios:visibility="collapse"></NavigationButton>
    <ActionItem icon="res://icon"  ios.position="left" android:visibility="collapse"></ActionItem>
</ActionBar>

@arnaudvalle , @mishapinky as a workaround for your Actionbars you can hide your Action items in NativeScript + Angular-2 using *ngIf directive. More information about this functionallity can be found at the following link: http://docs.nativescript.org/angular/ui/action-bar.html#hiding-action-items

Basically *ngIf directive removes or recreates a portion of your code (while expecting a boolean value)

For example:

<ActionBar title="Hello">
    <NavigationButton icon="res://icon" *ngIf="isNavVisible"></NavigationButton>
    <ActionItem icon="res://icon" ios.position="left" *ngIf="isItemVisible"></ActionItem>
</ActionBar>

import application = require("application");
@Component({
    selector: "my-app",
    templateUrl: "app.component.html",
})
export class AppComponent implements OnInit {

    isNavVisible:boolean = false;
    isItemVisible:boolean = false;

    ngOnInit() {
        if (application.ios) {
            this.isNavVisible = false;
            this.isItemVisible = true;
        } else if (application.android) {
            this.isNavVisible = true;
            this.isItemVisible = false;
        }
    }
}

@arnaudvalle
Copy link

@NickIliev just to confirm this works fine for me with your workaround. Thanks again!

@vakrilov
Copy link
Contributor

Just an update you can even define a set of if-platform directives that are similar to ngIf and you can use them instead of <ios> and <android>.
Here is gist with an implementation.

@robbdimitrov
Copy link

<ios>
    <ActionBar title="iOS" class="action-bar">
    
    </ActionBar>
</ios>
<android>
    <ActionBar title="Android" class="action-bar">
    
    </ActionBar>
</android>

March 2017 and this isn't working at all... Executes both sections on iOS. The code above produces 'Android' actionbar. Basically the last one is being applied.

@chrillewoodz
Copy link

I don't understand the whole ic_menu icon thing, according to this list:

https://developer.android.com/reference/android/R.drawable.html

That's not even an icon.. Needless to say it doesn't show up in my project when I try to use it.

@odubuc
Copy link

odubuc commented Apr 20, 2017

I have to agree with @robbdimitrov, this is still a bug in 2.5.4.
On both platform, the last ActionBar will always be applied and if it is inside it will not render..

I guess this should be re-opened or the documentation should be fixed since everyone reading it will end up here anyways...

Thanks for the workaround

@vakrilov vakrilov reopened this Apr 24, 2017
@vakrilov
Copy link
Contributor

Agree - reopening the issue since this is causing a lot of confusion.
For now you can fallback to this workaround.

@NickIliev can you add a note in the docs about <ios>/<android> directives not working inside the ActionBar?

@NickIliev
Copy link

@vakrilov Disclaimer added in the documentation article for ActionBar with this PR

@tsonevn
Copy link
Contributor

tsonevn commented Jun 13, 2017

Hi @ALL.
After a discussion, we conclude that the most appropriate way to define platform specific UI is to use custom directive for NativeScript Angular 2 project, which will verify the platform type and will show the needed HTML code.
For further help, you could review this example here, where a similar example is shown.

@tsonevn tsonevn closed this as completed Jun 13, 2017
@manojdcoder
Copy link

@tsonevn When it is essential and often used, why don't we ship it as built-in directive within NativeScript Angular package.

@tsonevn
Copy link
Contributor

tsonevn commented Jun 13, 2017

Hi @mishapinky,
This is only one way, which you could do that. You could also use some of available NG Directives, such as *ngIf. https://github.com/NativeScript/nativescript-sdk-examples-ng/tree/master/app/ui-category/ng-directives/ngif-directive. In this case, there is no need to built-in this custom directive within NativeScript Angular package

@bradmartin
Copy link

bradmartin commented Sep 13, 2017

@tsonevn - I won't pretend to know all the details about angular or the integration. I've been working on several NG apps lately and coming from plain NS background I always default to <android> & <ios> tags for platform specific nodes in my templates. Is there reasoning this doesn't work with the angular integration? What would it take to make this possible? After DevDays I wouldn't mind working on helping get this done. I am thinking something like the directive @vakrilov has come up with should ship with the core and be available or support for the platform nodes similar to plain NS apps. At any rate, any info on concerns or limitations from the team are appreciated.

@vakrilov
Copy link
Contributor

Hey @bradmartin. There are cases in which <android>/<ios> components do not work (for example in action-bar (the current issue). It is because the <android> and <ios> are actually regular components that have a conditional logic to show their contents (or not) based on the platform. However, you are not allowed to put just any component inside the action-bar - it should be an actionBarItem.
There might be other cases in which the <android> and <ios> do not work. Can you share some of your code so that we can investigate.

@ChirantanPatel
Copy link

hi @NickIliev
when I add Page tag in HTML view then Page tag between layout or context not display in IOS platform. In Android Platform working good. it's not working ios. so plz help me how to fix it. thanks in advance.

@NickIliev
Copy link

NickIliev commented Mar 16, 2018

@ChirantanPatel can you please provide a link to a sample project or Playground demo demonstrating your issue - not exactly sure what you mean by when I add Page tag in HTML view then Page tag between layout or context

@aosi87
Copy link

aosi87 commented Sep 2, 2020

still not working...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests