【发布时间】:2018-06-04 19:34:54
【问题描述】:
谁能帮我解决如何在 React Native 中检测 Webview 按钮点击事件?如下代码所示,我的 WebView (index.html) 中有一个 Button,我想检测来自 React Native 的点击事件并执行 onClick 方法。我尝试了多种方法,但无法成功。非常感谢。
我的 MyApp.js
import React from 'react';
import { AppRegistry, View, WebView, StyleSheet} from 'react-native'
export default class MyApp extends React.Component {
onClick = () => {
console.log('Button Clicked');
}
render() {
return (
<View style={styles.container}>
<WebView
style={styles.webView}
source={require('./index.html')}/>
</View>
);
}
};
let styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: '#fff',
},
webView: {
backgroundColor: '#fff',
height: 350,
}
});
我的 index.html
<html>
<body>
<Button>Click Here</Button>
</body>
</html>
【问题讨论】:
标签: javascript reactjs react-native webview create-react-app