react-navigation 之StackNavigator 使用 正向传真及其回调

这里写三个界面为栗子
StackNavigator 会按添加的顺序直接先显然Reactnav这个界面
先附上效果图

QQ20170620-135904.gif

步骤1

import  Reactnav from  './Components/ReactNav';
import  ReactSecNav from  './Components/ReactNavSec'
import ReactThirdNav from  './Components/ReactThiNav'

const  App = StackNavigator({
    Home:{screen:Reactnav},
    NavSec:{screen:ReactSecNav},
    NavThird:{screen:ReactThirdNav},
});

AppRegistry.registerComponent('RN044Demo', () => App);

步骤2

export default class ReactNav extends Component {
    render() {
        const  {navigate} = this.props.navigation; //使用这种引入方式更加简单
        return (
            
                

步骤3

export default class ReactNavSec extends Component {
    back =(state,goBack)=>{ //把属性传递过来,然后进行使用
        state.params.callBack('this is back data ') //回调传值
        goBack() //点击POP上一个页面得方法
    }
    render() {
        const  {navigate,state,goBack,} = this.props.navigation;
        return (
            
                
export default class ReactThiNav extends Component {
    render() {
        const  {navigate,goBack,state} = this.props.navigation;
        return (
            
                

你可能感兴趣的:(react-navigation 之StackNavigator 使用 正向传真及其回调)