From eaf0c04ee75fa2ff820f774b449833db141547c7 Mon Sep 17 00:00:00 2001 From: cgspine Date: Sat, 5 Dec 2020 00:05:44 +0800 Subject: [PATCH] bugfix: nav fragment. --- .../com/qmuiteam/qmui/arch/QMUIFragment.java | 34 +++++++++---------- .../qmuiteam/qmui/arch/QMUINavFragment.java | 14 ++++++-- .../qmuiteam/qmui/arch/SwipeBackLayout.java | 13 +++++++ 3 files changed, 41 insertions(+), 20 deletions(-) diff --git a/arch/src/main/java/com/qmuiteam/qmui/arch/QMUIFragment.java b/arch/src/main/java/com/qmuiteam/qmui/arch/QMUIFragment.java index d66d96ce..7e1d6a0f 100644 --- a/arch/src/main/java/com/qmuiteam/qmui/arch/QMUIFragment.java +++ b/arch/src/main/java/com/qmuiteam/qmui/arch/QMUIFragment.java @@ -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; } diff --git a/arch/src/main/java/com/qmuiteam/qmui/arch/QMUINavFragment.java b/arch/src/main/java/com/qmuiteam/qmui/arch/QMUINavFragment.java index 4c5e0c29..b3181ba9 100644 --- a/arch/src/main/java/com/qmuiteam/qmui/arch/QMUINavFragment.java +++ b/arch/src/main/java/com/qmuiteam/qmui/arch/QMUINavFragment.java @@ -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(); diff --git a/arch/src/main/java/com/qmuiteam/qmui/arch/SwipeBackLayout.java b/arch/src/main/java/com/qmuiteam/qmui/arch/SwipeBackLayout.java index e2aa0671..3897b034 100644 --- a/arch/src/main/java/com/qmuiteam/qmui/arch/SwipeBackLayout.java +++ b/arch/src/main/java/com/qmuiteam/qmui/arch/SwipeBackLayout.java @@ -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);