Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/reactjs/21.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Reactjs React Native中的嵌套组件事件处理_Reactjs_React Native - Fatal编程技术网

Reactjs React Native中的嵌套组件事件处理

Reactjs React Native中的嵌套组件事件处理,reactjs,react-native,Reactjs,React Native,这是我的示例代码 .. render(){ return ( <TouchableOpacity onPress={this.EventHandler.bind(this)}> <Text>....</Text> ..... <WebView source={{html: this.state.htmlContent}} onN

这是我的示例代码

..


 render(){
        return (
        <TouchableOpacity onPress={this.EventHandler.bind(this)}>
         <Text>....</Text>
         .....
         <WebView source={{html: this.state.htmlContent}}
                  onNavigationStateChange={this.onNavigationChange.bind(this)}>
         </WebView>
        </TouchableOpacity>
        )
    }
           ....
  onNavigationChange(event) {
     if (!event.url.startsWith("about:blank")) {
        Linking.openURL(event.url).catch(err => console.log('An error occurred', err));
        }
    }

        ....
。。
render(){
返回(
....
.....
)
}
....
onNavigationChange(事件){
如果(!event.url.startsWith(“about:blank”)){
Linking.openURL(event.url).catch(err=>console.log('发生错误',err));
}
}
....

我的this.state.htmlContent包含URL。上面的代码在“onNavigationChange”中正确激发“Linking.openURL”API,但也激发“EventHandler”函数。如果用户单击URL,我希望不会触发“EventHandler”。如果用户没有单击URL并单击WebView中的任何其他位置或WebView上方的组件,我希望触发“EventHandler”。

停止事件传播,请在最后一个:
event.stopImmediatePropagation()中的
onNavigationChange
方法中使用此行
。我以前尝试过,但得到了异常事件。stopImmediatePropagation不是一个函数。我使用的是RN 0.39。