Skip to content

Commit

Permalink
feat(h5): 修改 onShow、onHide 生命周期触发逻辑 (NervJS#15183)
Browse files Browse the repository at this point in the history
Co-authored-by: Zakary <zakarycode@gmail.com>
  • Loading branch information
beezen and ZakaryCode authored Jan 31, 2024
1 parent f5dc3de commit 3dafca1
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 1 deletion.
8 changes: 8 additions & 0 deletions packages/taro-router/src/router/mpa.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,4 +88,12 @@ export async function createMultiRouter (
handler.load(page, pageConfig)

app.onShow?.(launchParam as Record<string, any>)

window.addEventListener('visibilitychange', ()=>{
if (document.visibilityState === 'visible') {
app.onShow?.(launchParam as Record<string, any>)
}else{
app.onHide?.(launchParam as Record<string, any>)
}
})
}
8 changes: 8 additions & 0 deletions packages/taro-router/src/router/spa.ts
Original file line number Diff line number Diff line change
Expand Up @@ -210,5 +210,13 @@ export function createRouter (

app.onShow?.(launchParam as Record<string, any>)

window.addEventListener('visibilitychange', ()=>{
if (document.visibilityState === 'visible') {
app.onShow?.(launchParam as Record<string, any>)
}else{
app.onHide?.(launchParam as Record<string, any>)
}
})

return history.listen(render)
}
2 changes: 1 addition & 1 deletion packages/taro-router/src/tabbar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export function initTabbar (config: AppConfig, history: History) {

// TODO: custom-tab-bar
defineCustomElementTaroTabbar()
const tabbar: any = document.createElement('taro-tabbar') as HTMLDivElement
const tabbar: any = document.createElement('taro-tabbar') as HTMLElement
const homePage = config.entryPagePath || (config.pages ? config.pages[0] : '')
tabbar.conf = config.tabBar
tabbar.conf.homePage = history.location.pathname === '/' ? homePage : history.location.pathname
Expand Down
1 change: 1 addition & 0 deletions packages/taro-runtime/src/dsl/instance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ export interface AppInstance extends Show {
onPageNotFound? (res: any): void
onUnhandledRejection? (error: any): void
onShow?(options?: Record<string, unknown>): void
onHide?(options?: Record<string, unknown>): void
unmount? (id: string, cb?: () => void): void
taroGlobalData?: Record<any, any>
config?: Record<any, any>
Expand Down

0 comments on commit 3dafca1

Please sign in to comment.