react-native-webview-invoke icon indicating copy to clipboard operation
react-native-webview-invoke copied to clipboard

hooks bug?

Open orzhtml opened this issue 4 years ago • 2 comments

let _refWebview = React.useRef()
let invoke = createInvoke(() => _refWebview.current)

React.useEffect(() => {
    // 暴露方法给 H5
  invoke.define('route', setRoute)
    return () => {}
  }, [])

return (
<WebView
          useWebKit
          ref={_refWebview}
          style={{ flex: 1 }}
          source={{ uri: config.h5 + route.params.uri, headers: { 'Cache-Control': 'no-cache' } }}
          automaticallyAdjustContentInsets={true}
          decelerationRate="normal"
          scrollEnabled={true}
          javaScriptEnabled={true}
          domStorageEnabled={true}
          onMessage={invoke.listener}
          nativeConfig={{ props: { flex: 1 } }}
          onLoad={syntheticEvent => {
            const { nativeEvent } = syntheticEvent
            console.log(`nativeEvent.url: ${nativeEvent.url}`)
          }}
          onLoadProgress={({ nativeEvent }) => {
            console.log(`nativeEvent.progress: ${nativeEvent.progress}`)
          }}
          onLoadStart={syntheticEvent => {
            // update component to be aware of loading status
            const { nativeEvent } = syntheticEvent
            console.log(`onLoadStart nativeEvent.loading: ${nativeEvent.loading}`)
          }}
          onLoadEnd={syntheticEvent => {
            // update component to be aware of loading status
            const { nativeEvent } = syntheticEvent
            console.log(`onLoadEnd nativeEvent.loading: ${nativeEvent.loading}`)
          }}
          onError={syntheticEvent => {
            const { nativeEvent } = syntheticEvent
            console.warn('WebView error: ', nativeEvent)
          }}
          onHttpError={syntheticEvent => {
            const { nativeEvent } = syntheticEvent
            console.warn(
              'onHttpError WebView received error status code: ',
              nativeEvent.statusCode
            )
          }}
          originWhitelist={['*']}
          allowFileAccessFromFileURLs={true}
          allowFileAccess={true}
          allowUniversalAccessFromFileURLs={true}
          allowingReadAccessToURL={'file://'}
        />
)

H5 那边 会报 invoke.fn.route is not function

orzhtml avatar Nov 24 '20 06:11 orzhtml

你的这个问题解决了吗?

zhaozedong avatar Jan 20 '21 03:01 zhaozedong

invoke.define

暂时没有找到解决办法,目前还是用 class 写,在这里不用 hooks

orzhtml avatar Jul 25 '22 08:07 orzhtml