reactjs - 如何在 React Native 中通过 this.props.navigation.openDrawer() 发送参数
问题描述
我是反应原生的新手。我想通过 this.props.navigation.openDrawer() 函数在 react native 中发送参数。这是我的代码:但是,不起作用。
refreshSettingView() {
console.log('refresh data setting')
}
render() {
return(
<TouchableOpacity
onPress={() => {
this.props.navigation.openDrawer(this.refreshSettingView.bind(this))
}
}>
<Text>Button Open</Text
</TouchableOpacity>
)
}
解决方案
在您的抽屉组件中,尝试:
componentWillReceiveProps = (props) => {
if(!props.navigation.state.isDrawerOpen){
// Refresh the page here
}
}
componentWillReceiveProps
每次传递给传递的道具发生变化时,都会调用该方法。componentWillReceiveProps
可以在这里找到完整的参考: https ://reactjs.org/docs/react-component.html#updating-componentwillreceiveprops
让我知道它是否有效!谢谢。
推荐阅读
- python-3.x - 如何在 QcomboBox 中显示项目取决于第二个 QcomboBox 选定项目
- javascript - 在 Java Script 中动态生成嵌套 DIV 结构的有效方法
- html - 如何链接到 SVG 图像中的特定形状
- laravel - 在 Laravel 中获取用户记录的良好做法?
- c++ - 在 C++ 中将 HEX 字符串转换为 long
- javascript - 带有动态键的 JS SetInterval 未清除
- node.js - 是否可以在图像保存/上传之前使用 Multer 获取图像尺寸(宽度和高度)
- python - 加入两个表,文件名有额外的字符串,正则表达式从文件名中删除字符串并进行连接
- java - Android Studio 替换了我的 main.dart 文件中的代码
- c# - C#:使用 IQueryable 注入 DbContext 时无法访问 ASP.NET Core 中的已处置对象