关于react-native组件中navigation在navigationOptions自定义返回事件/触发事件/传递参数

关键属性 headerLeft, navigation.state.params, navigation.setParams

static navigationOptions = ({ navigation }) => {
        return {
            title: '我是一个页面',
            headerStyle: {
                backgroundColor: '#4E86F7',
            },
            headerTintColor: '#fff',
            headerLeft:(
                <TouchableOpacity onPress= {()=>navigation.state.params.handleBack()} >
                    <Image 
                        resizeMode={'contain'} 
                        source={require('../backIcon.png')} 
                        style={{width: 25, height: 25}} />
                </TouchableOpacity>
            )
        }
}

componentDidMount() {
        //componentDidMount阶段在navigation挂载
        this.props.navigation.setParams({handleBack:this._handleAdd})
}
_handleAdd(){
        console.log('我监听了返回键')
}

既然能够设置传递函数,那么传递参数不就更简单了

//有空在写
最后编辑于 :
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

友情链接更多精彩内容