在TouchableOpacity onPress React-Native上打开Webview

时间:2016-12-20 06:37:37

标签: webview react-native

目前我正在使用链接,但它正在应用外打开网址,我希望在应用内打开此应用,而不显示网址。

但是无法在React-Native中的TouchableOpecity onPress事件上打开Webview。我是否需要添加页面,然后使用URL打开页面?

任何人都可以帮忙。

1 个答案:

答案 0 :(得分:1)

我正在考虑最简单的情况,即我正在渲染单个组件而且没有使用导航器。

class ABC extends Component {
 constructor(props){
  super(props)
  this.state = {
   check : false
  }
 }
 renderWebView(){
   if(this.state.check){
     return(
       <WebView
          source={{uri: 'your url goes here'}}
          style={{marginTop: 20}}
       />
     );
   }else {
      return(
        <TouchableOpacity 
          onPress={()=>this.setState({check: true})}>
           <Text>Open WebView</Text>
        </TouchableOpacity>
     );
   }
 }
 render() {
   return (
     <View style={{flex:1}}>
      {this.renderWebView()}
     </View>
   );
 }
}

您可以使用其中一个导航器并将webview组件视为一条路线。

相关问题