Skip to content

Commit

Permalink
Merge pull request #35 from Rachel030219/master
Browse files Browse the repository at this point in the history
feat: Android impl of UniPage postCreate
  • Loading branch information
maxiee authored Oct 9, 2024
2 parents 24bc5fc + 4394138 commit 0281184
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 0281184

Please sign in to comment.