feat: implement onShouldStartLoadWithRequest and webView turboModule #250
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
#249
安卓onShouldStartLoadWithRequest实现方案:
相关代码
由于在RNOH中,emitComponentEvent是异步接口,如果按照类似实现在阻塞主线程时arkui没有发送VSync,而无法真正发送事件至js线程触发RN onShouldStartLoadWithRequest事件,因此在HarmonyOS中使用如下实现方案
HarmonyOS onShouldStartLoadWithRequest实现方案:
Test Plan
展示代码的稳定性。例如:用来复现场景的命令输入和结果输出、测试用例的路径地址,或者附上截图和视频。
import React, { useState } from 'react';
import { View, Button, StyleSheet } from 'react-native';
import { WebView } from 'react-native-webview';
const WebViewDemo = () => {
const [url, setUrl] = useState('https://www.example.com');
WebView.isFileUploadSupported().then(res=>{
console.log("isFileUploadSupported:",res)
})
return (
<WebView
style={{width:'100%',height:'300'}}
source={{ uri: 'https://www.baidu.com' }}
onShouldStartLoadWithRequest={(request) => {
// Only allow navigating within this website
return false
}}
onLoadEnd={()=>
console.log('end')
}
/>
<WebView
style={{width:'100%',height:'300'}}
source={{ uri: url }}
onShouldStartLoadWithRequest={(request) => {
// Only allow navigating within this website
console.log(request)
return request.url.startsWith('https://reactnative.dev');
}}
onLoadEnd={()=>
console.log('end')
}
/>
<Button title='11111' onPress={()=>{
setUrl('https://reactnative.dev')
setTimeout(() => {
setUrl('https://www.baidu.com')
}, 0);
}}>
);
};
const styles = StyleSheet.create({
container: {
width: '100%',
height: '100%'
},
webview: {
flex: 1,
marginTop: 10,
},
loading: {
flex: 1,
justifyContent: 'center',
alignItems: 'center',
},
});
export default WebViewDemo;
Checklist