diff --git a/packages/unify_uni_page/android/src/main/java/com/didi/unify_uni_page/UniPage.java b/packages/unify_uni_page/android/src/main/java/com/didi/unify_uni_page/UniPage.java index f7dabce..5aa3147 100644 --- a/packages/unify_uni_page/android/src/main/java/com/didi/unify_uni_page/UniPage.java +++ b/packages/unify_uni_page/android/src/main/java/com/didi/unify_uni_page/UniPage.java @@ -2,6 +2,7 @@ import android.content.Context; import android.view.View; +import android.view.ViewTreeObserver; import androidx.annotation.NonNull; import androidx.annotation.Nullable; @@ -46,6 +47,13 @@ public UniPage() { */ public abstract void onDispose(); + /** + * 嵌原生视图创建完成,被添加到布局树 + */ + public void postCreate() { + + } + /** * 嵌原生页面进入前台; * 该方法 不保证 在首次显示时调用,仅响应 Activity 的 onStart 事件。 @@ -141,8 +149,18 @@ public void init(@NonNull Context context, String viewType, int id, BinaryMessen @Nullable @Override public View getView() { - if (view == null) { - view = onCreate(); + if (view != null) { + return view; + } + view = onCreate(); + if (view != null) { + view.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() { + @Override + public void onGlobalLayout() { + postCreate(); + view.getViewTreeObserver().removeOnGlobalLayoutListener(this); + } + }); } return view; }