question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Dynamic binding for *tabItem directive to show selected iconSource

See original GitHub issue

Hi, I’m trying to make my tabItems dynamic. I’m trying to replace my icon.png the same way that it’s done on marketplace app.

I believe the tabItem directive gets wherever is on it’s ngOnInit and after that won’t update anymore. Are there any way to bind(watch) values, instead? So we could update the sourceIcon or text?

<TabView [(ngModel)]="selectedIndex">
    <StackLayout *tabItem="{title: 'Tab1', iconSource: selectedIndex == 1 ? 'res://icona' : 'res://icona1'}">
        <Label text="You are in Tab 1"></Label>
        <Label text="{{selectedIndex}}"></Label>
    </StackLayout>
    <StackLayout *tabItem="{title: 'Tab2', iconSource: selectedIndex == 1 ? 'res://iconb' : 'res://iconb1'}">
        <Label text="You are in Tab 2"></Label>
        <Label text="{{selectedIndex}}"></Label>
    </StackLayout>
</TabView>
export class AppComponent {
    public selectedIndex: number = 0;
}

My label shows the correct selectedIndex, but the Tab keeps as it is on load. If I set selectedIndex = 1 on my ngOnInit, shows the second tab selected tab, but after that, won’t change the icon. The tab works great.

Thanks

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:13 (9 by maintainers)

github_iconTop GitHub Comments

2reactions
nsndeckcommented, Jul 13, 2016

Yep this is online now. For more information how to used it just review ng-sample\app\examples\tab-view\tab-view-test.html first tab. The example shows a binding for title property, but I can ensure you that it also works for iconSource.

1reaction
Ihor912commented, Sep 6, 2018

Hi guys, This solution for me. Maybe it will help someone else.

I use two different icons for the selection state and for the inactive state. Also, property iosIconRenderingMode value should be “alwaysOriginal”.

In template:

<TabView tabBackgroundColor="#6E7AFA" androidTabsPosition="bottom" iosIconRenderingMode="alwaysOriginal" (selectedIndexChanged)="tabViewIndexChange($event)">
    <page-router-outlet *tabItem="homeTab" name="homeTab"></page-router-outlet>
    <page-router-outlet *tabItem="settingsTab" name="settingsTab"></page-router-outlet>
</TabView>

In component:

homeTab: any;
settingsTab: any;

constructor() {
    this.homeTab  = { iconSource: this.getIconSource("home") };
    this.settingsTab  = { iconSource: this.getIconSource("settings") };
}

tabViewIndexChange(args) {
    const index = args.newIndex;
    this.homeTab = { iconSource: this.getIconSource(index === 0 ? "home_selected" : "home") };
    this.settingsTab = { iconSource: this.getIconSource(index === 1 ? "settings_selected" : "settings") };
}

getIconSource(icon: string): string {
    const iconPrefix = isAndroid ? "res://" : "res://tabIcons/";
    return iconPrefix + icon;
}
Read more comments on GitHub >

github_iconTop Results From Across the Web

TabItem binding content dynamically - Stack Overflow
Trying to build a TabControl dynamically, but it won't bind the UserControl I've created. ... {Binding Content} does show a warning,
Read more >
TabView - NativeScript Docs
The TabView component provides a simple way to navigate between different views by tapping on some of the tabs or by swiping between...
Read more >
AdvancedTabControl - Docking & MDI Reference
Note that in MVVM scenarios, this will return the item that is selected and not the ... Normal tabs appear normally and left-aligned...
Read more >
- Welcome to Pega Platform
Adding WAI-ARIA roles to a Dynamic Layout; Adding a main content link to ... the Rule instruction to support a custom rule type;...
Read more >
Dynamically creating TabItems with one of the ... - MSDN
That TabItem with IsSelected = true will show the content but the tab itself stays in the background as if it's not selected....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found