2

Am learning react-native, trying to create a menu docked at the bottom of a screen. Is there a way i can display the screen content in the ScrollView docked at the top of navigation menu like this messenger menu ? When messages image is tapped, display messages screen content in the same page.

         return (<View style={styles.container}>
          <ScrollView>
            <Text style={styles.content}>
              {this.state.content}</Text>
          </ScrollView>
          <View style={styles.footer}>
            <TouchableOpacity onPress={this.navigateMessage}>
              <Image source={require('../img/messages.png')} style={[
                  styles.tabIcon, {
                    tintColor: this.state.messagesTint
                  }
                ]}/>
            </TouchableOpacity>
            <TouchableOpacity onPress={this.navigateContacts}>
              <Image source={require('../img/contacts.png')} style={[
                  styles.tabIcon, {
                    tintColor: this.state.contactsTint
                  }
                ]}/>
            </TouchableOpacity>
          </View>
        </View>);

1 Answer 1

2

React Native re-renders the content when the state changes/you call setState().

You can follow this.

state = {
    selectedTab: 'msg'
}
renderMessages(){
    return <YourMessageView />
}
render(){
    switch(this.state.selectedTab){
        case 'msg':
            this.renderMessages();
            break;
        case 'contact':
            this.renderContact();
            break;
        default:
            this.renderDefault();

    } 
    return(
      <YourFooter />
    );


}

and on your TouchableOpacity onPress:

onPress={() => this.setState({ selectedTab: 'msg'})}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.