react-navigation设置navigationOptions中Static中使用this的方法

来源:互联网 发布:中国临床试验数据库 编辑:程序博客网 时间:2024/06/04 18:29

使用react-navigation时,单页面设置navigationOptions中,进行Static中调用方法,不能像以下设置

onPress = {()=>this.navigatePress()}

static navigationOptions = ({navigation, screenProps}) => ({        headerTitle: '登录',        headerLeft:(            <Text  onPress={()=>this.navigatePress()} style={{marginLeft:5, width:30, textAlign:"center"}} >                <Icon  name='ios-arrow-back'size={24} color='white' />            </Text>        )    });


解决方法:

static navigationOptions = ({navigation, screenProps}) => ({        headerTitle: '登录',        headerLeft:(            <Text  onPress={()=>navigation.state.params.navigatePress()} style={{marginLeft:5, width:30, textAlign:"center"}} >                <Icon  name='ios-arrow-back'size={24} color='white' />            </Text>        )    });    _onBackAndroid=()=>{        alert('点击headerLeft');    }        componentDidMount(){        //在static中使用this方法        this.props.navigation.setParams({ navigatePress:this._onBackAndroid })    }




阅读全文
0 0
原创粉丝点击