Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Webview settitle #1733

Merged
merged 16 commits into from
Dec 19, 2024
Merged

Webview settitle #1733

merged 16 commits into from
Dec 19, 2024

Conversation

wangxiaokou
Copy link
Collaborator

No description provided.

if (navState.navigationType) { // navigationType这个事件在页面开始加载时和页面加载完成时都会被触发所以判断这个避免其他无效触发执行该逻辑
if (webViewTitle.current !== navState.title) {
const navigation = getFocusedNavigation()
navigation && navigation.setOptions({ headerTitle: navState.title })
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

title

window.ReactNativeWebView.postMessage(JSON.stringify({
type: 'setTitle',
payload: {
data: {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这个不用再包一层data啦,key值改为title

})
default:
if (type) {
const commonMethod = mpx.config.webviewConfig.apiImplementations && mpx.config.webviewConfig.apiImplementations[type]
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

commonMethod => implement

asyncCallback = Promise.resolve(result)
} else {
asyncCallback = Promise.reject({
errMsg: `未在apiImplementations中配置${data.type}方法`
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

data.type => type

default:
if (type) {
const commonMethod = mpx.config.webviewConfig.apiImplementations && mpx.config.webviewConfig.apiImplementations[type]
if (commonMethod) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

isFunction(implement)

const commonMethod = mpx.config.webviewConfig.apiImplementations && mpx.config.webviewConfig.apiImplementations[type]
if (commonMethod) {
const result = commonMethod()
asyncCallback = Promise.resolve(result)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

asyncCallback = Promise.resolve(implement())

}
break
}
asyncCallback && asyncCallback.then((res) => {
this.mpxIframe && this.mpxIframe.contentWindow && this.mpxIframe.contentWindow.postMessage && this.mpxIframe.contentWindow.postMessage({
type: data.type,
type: type,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

type,

detail: {
data: postData.data
},
layoutRef: webViewRef
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这咋能这么写呢

@@ -147,12 +164,26 @@ const _WebView = forwardRef<HandlerRef<WebView, WebViewProps>, WebViewProps>((pr
case 'reLaunch':
asyncCallback = navObj.reLaunch(postData)
break
default:
if (type) {
const commonMethod = mpx.config.webviewConfig.apiImplementations && mpx.config.webviewConfig.apiImplementations[type]
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

与.vue中对齐

}

asyncCallback && asyncCallback.then((res: any) => {
if (webViewRef.current?.postMessage) {
const test = JSON.stringify({
type: data.type,
type: type,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

type,

@hiyuki hiyuki merged commit a013670 into master Dec 19, 2024
6 checks passed
@hiyuki hiyuki deleted the webview-settitle branch December 19, 2024 06:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants