From eb6ba3ee36dd4a14f2bdb053f02a49b01d365e02 Mon Sep 17 00:00:00 2001 From: "pengfei.zhou" Date: Sat, 29 Feb 2020 14:17:38 +0800 Subject: [PATCH] Align lifecycle timing for Android and iOS --- .../doric/src/main/java/pub/doric/DoricContext.java | 2 +- doric-android/doric/src/main/java/pub/doric/DoricPanel.java | 5 +---- doric-iOS/Pod/Classes/DoricPanel.m | 1 + 3 files changed, 3 insertions(+), 5 deletions(-) diff --git a/doric-android/doric/src/main/java/pub/doric/DoricContext.java b/doric-android/doric/src/main/java/pub/doric/DoricContext.java index 7b5d571a..55f0f7e7 100644 --- a/doric-android/doric/src/main/java/pub/doric/DoricContext.java +++ b/doric-android/doric/src/main/java/pub/doric/DoricContext.java @@ -101,6 +101,7 @@ public class DoricContext { this.mContextId = contextId; this.source = source; this.extra = extra; + callEntity(DoricConstant.DORIC_ENTITY_CREATE); } public String getSource() { @@ -124,7 +125,6 @@ public class DoricContext { .put("height", height) .toJSONObject(); callEntity(DoricConstant.DORIC_ENTITY_INIT, this.initParams, extra); - callEntity(DoricConstant.DORIC_ENTITY_CREATE); } public AsyncResult callEntity(String methodName, Object... args) { diff --git a/doric-android/doric/src/main/java/pub/doric/DoricPanel.java b/doric-android/doric/src/main/java/pub/doric/DoricPanel.java index be87ac91..97f3a79d 100644 --- a/doric-android/doric/src/main/java/pub/doric/DoricPanel.java +++ b/doric-android/doric/src/main/java/pub/doric/DoricPanel.java @@ -56,6 +56,7 @@ public class DoricPanel extends FrameLayout implements LifecycleObserver { public void config(String script, String alias, String extra) { DoricContext doricContext = DoricContext.create(getContext(), script, alias, extra); + doricContext.onShow(); config(doricContext); } @@ -65,10 +66,6 @@ public class DoricPanel extends FrameLayout implements LifecycleObserver { if (getMeasuredWidth() != 0 && getMeasuredHeight() != 0) { mDoricContext.init(DoricUtils.px2dp(getMeasuredWidth()), DoricUtils.px2dp(getMeasuredHeight())); } - if (getContext() instanceof LifecycleOwner - && ((LifecycleOwner) getContext()).getLifecycle().getCurrentState().isAtLeast(Lifecycle.State.RESUMED)) { - mDoricContext.onShow(); - } } @Override diff --git a/doric-iOS/Pod/Classes/DoricPanel.m b/doric-iOS/Pod/Classes/DoricPanel.m index fb8463eb..2fae084b 100644 --- a/doric-iOS/Pod/Classes/DoricPanel.m +++ b/doric-iOS/Pod/Classes/DoricPanel.m @@ -28,6 +28,7 @@ - (void)config:(NSString *)script alias:(NSString *)alias extra:(NSString *)extr [self.view addSubview:it]; }]]; }]; + [self.doricContext onShow]; } - (void)viewWillLayoutSubviews {