isSupportVisible()的问题
private void dispatchSupportVisible(boolean visible) { if (visible && isParentInvisible()) { return; } if (mIsSupportVisible == visible) { mNeedDispatch = true; return; }
mIsSupportVisible = visible;
//
if (visible) {
if (checkAddState()) return;
mSupportF.onSupportVisible();
if (mIsFirstVisible) {
mIsFirstVisible = false;
mSupportF.onLazyInitView(mSaveInstanceState);
}
dispatchChild(true);
} else {
dispatchChild(false);
mSupportF.onSupportInvisible();
}
}
页面嵌套的fragment数量层级多了的时候,当前fragment的mIsSupportVisible 为true,但遍历到子的mFragment的时候得到父的isSupportVisible为false了。 private boolean isParentInvisible() { ISupportFragment fragment = (ISupportFragment) mFragment.getParentFragment(); return fragment != null && !fragment.isSupportVisible(); }
然后导致子fragment的onSupportVisible()不回调了
作者你好 VisibleDelegate里的方法 isParentInvisible(),其中 !fragment.isSupportVisible()改为!fragment.getSupportDelegate().isSupportVisible()就可以执行到。。
private boolean isParentInvisible() {
ISupportFragment fragment = (ISupportFragment) mFragment.getParentFragment();
return fragment != null && !/*fragment.isSupportVisible()*/fragment.getSupportDelegate().isSupportVisible();
}
作者你好 VisibleDelegate里的方法 isParentInvisible(),其中 !fragment.isSupportVisible()改为!fragment.getSupportDelegate().isSupportVisible()就可以执行到。。
private boolean isParentInvisible() { ISupportFragment fragment = (ISupportFragment) mFragment.getParentFragment(); return fragment != null && !/*fragment.isSupportVisible()*/fragment.getSupportDelegate().isSupportVisible(); }
@Override
final public boolean isSupportVisible() {
return mDelegate.isSupportVisible();
}
@Override
public SupportFragmentDelegate getSupportDelegate() {
return mDelegate;
}
难道不是同一个?
@liaolintao 你页面多了的时候打断点跟一下就会发现,原本是true的fragment.isSupportVisible()得到的是false,fragment.getSupportDelegate().isSupportVisible()这个值里面得到的就是你想要的结果。开始我也一直以为是同一个,但是赋值也就那么几个地方,却出现了这问题。
@Anayuta 源码写着的是同一个啊,你确定这样改了之后效果不一样?请参考liaolintao贴出来的源码。 我也碰到不回调的问题,但是情景和你们不一样
@Simon1121 我一开始也认同是同一个,根据源码看怎么都是同一个,断点跟也是同一个,但是Fragment嵌套过多的时候就会出现这情况,但是你会发现原本那个值自己知道是true的,fragment.isSupportVisible()这个得到是false,fragment.getSupportDelegate().isSupportVisible()这个得到是true,很是奇怪。