feat:fix lifecycle call not exactly right

This commit is contained in:
pengfei.zhou 2020-05-06 16:17:41 +08:00 committed by osborn
parent 88a8db247c
commit 8f693b451d
3 changed files with 14 additions and 5 deletions

View File

@ -60,7 +60,9 @@ public class DoricPanel extends FrameLayout implements LifecycleObserver {
public void config(String script, String alias, String extra) { public void config(String script, String alias, String extra) {
DoricContext doricContext = DoricContext.create(getContext(), script, alias, extra); DoricContext doricContext = DoricContext.create(getContext(), script, alias, extra);
config(doricContext); config(doricContext);
doricContext.onShow(); if (getContext() instanceof LifecycleOwner && ((LifecycleOwner) getContext()).getLifecycle().getCurrentState().isAtLeast(Lifecycle.State.RESUMED)) {
doricContext.onShow();
}
} }
public void config(DoricContext doricContext) { public void config(DoricContext doricContext) {

View File

@ -26,6 +26,7 @@ import android.widget.FrameLayout;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
import androidx.annotation.Nullable; import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment; import androidx.fragment.app.Fragment;
import androidx.lifecycle.LifecycleOwner;
import androidx.navigation.NavController; import androidx.navigation.NavController;
import androidx.navigation.Navigation; import androidx.navigation.Navigation;
@ -97,19 +98,23 @@ public class DoricPanelFragment extends Fragment implements IDoricNavigator {
@Override @Override
public void onResume() { public void onResume() {
super.onResume(); super.onResume();
doricPanel.onActivityResume(); if (!(getActivity() instanceof LifecycleOwner)) {
doricPanel.onActivityResume();
}
} }
@Override @Override
public void onPause() { public void onPause() {
super.onPause(); super.onPause();
doricPanel.onActivityPause(); if (!(getActivity() instanceof LifecycleOwner)) {
doricPanel.onActivityPause();
}
} }
@Override @Override
public void onDestroy() { public void onDestroy() {
super.onDestroy(); super.onDestroy();
if (getActivity() == null || !getActivity().isFinishing()) { if (getActivity() == null || !getActivity().isFinishing() || !(getActivity() instanceof LifecycleOwner)) {
doricPanel.onActivityDestroy(); doricPanel.onActivityDestroy();
} }
} }

View File

@ -47,7 +47,9 @@ - (void)config:(NSString *)script alias:(NSString *)alias extra:(NSString *)extr
[self.view addSubview:it]; [self.view addSubview:it];
}]]; }]];
}]; }];
[self.doricContext onShow]; if (self.parentViewController != nil) {
[self.doricContext onShow];
}
} }
- (void)viewWillLayoutSubviews { - (void)viewWillLayoutSubviews {