react-native - 在本机反应中使用 WebView
问题描述
每当我单击图像时,我都想使用 WebView 来显示 youtube 播放列表。但我无法显示 WebView,只有一个空白页。这是代码:
showBelier(){
this.setState({ishowing:true});
return(
<WebView
javaScriptEnabled={true}
domStorageEnabled={true}
source={{ uri: "https://www.youtube.com/watch?v=WiOKM4SvC5U&list=PLSlVQ0kIy6qx3s6EHtgStY2kzVfXKwuFD" }}
/>
)}
<View style = {{flexDirection: 'row', justifyContent:'space-between', position:'relative'}}>
<TouchableOpacity onPressIn={() => this.setState({belier: !this.state.belier})} onPress={()=> this.showBelier()}>
<Image style = {styles.image} source={ this.state.belier === true ? require("../Images/couleurs/icons8-belier-100.png")
: require("../Images/gris/beliergris.png")}/>
</TouchableOpacity>
</View>
提前致谢 !
解决方案
如果您在元素的另一个函数内部有一个渲染方法showBelier
,它将不可见。请在您的渲染中包含这样的方法:
<View>
<TouchableOpacity onPress={() => this.setState({belier: !this.state.belier})}}>
....
</TouchableOpacity>
{this.showBelier()}
</View>
并像这样调整您的方法:
showBelier(){
if(this.state.belier) {
return(
<WebView
javaScriptEnabled={true}
domStorageEnabled={true}
source={{ uri: "https://www.youtube.com/watch?v=WiOKM4SvC5U&list=PLSlVQ0kIy6qx3s6EHtgStY2kzVfXKwuFD" }}
/>
)}
}
推荐阅读
- javascript - 为不和谐服务器中的所有成员命名
- javascript - 选项之间的数据传输到相同的值和值
- algorithm - 图中具有特定长度的顶点不相交路径
- ssl - 使用 Globalsign R2 根证书的 Google Cloud 连接设备
- python - 使用python拆分行并将分隔符添加到文本文件
- python - 将字典的第一项作为Python中的字典返回?
- python-3.x - python在文档字符串中自动添加类型提示
- javascript - 从范围列表中大写
- dataframe - PySpark 动态爆炸嵌套列 - 从使用 FOR 更改为更优化的解决方案
- mysql - MySQL 日志记录使用触发器更改。有没有更好的办法?