0

i'm new in react native. i'm use react native action button and i want if button clicked, then show other page. this is my code but still doesn't work. have any solution?

render() {
    return (
        <View style={styles.container}>
           <ActionButton buttonColor="#1E73C1" onPress={() => this.buttonPressed}>
          </ActionButton>
        </View>
    );
  }

 buttonPressed() {
    this.props.navigation.navigate('NewCase', {});
  }
Quinn
  • 697
  • 1
  • 10
  • 25

3 Answers3

0

Be sure to pass the navigation prop to the component

David Vittori
  • 1,146
  • 1
  • 13
  • 30
0

You don't execute buttonPressed at all. Fix it with ():

<ActionButton buttonColor="#1E73C1" onPress={() => this.buttonPressed()}>

Other way would be:

<ActionButton buttonColor="#1E73C1" onPress={this.buttonPressed.bind(this)}>

And like said in the comments, you should ensure that navigation actually exists in the props.

Samuli Hakoniemi
  • 18,740
  • 1
  • 61
  • 74
0

Example

<ActionButton buttonColor="#1E73C1" onPress={() => this.buttonPressed('page2')}>

buttonPressed(page){
  this.props.navigator.replace({
    id: page,
  })
}

You just put buttonPressed thats doesn't really do nothing if you have a buttonPressed() to exec the transition you need to put buttonPressed() , by the away a good thing to do is putting this type of function with '_' behind , like this: _buttonPressed('page2') and then _buttonPressed(page) , it helps a bit to know what you are doing

Brunaine
  • 1,178
  • 2
  • 16
  • 24