Fragmentation icon indicating copy to clipboard operation
Fragmentation copied to clipboard

部分情况下不会执行onLazyInitView方法

Open yihuajia opened this issue 5 years ago • 4 comments

Issues Guideline

Following information can help us to resolve the issue faster.

  • Library version fragmentationx 1.0.1
  • Support-v4 version androidx-1.0.2
  • Logs
  • Screenshots

In addition, we do not accept issues unrelated to Fragmentation.

场景: 输入完登录密码,立即按home键,之后再返回到app首页,结果子Fragment A未执行onLazyInitView方法,onSupportVisible及onSupportInvisible均未执行。通过调试发现,子Fragment A未执行onResume内的逻辑,原因是mIsFirstVisible为true了

页面结构: 首页五个平级的Fragment B,C,D,E,F,其中Fragment B中嵌套了ViewPager,Fragment A就是在ViewPager中的子Fragment。

该问题为必现

yihuajia avatar Jul 15 '19 07:07 yihuajia

https://github.com/YoKeyword/Fragmentation/issues/783 原来之前也提了这个问题,不知道androdix里面还存不存在之前说的那个问题了

ps:感觉像是还没有加载到Fragment A页面就onStop了,所以才导致了上述的情况出现

yihuajia avatar Jul 15 '19 07:07 yihuajia

重写VisibleDelegate的onPause事件。原有逻辑上,

public void onPause() {
    if (!mIsFirstVisible) {
        if (mIsSupportVisible && isFragmentVisible(mFragment)) {
            mNeedDispatch = false;
            mInvisibleWhenLeave = false;
            dispatchSupportVisible(false);
        } else {
            mInvisibleWhenLeave = true;
        }
    } else {
        if (!mInvisibleWhenLeave && !mFragment.isHidden() &&
            mFragment.getUserVisibleHint()) {
            if ((mFragment.getParentFragment() != null && isFragmentVisible(mFragment.getParentFragment()))
                || mFragment.getParentFragment() == null) {
                mNeedDispatch = false;
                enqueueDispatchVisible(false);
            }
        }
    }
}

对应的修改的地方也修改下

cocowobo avatar Jul 24 '19 09:07 cocowobo

@cocowobo 那只能是去改源码?

yihuajia avatar Jul 25 '19 03:07 yihuajia

这样改没解决问题吧,我的就没效果。

idealgn avatar Nov 07 '19 02:11 idealgn