Skip to content

Commit

Permalink
fix: 解决页面切换的问题
Browse files Browse the repository at this point in the history
* 解决pageNo===0时,即打开第1个页面时,在鸿蒙平台动画不能真正的停止"
* 解决返回时上一个页面瞬间白屏的问题
  • Loading branch information
guoenxuan committed Apr 2, 2024
1 parent 93e47bc commit 9558e99
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 0 deletions.
10 changes: 10 additions & 0 deletions packages/taro-router/src/router/page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,8 @@ export default class PageHandler {
pageEl.style.zIndex = '1'
}

eventCenter.trigger('__taroPageWillShowAfterDestroyed')

this.unloadTimer = setTimeout(() => {
this.unloadTimer = null
this.lastUnloadPage?.onUnload?.()
Expand All @@ -235,6 +237,14 @@ export default class PageHandler {
if (delta >= 1) this.unload(stacks.last, delta)
}

willShow (page?: PageInstance | null) {
if (!page) return
const pageEl = this.getPageContainer(page)

Check warning on line 242 in packages/taro-router/src/router/page.ts

View check run for this annotation

Codecov / codecov/patch

packages/taro-router/src/router/page.ts#L241-L242

Added lines #L241 - L242 were not covered by tests
if (pageEl) {
pageEl.classList.remove('taro_page_shade')
}
}

Check warning on line 246 in packages/taro-router/src/router/page.ts

View check run for this annotation

Codecov / codecov/patch

packages/taro-router/src/router/page.ts#L244-L246

Added lines #L244 - L246 were not covered by tests

show (page?: PageInstance | null, pageConfig: Route = {}, pageNo = 0) {
if (!page) return

Expand Down
6 changes: 6 additions & 0 deletions packages/taro-router/src/router/spa.ts
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,12 @@ export function createRouter (
const delta = stacks.getDelta(pathname)
// NOTE: Safari 内核浏览器在非应用页面返回上一页时,会触发额外的 POP 事件,此处需避免当前页面被错误卸载
if (currentPage !== stacks.getItem(prevIndex)) {
eventCenter.once('__taroPageWillShowAfterDestroyed', () => {

Check warning on line 158 in packages/taro-router/src/router/spa.ts

View check run for this annotation

Codecov / codecov/patch

packages/taro-router/src/router/spa.ts#L158

Added line #L158 was not covered by tests
if (prevIndex > -1) {
const pageInstance = stacks.getItem(prevIndex)
pageInstance && handler.willShow(pageInstance)
}

Check warning on line 162 in packages/taro-router/src/router/spa.ts

View check run for this annotation

Codecov / codecov/patch

packages/taro-router/src/router/spa.ts#L162

Added line #L162 was not covered by tests
})
handler.unload(currentPage, delta, prevIndex > -1)
if (prevIndex > -1) {
eventCenter.once('__taroPageOnShowAfterDestroyed', () => {
Expand Down
1 change: 1 addition & 0 deletions packages/taro-router/src/style.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ body {
.taro_router > .taro_page.taro_tabbar_page,
.taro_router > .taro_page.taro_page_show.taro_page_stationed {
transform: none;
transition: none;
}
.taro_router > .taro_page.taro_page_show {
Expand Down

0 comments on commit 9558e99

Please sign in to comment.