我正在使用反應原生路由器通量爲我的導航應用程序中,我有容器文件夾和組件文件夾中我創建了一個按鈕組件。觸發react-native-router-flux從演示組件或傳遞反應本地路由器通量功能組件作爲道具
這是容器文件夾我的Register.js文件,我也有一個Verify.js文件只呈現一個「世界你好」
import React, { Component } from 'react';
import { View, Text, TextInput,StyleSheet} from 'react-native';
import {Actions} from 'react-native-router-flux';
import Button from '../../components/button/Button';
import styles from '../../styles/styles';
export default class Register extends Component{
constructor(){
super();
this.onPressButton = this.onPressButton.bind(this);
}
onPressButton(){
return()=>Actions.verify();
}
render() {
return (
<View style={styles.global}>
<View style={styles.registerContainer}>
<Text style={styles.registerText}>Input your mobile number</Text>
</View>
<View style={styles.inputRow}>
<TextInput keyboardType={'numeric'} underlineColorAndroid={'transparent'} style={styles.zipCode}/>
<TextInput multiline={true} underlineColorAndroid={'transparent'} style={styles.number}/>
</View>
<Button text="REGISTER" onPressButton={this.onPressButton}/>
</View>
);
}
}
Button組件低於
import React,{Component,PropTypes} from 'react';
import {View,Text,TouchableHighlight,StyleSheet} from 'react-native';
export default class Button extends Component{
static propTypes={
text: PropTypes.string.isRequired,
onPressButton: PropTypes.func.isRequired
};
render(){
return(
<TouchableHighlight onPress={this.props.onPressButton}>
<View style={styles.btn}>
<Text style={styles.btn_text}>{this.props.text}</Text>
</View>
</TouchableHighlight>
);
}
}
此外,下面是我的路由節略應用程序文件,只是爲了顯示我想從中路由的場景。
<Scene key="root">
<Scene key="register" title="Register" hideNavBar component={Register} />
<Scene key="verify" title="Verify" hideNavBar component={Verify} />
/>
如何將我的導航功能作爲道具傳遞給Button組件,以便onPressButton觸發導航?