2017-09-12 8 views
1

React Native에 처음 왔으며 버튼을 누를 때 Webview를 여는 간단한 앱이 있습니다. 탐색 상태가 변경되면 Webview를 닫고 싶습니다. 나는 그것을 닫을 수 있지만 어떻게 찾을 수 없는지 알 수있다.React-Native Webview를 닫는 방법?

doc에는 기능을 언급하지 않았습니다. 이것에 대한 해결책은 무엇입니까?

버전 : 반응 네이티브 : 0.47.2

답변

0

당신이 모달

_onNavigationStateChange (webViewState) { 
    this.hide() 
} 
show() { 
    this.setState({ modalVisible: true }) 
} 

hide() { 
    this.setState({ modalVisible: false }) 
} 

render() { 
const { clientId, redirectUrl, scopes } = this.props 
return (
    <Modal 
    animationType={'slide'} 
    visible={this.state.modalVisible} 
    onRequestClose={this.hide.bind(this)} 
    transparent 
    > 
    <View style={styles.modalWarp}> 
     <View style={styles.contentWarp}> 
     <WebView 
      style={[{ flex: 1 }, this.props.styles]} 
      source={{ uri: `http://google.com` }} 
      scalesPageToFit 
      startInLoadingState 
      onNavigationStateChange={this._onNavigationStateChange.bind(this)} 
      onError={this._onNavigationStateChange.bind(this)} 
     /> 
     <TouchableOpacity onPress={this.hide.bind(this)} style={styles.btnStyle}> 
      <Text style={styles.closeStyle}>close</Text> 
     </TouchableOpacity> 
     </View> 
    </View> 
    </Modal > 

) 
} 
+0

감사를 추가 할 수 있습니다, 그것은 작동 내가 원하는대로! – timp

+0

당신은 오신 것을 환영합니다 –