Skip to content

Commit

Permalink
feat: Android impl of UniPage postCreate
Browse files Browse the repository at this point in the history
  • Loading branch information
Rachel030219 committed Oct 8, 2024
1 parent 24bc5fc commit 4394138
Showing 1 changed file with 20 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import android.content.Context;
import android.view.View;
import android.view.ViewTreeObserver;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
Expand Down Expand Up @@ -46,6 +47,13 @@ public UniPage() {
*/
public abstract void onDispose();

/**
* 嵌原生视图创建完成,被添加到布局树
*/
public void postCreate() {

}

/**
* 嵌原生页面进入前台;
* 该方法 <bold>不保证</bold> 在首次显示时调用,仅响应 Activity 的 onStart 事件。
Expand Down Expand Up @@ -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;
}
Expand Down

0 comments on commit 4394138

Please sign in to comment.