-
Notifications
You must be signed in to change notification settings - Fork 380
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
Webview settitle #1733
Conversation
if (navState.navigationType) { // navigationType这个事件在页面开始加载时和页面加载完成时都会被触发所以判断这个避免其他无效触发执行该逻辑 | ||
if (webViewTitle.current !== navState.title) { | ||
const navigation = getFocusedNavigation() | ||
navigation && navigation.setOptions({ headerTitle: navState.title }) |
There was a problem hiding this comment.
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: { |
There was a problem hiding this comment.
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] |
There was a problem hiding this comment.
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}方法` |
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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, |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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] |
There was a problem hiding this comment.
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, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
type,
No description provided.