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 c9731feb..b840d2a0 100644 --- a/doric-android/doric/src/main/java/pub/doric/DoricPanel.java +++ b/doric-android/doric/src/main/java/pub/doric/DoricPanel.java @@ -60,7 +60,9 @@ public class DoricPanel extends FrameLayout implements LifecycleObserver { public void config(String script, String alias, String extra) { DoricContext doricContext = DoricContext.create(getContext(), script, alias, extra); config(doricContext); - doricContext.onShow(); + if (getContext() instanceof LifecycleOwner && ((LifecycleOwner) getContext()).getLifecycle().getCurrentState().isAtLeast(Lifecycle.State.RESUMED)) { + doricContext.onShow(); + } } public void config(DoricContext doricContext) { diff --git a/doric-android/doric/src/main/java/pub/doric/DoricPanelFragment.java b/doric-android/doric/src/main/java/pub/doric/DoricPanelFragment.java index 37447652..d0ae5a56 100644 --- a/doric-android/doric/src/main/java/pub/doric/DoricPanelFragment.java +++ b/doric-android/doric/src/main/java/pub/doric/DoricPanelFragment.java @@ -26,6 +26,7 @@ import android.widget.FrameLayout; import androidx.annotation.NonNull; import androidx.annotation.Nullable; import androidx.fragment.app.Fragment; +import androidx.lifecycle.LifecycleOwner; import androidx.navigation.NavController; import androidx.navigation.Navigation; @@ -97,19 +98,23 @@ public class DoricPanelFragment extends Fragment implements IDoricNavigator { @Override public void onResume() { super.onResume(); - doricPanel.onActivityResume(); + if (!(getActivity() instanceof LifecycleOwner)) { + doricPanel.onActivityResume(); + } } @Override public void onPause() { super.onPause(); - doricPanel.onActivityPause(); + if (!(getActivity() instanceof LifecycleOwner)) { + doricPanel.onActivityPause(); + } } @Override public void onDestroy() { super.onDestroy(); - if (getActivity() == null || !getActivity().isFinishing()) { + if (getActivity() == null || !getActivity().isFinishing() || !(getActivity() instanceof LifecycleOwner)) { doricPanel.onActivityDestroy(); } } diff --git a/doric-iOS/Pod/Classes/DoricPanel.m b/doric-iOS/Pod/Classes/DoricPanel.m index be5a743c..cd07cc42 100644 --- a/doric-iOS/Pod/Classes/DoricPanel.m +++ b/doric-iOS/Pod/Classes/DoricPanel.m @@ -47,7 +47,9 @@ - (void)config:(NSString *)script alias:(NSString *)alias extra:(NSString *)extr [self.view addSubview:it]; }]]; }]; - [self.doricContext onShow]; + if (self.parentViewController != nil) { + [self.doricContext onShow]; + } } - (void)viewWillLayoutSubviews {