From 5c22e914652fc0b537250b46354c41ec1ba7852e Mon Sep 17 00:00:00 2001 From: qiang Date: Thu, 1 Aug 2019 20:15:14 +0800 Subject: [PATCH] feat: app-plus onWindowResize --- src/core/service/api/ui/window.js | 23 +++++++++++++++++++ .../service/framework/webview/index.js | 22 ++++++++++++++++-- 2 files changed, 43 insertions(+), 2 deletions(-) create mode 100644 src/core/service/api/ui/window.js diff --git a/src/core/service/api/ui/window.js b/src/core/service/api/ui/window.js new file mode 100644 index 0000000000..7d2faad28d --- /dev/null +++ b/src/core/service/api/ui/window.js @@ -0,0 +1,23 @@ +import { + invoke +} from 'uni-core/service/bridge' + +import { + onMethod +} from '../../platform' + +const callbacks = [] +onMethod('onViewDidResize', res => { + callbacks.forEach(callbackId => { + invoke(callbackId, res) + }) +}) + +export function onWindowResize (callbackId) { + callbacks.push(callbackId) +} + +export function offWindowResize (callbackId) { + // 此处和微信平台一致查询不到去掉最后一个 + callbacks.splice(callbacks.indexOf(callbackId), 1) +} diff --git a/src/platforms/app-plus/service/framework/webview/index.js b/src/platforms/app-plus/service/framework/webview/index.js index 4d0046fa71..e988a987c4 100644 --- a/src/platforms/app-plus/service/framework/webview/index.js +++ b/src/platforms/app-plus/service/framework/webview/index.js @@ -7,6 +7,10 @@ import { parseWebviewStyle } from './parser/webview-style-parser' +import { + publish +} from '../../bridge' + let id = 2 const WEBVIEW_LISTENERS = { @@ -40,8 +44,8 @@ export function initWebview (webview, routeOptions) { ) if (process.env.NODE_ENV !== 'production') { console.log(`[uni-app] updateWebview`, webviewStyle) - } - + } + webview.setStyle(webviewStyle) } @@ -57,6 +61,20 @@ export function initWebview (webview, routeOptions) { }) }) + webview.addEventListener('resize', ({ + width, + height + }) => { + const res = { + size: { + windowWidth: Math.ceil(width), + windowHeight: Math.ceil(height) + } + } + publish('onViewDidResize', res) + emit('onResize', res, parseInt(webview.id)) + }) + // TODO 应该结束之前未完成的下拉刷新 on(webview.id + '.startPullDownRefresh', () => { webview.beginPullToRefresh() -- GitLab