2017-05-23 14 views
0

React Nativeの新機能です。反応ネイティブのアラートクリックからリダイレクトしたいしかし、まだエラー これは私のコードです。 {text: 'OK', onPress:() => props.onButtonPress()}:感謝Alert React Nativeで他のページをリダイレクトする方法

render() { 
    return (
     <View style={styles.Footer}> 
      <TouchableHighlight 
       onPress={() => Alert.alert(
        'Logout', 
        alertMessage, 
        [ 
        {text: 'Cancel', onPress:() => console.log('Cancel Pressed!')}, 
        {text: 'OK', onPress:() => this.onButtonPress()}, 
        ] 
       )}> 
       <View style={styles.button}> 
        <Text style={styles.buttonTitle}>Logout</Text> 
       </View> 
       </TouchableHighlight> 
     </View> 
    ); 
    } 

onButtonPress() { 
    const resetAction = NavigationActions.reset({ 
     index: 0, 
     actions: [ 
     NavigationActions.navigate({ routeName: 'Home'}) 
     ] 
    }) 
    this.props.navigation.dispatch(resetAction) 
    } 
+0

どのようなエラーが表示されますか? – Avdept

+0

未定義はオブジェクトではありません( 'this.props.navigation.dispatch'を評価しています)。このエラー@Avdept – Queen

答えて

0

あなたはそれが適切な範囲を持っているので、onButtonPressにthisをバインドする必要があるように見えます。

constructor(props) { 
    super(props); 
    this.onButtonPress = this.onButtonPress.bind(this); 
} 
1

あなたはonButtonPress親コンテナ内の、その後のコードを実行することであるCustomDrawerContentComponentに小道具としてそれを渡すことが必要です。

現在、this.props.navigationはありません。あなたの機能はコンポーネントスコープの外にあります。

0
あなたが代わりに onButtonPress(のonButtonPressを呼び出す必要があり

   Alert.alert(
          'FingerPrint Authentication', 
          'Would you like to authenticate using fingerprint ?', 
          [ 
           {text: 'Cancel', onPress:() => console.log('Cancel Pressed!')}, 
           {text: 'Yes', onPress: this.onButtonPress}, 
          ], 
          { cancelable: false } 
         ) 


    onButtonPress =() => { 
      this.props.navigator.push({ 
      name: 'Home', 
      title: 'Home', 
      }); 
     } 
関連する問題