Skip to content

Commit 0281184

Browse files
authored
Merge pull request #35 from Rachel030219/master
feat: Android impl of UniPage postCreate
2 parents 24bc5fc + 4394138 commit 0281184

File tree

1 file changed

+20
-2
lines changed
  • packages/unify_uni_page/android/src/main/java/com/didi/unify_uni_page

1 file changed

+20
-2
lines changed

packages/unify_uni_page/android/src/main/java/com/didi/unify_uni_page/UniPage.java

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import android.content.Context;
44
import android.view.View;
5+
import android.view.ViewTreeObserver;
56

67
import androidx.annotation.NonNull;
78
import androidx.annotation.Nullable;
@@ -46,6 +47,13 @@ public UniPage() {
4647
*/
4748
public abstract void onDispose();
4849

50+
/**
51+
* 嵌原生视图创建完成,被添加到布局树
52+
*/
53+
public void postCreate() {
54+
55+
}
56+
4957
/**
5058
* 嵌原生页面进入前台;
5159
* 该方法 <bold>不保证</bold> 在首次显示时调用,仅响应 Activity 的 onStart 事件。
@@ -141,8 +149,18 @@ public void init(@NonNull Context context, String viewType, int id, BinaryMessen
141149
@Nullable
142150
@Override
143151
public View getView() {
144-
if (view == null) {
145-
view = onCreate();
152+
if (view != null) {
153+
return view;
154+
}
155+
view = onCreate();
156+
if (view != null) {
157+
view.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
158+
@Override
159+
public void onGlobalLayout() {
160+
postCreate();
161+
view.getViewTreeObserver().removeOnGlobalLayoutListener(this);
162+
}
163+
});
146164
}
147165
return view;
148166
}

0 commit comments

Comments
 (0)