bugfix: nav fragment.

This commit is contained in:
cgspine
2020-12-05 00:05:44 +08:00
parent 984a60ae18
commit eaf0c04ee7
3 changed files with 41 additions and 20 deletions
@@ -227,7 +227,7 @@ public abstract class QMUIFragment extends Fragment implements
}
protected void checkForRequestForHandlePopBack(){
QMUIFragmentContainerProvider provider = findFragmentContainerProvider();
QMUIFragmentContainerProvider provider = findFragmentContainerProvider(false);
if(provider != null){
provider.requestForHandlePopBack(false);
}
@@ -313,20 +313,20 @@ public abstract class QMUIFragment extends Fragment implements
private void ensureFragmentEffectRegistry() {
if (mFragmentEffectRegistry == null) {
QMUIFragmentContainerProvider provider = findFragmentContainerProvider();
QMUIFragmentContainerProvider provider = findFragmentContainerProvider(false);
ViewModelStoreOwner viewModelStoreOwner = provider != null ? provider.getContainerViewModelStoreOwner() : requireActivity();
mFragmentEffectRegistry = new ViewModelProvider(viewModelStoreOwner).get(QMUIFragmentEffectRegistry.class);
}
}
@Nullable
protected QMUIFragmentContainerProvider findFragmentContainerProvider() {
Fragment parent = getParentFragment();
while (parent != null) {
if (parent instanceof QMUIFragmentContainerProvider) {
return (QMUIFragmentContainerProvider) parent;
protected QMUIFragmentContainerProvider findFragmentContainerProvider(boolean includeSelf) {
Fragment current = includeSelf ? this : getParentFragment();
while (current != null) {
if (current instanceof QMUIFragmentContainerProvider) {
return (QMUIFragmentContainerProvider) current;
} else {
parent = parent.getParentFragment();
current = current.getParentFragment();
}
}
Activity activity = getActivity();
@@ -336,7 +336,7 @@ public abstract class QMUIFragment extends Fragment implements
return null;
}
protected int startFragmentAndDestroyCurrent(QMUIFragment fragment) {
public int startFragmentAndDestroyCurrent(QMUIFragment fragment) {
return startFragmentAndDestroyCurrent(fragment, true);
}
@@ -353,13 +353,13 @@ public abstract class QMUIFragment extends Fragment implements
* @param useNewTransitionConfigWhenPop if true, use animation generated by transition C->D,
* else, use animation generated by transition B->C
*/
protected int startFragmentAndDestroyCurrent(QMUIFragment fragment,
public int startFragmentAndDestroyCurrent(QMUIFragment fragment,
boolean useNewTransitionConfigWhenPop) {
if (!checkStateLoss("startFragmentAndDestroyCurrent")) {
return -1;
}
QMUIFragmentContainerProvider provider = findFragmentContainerProvider();
QMUIFragmentContainerProvider provider = findFragmentContainerProvider(true);
if (provider == null) {
if (BuildConfig.DEBUG) {
throw new RuntimeException("Can not find the fragment container provider.");
@@ -394,7 +394,7 @@ public abstract class QMUIFragment extends Fragment implements
if (!checkStateLoss("startFragment")) {
return -1;
}
QMUIFragmentContainerProvider provider = findFragmentContainerProvider();
QMUIFragmentContainerProvider provider = findFragmentContainerProvider(true);
if (provider == null) {
if (BuildConfig.DEBUG) {
throw new RuntimeException("Can not find the fragment container provider.");
@@ -425,7 +425,7 @@ public abstract class QMUIFragment extends Fragment implements
if (requestCode == NO_REQUEST_CODE) {
throw new RuntimeException("requestCode can not be " + NO_REQUEST_CODE);
}
QMUIFragmentContainerProvider provider = findFragmentContainerProvider();
QMUIFragmentContainerProvider provider = findFragmentContainerProvider(true);
if (provider == null) {
if (BuildConfig.DEBUG) {
throw new RuntimeException("Can not find the fragment container provider.");
@@ -540,7 +540,7 @@ public abstract class QMUIFragment extends Fragment implements
@Override
public void onScrollStateChange(int state, float scrollPercent) {
Log.i(TAG, "SwipeListener:onScrollStateChange: state = " + state + " ;scrollPercent = " + scrollPercent);
QMUIFragmentContainerProvider provider = findFragmentContainerProvider();
QMUIFragmentContainerProvider provider = findFragmentContainerProvider(false);
if (provider == null || provider.getFragmentContainerView() == null) {
return;
}
@@ -618,7 +618,7 @@ public abstract class QMUIFragment extends Fragment implements
@Override
public void onScroll(int dragDirection, int moveEdge, float scrollPercent) {
scrollPercent = Math.max(0f, Math.min(1f, scrollPercent));
QMUIFragmentContainerProvider provider = findFragmentContainerProvider();
QMUIFragmentContainerProvider provider = findFragmentContainerProvider(false);
if (provider == null || provider.getFragmentContainerView() == null) {
return;
}
@@ -642,7 +642,7 @@ public abstract class QMUIFragment extends Fragment implements
@Override
public void onSwipeBackBegin(final int dragDirection, final int moveEdge) {
Log.i(TAG, "SwipeListener:onSwipeBackBegin: moveEdge = " + moveEdge);
QMUIFragmentContainerProvider provider = findFragmentContainerProvider();
QMUIFragmentContainerProvider provider = findFragmentContainerProvider(false);
if (provider == null || provider.getFragmentContainerView() == null) {
return;
}
@@ -1188,7 +1188,7 @@ public abstract class QMUIFragment extends Fragment implements
return false;
}
QMUIFragmentContainerProvider provider = findFragmentContainerProvider();
QMUIFragmentContainerProvider provider = findFragmentContainerProvider(false);
if (provider == null) {
return false;
}
@@ -102,7 +102,9 @@ public class QMUINavFragment extends QMUIFragment implements QMUIFragmentContain
@Override
protected View onCreateView() {
return new FragmentContainerView(getContext());
FragmentContainerView rootView = new FragmentContainerView(getContext());
rootView.setId(getContextViewId());
return rootView;
}
@Override
@@ -132,7 +134,7 @@ public class QMUINavFragment extends QMUIFragment implements QMUIFragmentContain
@Override
public void requestForHandlePopBack(boolean toHandle) {
isChildHandlePopBackRequested = toHandle;
QMUIFragmentContainerProvider provider = findFragmentContainerProvider();
QMUIFragmentContainerProvider provider = findFragmentContainerProvider(false);
if(provider != null){
provider.requestForHandlePopBack(toHandle || getChildFragmentManager().getBackStackEntryCount() > 1);
}
@@ -167,12 +169,18 @@ public class QMUINavFragment extends QMUIFragment implements QMUIFragmentContain
@Override
protected void checkForRequestForHandlePopBack(){
boolean enoughBackStackCount = getChildFragmentManager().getBackStackEntryCount() > 1;
QMUIFragmentContainerProvider provider = findFragmentContainerProvider();
QMUIFragmentContainerProvider provider = findFragmentContainerProvider(false);
if(provider != null){
provider.requestForHandlePopBack(isChildHandlePopBackRequested || enoughBackStackCount);
}
}
@Override
public void onResume() {
super.onResume();
checkForPrimaryNavigation();
}
@Override
public FragmentManager getContainerFragmentManager() {
return getChildFragmentManager();
@@ -28,6 +28,7 @@ import android.view.VelocityTracker;
import android.view.View;
import android.view.ViewConfiguration;
import android.view.ViewGroup;
import android.view.ViewParent;
import android.widget.FrameLayout;
import android.widget.OverScroller;
@@ -320,6 +321,7 @@ public class SwipeBackLayout extends QMUIWindowInsetLayout implements IWindowIns
mInitialMotionX = mLastMotionX = x;
mInitialMotionY = mLastMotionY = y;
onSwipeBackBegin();
requestParentDisallowInterceptTouchEvent(true);
setDragState(STATE_DRAGGING);
}
return mCurrentDragDirection;
@@ -360,6 +362,7 @@ public class SwipeBackLayout extends QMUIWindowInsetLayout implements IWindowIns
mInitialMotionY = mLastMotionY = y;
if (mDragState == STATE_SETTLING) {
if (isTouchInContentView(x, y)) {
requestParentDisallowInterceptTouchEvent(true);
setDragState(STATE_DRAGGING);
}
}
@@ -375,6 +378,7 @@ public class SwipeBackLayout extends QMUIWindowInsetLayout implements IWindowIns
onScroll();
} else {
if (isTouchInContentView(x, y)) {
requestParentDisallowInterceptTouchEvent(true);
setDragState(STATE_DRAGGING);
}
}
@@ -418,6 +422,7 @@ public class SwipeBackLayout extends QMUIWindowInsetLayout implements IWindowIns
mInitialMotionY = mLastMotionY = y;
if (mDragState == STATE_SETTLING) {
if (isTouchInContentView(x, y)) {
requestParentDisallowInterceptTouchEvent(true);
setDragState(STATE_DRAGGING);
}
}
@@ -433,6 +438,7 @@ public class SwipeBackLayout extends QMUIWindowInsetLayout implements IWindowIns
onScroll();
} else {
if (isTouchInContentView(x, y)) {
requestParentDisallowInterceptTouchEvent(true);
setDragState(STATE_DRAGGING);
}
}
@@ -462,6 +468,13 @@ public class SwipeBackLayout extends QMUIWindowInsetLayout implements IWindowIns
return true;
}
private void requestParentDisallowInterceptTouchEvent(boolean disallowIntercept) {
final ViewParent parent = getParent();
if (parent != null) {
parent.requestDisallowInterceptTouchEvent(disallowIntercept);
}
}
private void releaseViewForPointerUp() {
mVelocityTracker.computeCurrentVelocity(1000, mMaxVelocity);
int moveEdge = mViewMoveAction.getEdge(mCurrentDragDirection);