facebook / react-native

A framework for building native applications using React
https://reactnative.dev
MIT License
119.26k stars 24.35k forks source link

[TabBarIOS] Icon doesn't rerender on state change #4314

Closed jlsandri closed 8 years ago

jlsandri commented 8 years ago

An overview: I'm using a conditional statement on the icon prop and title prop of a TabBarIOS item. When the conditional value changes (through a state update) the title will rerender but not the icon. Is this a known bug?

I've included an example of the code below. I am updating the state of the TabBar in a seperate function.

<TabBarIOS.Item
    title=""
    selected={this.state.selectedTab === 'pomodoro'}
    icon={this.state.timerActive ? require('image!Play') : require('image!Pause') }
    onPress={() => {
        this.setState({
           selectedTab: 'pomodoro',
        });
    }}>
    <Pomodoro timerActive={this.state.timerActive}/>
</TabBarIOS.Item>
facebook-github-bot commented 8 years ago

Hey kilgoremaskreplica, thanks for reporting this issue!

React Native, as you've probably heard, is getting really popular and truth is we're getting a bit overwhelmed by the activity surrounding it. There are just too many issues for us to manage properly.

skevy commented 8 years ago

@kilgoremaskreplica could you throw together a quick example on https://rnplay.org/ for this?

jlsandri commented 8 years ago

Hey Skevy, thanks for the reply.

Rnplay doesn't support requiring assets from within the IOS bundle so unfortunately I can't replicate this issue using that site.

However, after going through the process I have discovered this icon rerendering issue is directly tied to requiring an image from the IOS bundle. For instance this works:

systemIcon={this.state.timerActive ? 'contacts' : 'bookmarks' }

but this does not:

icon={this.state.timerActive ? require('image!Play') : require('image!Pause') }

I am happy to setup a repo for you to have a look at if that helps.

skuridin commented 8 years ago

I think I have a related issue. ezgif-1802978386

export default class TabBarItem extends Component {
  render() {
    let icon = `ios-${this.props.icon}`;

    if (!this.props.selected) icon += '-outline';

    return (
      <Icon.TabBarItem
        iconName={icon}
        title={this.props.title}
        onPress={this.props.select}
        selected={this.props.selected}
      >
        <View></View>
      </Icon.TabBarItem>
    );
  }
}

UPD: Fixed by adding key={icon} to the <Icon.TabBarItem />

christopherdro commented 8 years ago

@kilgoremaskreplica Could you try @skuridin solution and see if that works for you?

satya164 commented 8 years ago

@facebook-github-bot answered

facebook-github-bot commented 8 years ago

Closing this issue as @satya164 says the question asked has been answered. Please help us by asking questions on StackOverflow. StackOverflow is amazing for Q&A: it has a reputation system, voting, the ability to mark a question as answered. Because of the reputation system it is likely the community will see and answer your question there. This also helps us use the GitHub bug tracker for bugs only.