Skip to content

Commit

Permalink
[ohos]解决FlutterBoostEntry中onPageHide的调用和onPageShow不对称问题
Browse files Browse the repository at this point in the history
  • Loading branch information
蔡嘉健 authored and 0xZOne committed Jun 7, 2024
1 parent c442c1c commit 488ecd4
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 9 deletions.
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
## NEXT
1. [dart]添加`SystemChrome.setPreferredOrientations`测试案例
2. [ohos]修复透明弹窗由于被其他全屏page遮盖导致弹窗再现时页面假死等一系列问题,补充和dialog相关场景example demo
3. [ohos]解决FlutterBoostEntry中onPageHide的调用和onPageShow不对称问题

# 4.5.10
1. [dart]添加HDR/HEIC/HEIF/TIFF/WBMP/WEBP等图片格式的测试案例
2. [ohos]修复透明弹窗由于被其他全屏page遮盖导致弹窗再现时页面假死等一系列问题,补充和dialog相关场景example demo
2. [ohos]解决透明弹窗页面切后台或被Native页面覆盖后出现的假死问题

# 4.5.9
1. [ohos]完全支持鸿蒙页面返回参数传递,包括全部四种情况(native返回native、Flutter返回native、native返回Flutter、Flutter返回Flutter)
Expand Down
23 changes: 15 additions & 8 deletions ohos/src/main/ets/components/containers/FlutterBoostEntry.ets
Original file line number Diff line number Diff line change
Expand Up @@ -247,14 +247,7 @@ export default class FlutterBoostEntry extends FlutterEntry implements FlutterVi
}

onPageShow(): void { //生命周期
//进入onPageShow有四种情况: 1、打开新页面 2、从别的页面pop返回 3、tab场景下从别的tab跳转 4、从后台切回前台
//topContainerOfThis指的是曾经从当前container打开或者跳转的container
//对于第1种情况,topContainerOfThis为null;
//对于第2种情况,topContainerOfThis是dialog,或者由于在执行当前页面的onPageShow时,topContainerOfThis还没有destroy,所以能够准确获取到;
//对于第3种情况,和第2种情况类似,只是topContainerOfThis后续不会被destroy,并且从实际业务出发,topContainerOfThis不会是dialog;
//对于第4种情况,topContainerOfThis为null或者是dialog。
const topContainerOfThis = FlutterContainerManager.getInstance().getTopContainerOfThis(this);
if (topContainerOfThis && !topContainerOfThis.isOpaque()) return;
if (this.isUnderDialogPage()) return;
if (this.isTraceEnabled()) Log.d(TAG, "#onPageShow: " + this.getUrl());

// Calls super method
Expand All @@ -265,6 +258,7 @@ export default class FlutterBoostEntry extends FlutterEntry implements FlutterVi
}

onPageHide(): void { //生命周期
if (this.isUnderDialogPage()) return;
if (this.isTraceEnabled()) Log.d(TAG, "#onPageHide: " + this.getUrl());
this.stage = LifecycleStage.ON_HIDE;
this.onContainerDisappeared();
Expand Down Expand Up @@ -348,4 +342,17 @@ export default class FlutterBoostEntry extends FlutterEntry implements FlutterVi
this.platformPlugin = null;
}
}

private isUnderDialogPage(): boolean {
//进入onPageShow有四种情况: 1、打开新页面 2、从别的页面pop返回 3、tab场景下从别的tab跳转 4、从后台切回前台
//topContainerOfThis指的是曾经从当前container打开或者跳转的container
//对于第1种情况,topContainerOfThis为null;
//对于第2种情况,topContainerOfThis是dialog,或者由于在执行当前页面的onPageShow时,topContainerOfThis还没有destroy,所以能够准确获取到;
//对于第3种情况,和第2种情况类似,只是topContainerOfThis后续不会被destroy,并且从实际业务出发,topContainerOfThis不会是dialog;
//对于第4种情况,topContainerOfThis为null或者是dialog。
//onPageHide情况和opPageShow对称
const topContainerOfThis = FlutterContainerManager.getInstance().getTopContainerOfThis(this);
if (topContainerOfThis && !topContainerOfThis.isOpaque()) return true;
else return false;
}
}

0 comments on commit 488ecd4

Please sign in to comment.