Search code examples
react-nativeshoutem

How can i use NavigationBar shoutemui


I'm trying to use NavigationBar from the Shoutem UI toolkit.

My code:

<Screen>
    <NavigationBar centerComponent={<Title>TITLE</Title>}/>

    <ListView
        data={groupedData}
        renderRow={this.renderRow}
        loading ={this.state.loading}
        onRefresh={this.getAllNewsfeed.bind(this)}
        onLoadMore ={this.loadMoreData.bind(this)}
        loadMoreSpinner={<Spinner/>} />

    <Button onPress={this.onLogout.bind(this)}>
        <Text>
            LOGOUT
        </Text>
    </Button>
</Screen>

But NavigationBar always hidden, listview above NavigationBar. But when I try replace it to Title. It still work. But I don't want use Title because I want add button back or something else same that.


Solution

  • This PR solves it https://github.com/shoutem/ui/pull/104/files but somehow we have removed it from the theme. We are going to fix that in next release but until then you can help yourself by this:

    <Screen>
      <NavigationBar
        style={{
          container: {
            position: 'relative',
            width: Dimensions.get('window').width,
          }
        }}
        centerComponent={<Title>TITLE</Title>}
      />
      <ListView
        data={groupedData}
        renderRow={this.renderRow}
        loading ={this.state.loading}
        onRefresh={this.getAllNewsfeed.bind(this)}
        onLoadMore ={this.loadMoreData.bind(this)}
        loadMoreSpinner={<Spinner/>}
      />
    
      <Button onPress={this.onLogout.bind(this)}>
        <Text>
            LOGOUT
        </Text>
      </Button>
    </Screen>
    

    After release you will just have to change style prop to:

    <NavigationBar
      styleName="inline"
      centerComponent={<Title>TITLE</Title>}
    />