timomeh / react-native-material-bottom-navigation

πŸ’…πŸ”§πŸ‘Œ a beautiful, customizable and easy-to-use material design bottom navigation for react-native
MIT License
710 stars 127 forks source link

Bottom Navigation Tabs re-render issue on switching between tabs #135

Closed SAHITYASAI closed 5 years ago

SAHITYASAI commented 5 years ago

55 # What kind of Issue is this?

Question / Problem

Actual behavior

Expected behavior

Additional resources

| macOS | High Sierra | react-native-material-bottom-navigation | ^1.0.4 | react-native | 0.61.1

timomeh commented 5 years ago

This depends on how you display the content for each tab (usually referred to as "screen"). There should be only 1 instance of <BottomNavigation ... /> in your whole code, alongside your screens. This allows you to switch the contents of the screen depending on this.state.activeTab:

  render() {
    return (
      <View style={{ flex: 1, backgroundColor: 'white' }}>
        {this.state.activeTab === "books" && <Text>Content for "Books"</Text>}
        {this.state.activeTab === "movies" && <Text>Content for "Movies"</Text>}
        {this.state.activeTab === "music" && <Text>Content for "Music"</Text>}

        <BottomNavigation
          tabs={this.tabs}
          activeTab={this.state.activeTab}
          onTabPress={newTab => this.setState({ activeTab: newTab.key })}
          renderTab={this.renderTab}
          useLayoutAnimation
        />
      </View>
    )
  }

If you press a tab, the corresponding content will be displayed, and the BottomNavigation doesn't re-render.

This is a very simple way to navigate between screens. If you need a more advanced navigation, you should consider using a navigation library like https://reactnavigation.org.

timomeh commented 5 years ago

Since this is not an issue with this library, I'm going to close it.