提交 ebb9672c 编写于 作者: fxy060608's avatar fxy060608

feat(app): add lifecycle

上级 c25a45fa
......@@ -9355,6 +9355,15 @@ var serviceContext = (function (vue) {
pageVm.$page = __pageInstance;
pageVm.$vm = pageVm;
addCurrentPage(initScope(__pageId, pageVm));
invokeHook(pageVm, 'onLoad', __pageQuery);
invokeHook(pageVm, 'onShow');
vue.onMounted(() => {
invokeHook(pageVm, 'onReady');
// TODO preloadSubPackages
});
vue.onBeforeUnmount(() => {
invokeHook(pageVm, 'onUnload');
});
if (oldSetup) {
return oldSetup(__pageQuery, ctx);
}
......@@ -9500,6 +9509,8 @@ var serviceContext = (function (vue) {
}, NavigateToProtocol, NavigateToOptions);
function _navigateTo({ url, path, query, aniType, aniDuration, }) {
// TODO eventChannel
// 当前页面触发 onHide
invokeHook('onHide');
return new Promise((resolve) => {
showWebview(registerPage({ url, path, query, openType: 'navigateTo' }), aniType, aniDuration, () => {
resolve(undefined);
......@@ -9623,6 +9634,8 @@ var serviceContext = (function (vue) {
.slice(len - delta, len)
.forEach((page) => removePage(page));
setStatusBarStyle();
// 前一个页面触发 onShow
invokeHook('onShow');
};
const webview = plus.webview.getWebviewById(currentPage.$page.id + '');
if (!currentPage.__uniapp_webview) {
......
......@@ -104,6 +104,8 @@ function back(
.slice(len - delta, len)
.forEach((page) => removePage(page as ComponentPublicInstance))
setStatusBarStyle()
// 前一个页面触发 onShow
invokeHook('onShow')
}
const webview = plus.webview.getWebviewById(currentPage.$page.id + '')
......
import { parseUrl } from '@dcloudio/uni-shared'
import { getRouteMeta } from '@dcloudio/uni-core'
import { getRouteMeta, invokeHook } from '@dcloudio/uni-core'
import {
API_NAVIGATE_TO,
API_TYPE_NAVIGATE_TO,
......@@ -59,6 +59,8 @@ function _navigateTo({
aniDuration,
}: NavigateToOptions): Promise<undefined> {
// TODO eventChannel
// 当前页面触发 onHide
invokeHook('onHide')
return new Promise((resolve) => {
showWebview(
registerPage({ url, path, query, openType: 'navigateTo' }),
......
import { getCurrentPage } from '@dcloudio/uni-core'
import { formatLog } from '@dcloudio/uni-shared'
import { ComponentPublicInstance } from 'vue'
......@@ -21,6 +22,10 @@ export function getCurrentPages() {
return curPages
}
export function removeCurrentPage() {
removePage(getCurrentPage() as ComponentPublicInstance)
}
export function removePage(curPage: ComponentPublicInstance) {
const index = pages.findIndex((page) => page === curPage)
if (index === -1) {
......
import { invokeHook } from '@dcloudio/uni-core'
import { formatLog } from '@dcloudio/uni-shared'
import { ComponentPublicInstance, getCurrentInstance } from 'vue'
import {
ComponentPublicInstance,
getCurrentInstance,
onBeforeUnmount,
onMounted,
} from 'vue'
import { VuePageComponent } from './define'
import { addCurrentPage } from './getCurrentPages'
......@@ -18,6 +24,15 @@ export function setupPage(component: VuePageComponent) {
pageVm.$page = __pageInstance as Page.PageInstance['$page']
pageVm.$vm = pageVm
addCurrentPage(initScope(__pageId as number, pageVm))
invokeHook(pageVm, 'onLoad', __pageQuery)
invokeHook(pageVm, 'onShow')
onMounted(() => {
invokeHook(pageVm, 'onReady')
// TODO preloadSubPackages
})
onBeforeUnmount(() => {
invokeHook(pageVm, 'onUnload')
})
if (oldSetup) {
return oldSetup(__pageQuery as any, ctx)
}
......
import { onWebviewClose } from './close'
import { onWebviewPopGesture } from './popGesture'
import { onWebviewResize } from './resize'
const WEBVIEW_LISTENERS = {
......@@ -21,8 +22,8 @@ export function initWebviewEvent(webview: PlusWebviewWebviewObject) {
onWebviewResize(webview)
// TODO
// if (plus.os.name === 'iOS') {
// !(webview as any).nvue && onWebviewRecovery(webview, routeOptions)
// onWebviewPopGesture(webview)
// }
if (plus.os.name === 'iOS') {
// !(webview as any).nvue && onWebviewRecovery(webview, routeOptions)
onWebviewPopGesture(webview)
}
}
import { invokeHook } from '@dcloudio/uni-core'
import {
lastStatusBarStyle,
setStatusBarStyle,
StatusBarStyle,
} from '../../../../statusBar'
import { removeCurrentPage } from '../../../page/getCurrentPages'
export function onWebviewPopGesture(webview: PlusWebviewWebviewObject) {
let popStartStatusBarStyle: StatusBarStyle
webview.addEventListener('popGesture', (e) => {
if (e.type === 'start') {
// 设置下一个页面的 statusBarStyle
const pages = getCurrentPages()
const page = pages[pages.length - 2]
popStartStatusBarStyle = lastStatusBarStyle
const statusBarStyle =
page && (page.$page.statusBarStyle as StatusBarStyle)
statusBarStyle && setStatusBarStyle(statusBarStyle)
} else if (e.type === 'end' && !e.result) {
// 拖拽未完成,设置为当前状态栏前景色
setStatusBarStyle(popStartStatusBarStyle)
} else if (e.type === 'end' && e.result) {
removeCurrentPage()
setStatusBarStyle()
// 触发前一个页面 onShow
invokeHook('onShow')
}
})
}
import { formatLog } from '@dcloudio/uni-shared'
type SetStatusBarStyle = typeof plus.navigator.setStatusBarStyle
type StatusBarStyle = Parameters<SetStatusBarStyle>[0]
export type StatusBarStyle = Parameters<SetStatusBarStyle>[0]
export let lastStatusBarStyle: StatusBarStyle
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册