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

feat: support webview replace api #1050

Merged
merged 3 commits into from
Apr 24, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 13 additions & 18 deletions packages/mp-runtime/src/createPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ import { pushPage, unlinkPage, popupPage } from './pageHub';

const WEBVIEW_MESSAGE_NAME = '__WEBVIEW_MESSAGE_EVENT_NAME__@';
const CURRENT_WV_URL = '__CURRENT_WEBVIEW_URL__';
const API_REPLACE_WEBVIEW = '__replace_webview_render__';
const WEBVIEW_STYLE = { width: '100vw', height: '100vh' };
const replaceWebView = global[API_REPLACE_WEBVIEW];

const STATE_CONSTRUCTOR = 0;
const STATE_WILLMOUNT = 1;
Expand Down Expand Up @@ -84,26 +86,19 @@ export default function createPage(renderFactory, requireCoreModule, config = {}
// Compatible with previous version of miniapp framework
location.replace(url);
return null;
} else if (evaluator) {
/**
* `render` method will be executed everytime data has changed.
* To avoid send evaluator more than once at sametime, cache the current webview
* url to detect.
*/
} else if (replaceWebView || evaluator) {
if (pageInstance[CURRENT_WV_URL] !== url) {
/**
* @HACK: In WindMill env & iOS 10, message sent to redirect webview
* must be setTimeout to avoid BUG.
* @NOTE: 2000ms at least to break through.
*/
if (
typeof __windmill_environment__ !== 'undefined'
&& __windmill_environment__.platform === 'iOS'
&& parseFloat(__windmill_environment__.systemVersion) < 11) {
evaluator._eval({
code: `setTimeout(function(){ location.replace("${url}"); }, 2000);`
});
if (replaceWebView) {
/**
* Use runtime provided API to replace webview instance.
*/
replaceWebView(url, clientId, pageName);
} else {
/**
* `render` method will be executed everytime data has changed.
* To avoid send evaluator more than once at sametime, cache the current webview
* url to detect.
*/
evaluator.call('location.replace', url);
}
}
Expand Down