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

feat: onReachBottom

上级 2bc43dfa
......@@ -3,6 +3,7 @@ import { ComponentCustomProperties, ComponentInternalInstance } from 'vue'
declare module '@vue/runtime-core' {
interface ComponentCustomProperties {
$page: Page.PageInstance['$page']
__isTabBar: boolean
}
type LifecycleHook = Function[] | null
......
import { getPageVmById, invokeHook } from './page'
const SUBSCRIBE_LIFECYCLE_HOOKS = ['onPageScroll', 'onReachBottom']
export function initSubscribe() {
UniServiceJSBridge.subscribe('onPageScroll', createPageEvent('onPageScroll'))
SUBSCRIBE_LIFECYCLE_HOOKS.forEach((name) =>
UniServiceJSBridge.subscribe(name, createPageEvent(name))
)
}
function createPageEvent(name: string) {
......
......@@ -1013,8 +1013,9 @@ function onAppEnterBackground() {
invokeHook(getApp(), "onHide");
invokeHook(getCurrentPage(), "onHide");
}
const SUBSCRIBE_LIFECYCLE_HOOKS = ["onPageScroll", "onReachBottom"];
function initSubscribe() {
UniServiceJSBridge.subscribe("onPageScroll", createPageEvent("onPageScroll"));
SUBSCRIBE_LIFECYCLE_HOOKS.forEach((name) => UniServiceJSBridge.subscribe(name, createPageEvent(name)));
}
function createPageEvent(name) {
return (args, pageId) => {
......@@ -3500,7 +3501,7 @@ function getCurrentPages$1() {
const curPages = [];
const pages = currentPagesMap.values();
for (const page of pages) {
if (page.$page.meta.isTabBar) {
if (page.__isTabBar) {
if (page.$.__isActive) {
curPages.push(page);
}
......@@ -3559,6 +3560,7 @@ function initPage(vm) {
const page = initPublicPage(route);
vm.$vm = vm;
vm.$page = page;
vm.__isTabBar = page.meta.isTabBar;
currentPagesMap.set(normalizeRouteKey(page.path, page.id), vm);
}
function normalizeRouteKey(path, id2) {
......@@ -3592,6 +3594,18 @@ const routeCache = {
pageCacheMap.forEach(fn);
}
};
function isTabBarVNode(vnode) {
if (!hasOwn$1(vnode, "__isTabBar")) {
const {component} = vnode;
if (component && component.refs.page) {
const vm = component.refs.page;
if (vm.$page) {
vnode.__isTabBar = vm.__isTabBar;
}
}
}
return vnode.__isTabBar;
}
function pruneRouteCache(key) {
const pageId = parseInt(key.split(SEP)[1]);
if (!pageId) {
......@@ -3600,11 +3614,8 @@ function pruneRouteCache(key) {
routeCache.forEach((vnode, key2) => {
const cPageId = parseInt(key2.split(SEP)[1]);
if (cPageId && cPageId > pageId) {
if (__UNI_FEATURE_TABBAR__) {
const {component} = vnode;
if (component && component.refs.page && component.refs.page.$page.meta.isTabBar) {
return;
}
if (__UNI_FEATURE_TABBAR__ && isTabBarVNode(vnode)) {
return;
}
routeCache.delete(key2);
routeCache.pruneCacheEntry(vnode);
......
......@@ -6,6 +6,7 @@ import {
ComponentPublicInstance,
ComponentInternalInstance,
} from 'vue'
import { hasOwn } from '@vue/shared'
import { useRoute, RouteLocationNormalizedLoaded } from 'vue-router'
import {
invokeHook,
......@@ -38,7 +39,7 @@ export function getCurrentPages() {
const curPages: Page.PageInstance[] = []
const pages = currentPagesMap.values()
for (const page of pages) {
if (page.$page.meta.isTabBar) {
if ((page as ComponentPublicInstance).__isTabBar) {
if ((page as ComponentPublicInstance).$.__isActive) {
curPages.push(page)
}
......@@ -103,6 +104,7 @@ export function initPage(vm: ComponentPublicInstance) {
const page = initPublicPage(route)
;(vm as any).$vm = vm
;(vm as any).$page = page
vm.__isTabBar = page.meta.isTabBar!
currentPagesMap.set(
normalizeRouteKey(page.path, page.id),
(vm as unknown) as Page.PageInstance
......@@ -159,6 +161,19 @@ const routeCache: KeepAliveCache = {
},
}
function isTabBarVNode(vnode: VNode): boolean {
if (!hasOwn(vnode, '__isTabBar')) {
const { component } = vnode
if (component && component.refs.page) {
const vm = component.refs.page as ComponentPublicInstance
if (vm.$page) {
;(vnode as any).__isTabBar = vm.__isTabBar
}
}
}
return (vnode as any).__isTabBar
}
function pruneRouteCache(key: string) {
const pageId = parseInt(key.split(SEP)[1])
if (!pageId) {
......@@ -167,16 +182,9 @@ function pruneRouteCache(key: string) {
routeCache.forEach((vnode, key) => {
const cPageId = parseInt((key as string).split(SEP)[1])
if (cPageId && cPageId > pageId) {
if (__UNI_FEATURE_TABBAR__) {
if (__UNI_FEATURE_TABBAR__ && isTabBarVNode(vnode)) {
// tabBar keep alive
const { component } = vnode
if (
component &&
component.refs.page &&
(component.refs.page as ComponentPublicInstance).$page.meta.isTabBar
) {
return
}
return
}
routeCache.delete(key)
routeCache.pruneCacheEntry!(vnode)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册