Skip to content

[BottomNavigation] Icons in tab-strips items cannot be changed dynamically #7470

Closed

Description

@SvetoslavTsenov

Tested with tns-core-modules modules@6.0.0-rc-2019-07-04-184211-04

Trying to change icon source on tab strip when changing the selected tab strip item is not working and cannot be changed.

Please take a look into this bottom-navigation/icon-change-page.ts sample


Want to back this issue? Post a bounty on it! We accept bounties via Bountysource.

Activity

  1. changed the title [-]BottomNavigation icons in tabStrips cannot be changed dynamically[/-] [+]BottomNavigation icons in tab-strips items cannot be changed dynamically[/+] on Jul 5, 2019
  2. changed the title [-]BottomNavigation icons in tab-strips items cannot be changed dynamically[/-] [+][BottomNavigation] Icons in tab-strips items cannot be changed dynamically[/+] on Jul 8, 2019
  3. lhovee commented on Sep 5, 2019

    @lhovee

    I have a use case where attempting to swap an active icon when tab strip item is selected that doesn't work. Hoping we can re-open this ticket.

  4. lhovee commented on Sep 5, 2019

    @lhovee

    code is:

    <template>
      <Page>
        <BottomNavigation
          :selectedIndex="activeIndex"
          @selectedIndexChanged="activeIndexChange"
        >
          <TabStrip>
            <TabStripItem
              v-for="(item, index) in tabStripItems"
              :key="item.key"
            >
              <Label :text="item.text" />
              <Image :src="index === activeIndex ? item.activeIcon : item.icon" />
            </TabStripItem>
          </TabStrip>
    
          <TabContentItem
            v-for="(itm, idx) in tabStripItems"
            :key="idx"
          >
            <component
              :is="itm.component"
              :key="`${itm.key}-${idx}`"
              :title="itm.text"
            />
          </TabContentItem>
        </BottomNavigation>
      </Page>
    </template>
    
    <script lang="ts">
    import { Component } from 'vue-property-decorator';
    import Vue from 'nativescript-vue';
    import { SelectedIndexChangedEventData } from 'tns-core-modules/ui/bottom-navigation';
    import PlaceholderComponent from '@/components/PlaceholderComponent.vue';
    
    @Component({
      components: {
        PlaceholderComponent,
      },
    })
    export default class HomeRoot extends Vue {
      public activeIndex: number = 2;
      private tabStripItems = [
        {
          text: 'Account',
          key: 'account',
          icon: 'res://app/icon_account',
          activeIcon: 'res://app/icon_account_active',
          component: PlaceholderComponent,
        },
        {
          text: 'Rules',
          key: 'rules',
          icon: 'res://app/icon_rules',
          activeIcon: 'res://app/icon_rules_active',
          component: PlaceholderComponent,
        },
        {
          text: 'Home',
          key: 'home',
          icon: 'res://app/icon_home',
          activeIcon: 'res://app/icon_home_active',
          component: PlaceholderComponent,
        },
        {
          text: 'Activity',
          key: 'activity',
          icon: 'res://app/icon_activity',
          activeIcon: 'res://app/icon_activity_active',
          component: PlaceholderComponent,
        },
        {
          text: 'Devices',
          key: 'devices',
          icon: 'res://app/icon_devices',
          activeIcon: 'res://app/icon_devices_active',
          component: PlaceholderComponent,
        },
      ];
    
      public activeIndexChange(update: SelectedIndexChangedEventData): void {
        this.activeIndex = update.newIndex;
      }
    }
    </script>
    
    <style lang="scss" scoped>
    TabStripItem {
      color: grey;
    
      Label {
        text-transform: uppercase;
      }
    }
    
    TabStripItem:active {
      color: green;
    }
    </style>
    
  5. lhovee commented on Sep 5, 2019

    @lhovee

    where PlaceholderComponent.vue looks like

    <template>
      <GridLayout>
        <Label
          :text="`${title} Component`"
          class="h2 text-center"
        />
      </GridLayout>
    </template>
    
    <script lang="ts">
    import Vue from 'nativescript-vue';
    import { Component, Prop } from 'vue-property-decorator';
    
    @Component
    export default class PlaceHolderComponent extends Vue {
      @Prop({ default: 'Placeholder' }) title: string;
    }
    </script>
    
  6. lhovee commented on Sep 5, 2019

    @lhovee

    tns-android: 6.0.2
    tns-ios: 6.0.2
    nativescript-vue: 2.4.0
    tns-core-modules: 6.1.0

  7. rigor789 commented on Sep 9, 2019

    @rigor789
    Member

    @lhovee I just re-created your example in the playground (using js) and seems to be working fine: https://play.nativescript.org/?template=play-vue&id=RPxTCx

    I had to change grey to gray as it was erroring about grey not being a valid color.

  8. lhovee commented on Sep 25, 2019

    @lhovee

    @rigor789 @MartoYankov

    Tested your playground on an Android 7.0 LG K20 PLUS (I know I need to upgrade) and it works as expected. The active icon is black.

    Unfortunately,
    iPhone XR (and other iOS devices) the playground has a blue icon instead of the black. Can you confirm this is what you're seeing and whether or not that's an issue?

  9. lhovee commented on Sep 25, 2019

    @lhovee

    UPDATE:
    <TabStrip iosIconRenderingMode="alwaysOriginal">

    This resolves the issue I was seeing on iOS.

  10. MartoYankov commented on Sep 25, 2019

    @MartoYankov
    Contributor

    @lhovee Yes, this is the expected default behavior with 6.1 on iOS when you use resource images. There are specific iOS guidelines for these as far as I know. The iosIconRenderingMode property disables this behavior. The property was missed/forgotten in 6.0 See also #6967

  11. lhovee commented on Sep 25, 2019

    @lhovee

    Appreciate the help!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions