hybrid-navigation 4.1.0 → 5.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/HybridNavigation.podspec +9 -1
- package/README.md +12 -4
- package/android/build.gradle +4 -4
- package/android/proguard-rules.pro +0 -14
- package/android/src/main/java/com/navigation/androidx/AwesomeActivity.java +116 -27
- package/android/src/main/java/com/navigation/androidx/AwesomeFragment.java +162 -13
- package/android/src/main/java/com/navigation/androidx/DefaultTabBarProvider.java +2 -2
- package/android/src/main/java/com/navigation/androidx/DrawableUtils.java +83 -18
- package/android/src/main/java/com/navigation/androidx/DrawerFragment.java +185 -25
- package/android/src/main/java/com/navigation/androidx/FragmentHelper.java +18 -0
- package/android/src/main/java/com/navigation/androidx/HybridDrawerLayout.java +563 -143
- package/android/src/main/java/com/navigation/androidx/LifecycleDelegate.java +39 -12
- package/android/src/main/java/com/navigation/androidx/PresentableActivity.java +3 -0
- package/android/src/main/java/com/navigation/androidx/PresentationDelegate.java +10 -7
- package/android/src/main/java/com/navigation/androidx/StackDelegate.java +29 -9
- package/android/src/main/java/com/navigation/androidx/StackFragment.java +31 -3
- package/android/src/main/java/com/navigation/androidx/SystemUI.java +59 -90
- package/android/src/main/java/com/navigation/androidx/TabBar.java +21 -2
- package/android/src/main/java/com/navigation/androidx/TabBarFragment.java +74 -7
- package/android/src/main/java/com/navigation/androidx/TabBarItem.java +4 -0
- package/android/src/main/java/com/navigation/androidx/TabView.java +11 -2
- package/android/src/main/java/com/reactnative/hybridnavigation/DispatchResult.java +71 -0
- package/android/src/main/java/com/reactnative/hybridnavigation/Garden.java +18 -10
- package/android/src/main/java/com/reactnative/hybridnavigation/GlobalStyle.java +34 -2
- package/android/src/main/java/com/reactnative/hybridnavigation/HBDRootView.java +20 -10
- package/android/src/main/java/com/reactnative/hybridnavigation/HybridFragment.java +179 -13
- package/android/src/main/java/com/reactnative/hybridnavigation/HybridNavigationPackage.java +13 -24
- package/android/src/main/java/com/reactnative/hybridnavigation/NativeEvent.java +5 -1
- package/android/src/main/java/com/reactnative/hybridnavigation/NativeNavigation.java +283 -183
- package/android/src/main/java/com/reactnative/hybridnavigation/NavigationCommandQueue.java +507 -0
- package/android/src/main/java/com/reactnative/hybridnavigation/Navigator.java +4 -1
- package/android/src/main/java/com/reactnative/hybridnavigation/OrientationCoordinator.java +162 -0
- package/android/src/main/java/com/reactnative/hybridnavigation/ReactAppCompatActivity.java +103 -66
- package/android/src/main/java/com/reactnative/hybridnavigation/ReactFragment.java +421 -92
- package/android/src/main/java/com/reactnative/hybridnavigation/ReactManager.java +227 -78
- package/android/src/main/java/com/reactnative/hybridnavigation/ReactStackFragment.java +6 -6
- package/android/src/main/java/com/reactnative/hybridnavigation/ReactTabBarFragment.java +26 -0
- package/android/src/main/java/com/reactnative/hybridnavigation/ReactTabBarProvider.java +8 -1
- package/android/src/main/java/com/reactnative/hybridnavigation/SceneLifecycleState.java +21 -0
- package/android/src/main/java/com/reactnative/hybridnavigation/SceneLifecycleStateMachine.java +116 -0
- package/android/src/main/java/com/reactnative/hybridnavigation/ScreenOrientation.java +42 -0
- package/android/src/main/java/com/reactnative/hybridnavigation/Utils.java +17 -0
- package/android/src/main/java/com/reactnative/hybridnavigation/navigator/DrawerNavigator.java +14 -6
- package/android/src/main/java/com/reactnative/hybridnavigation/navigator/ScreenNavigator.java +188 -26
- package/android/src/main/java/com/reactnative/hybridnavigation/navigator/StackNavigator.java +67 -16
- package/android/src/main/java/com/reactnative/hybridnavigation/navigator/TabNavigator.java +42 -14
- package/dist/DeepLink.d.ts +3 -2
- package/dist/DeepLink.js +37 -14
- package/dist/NativeEvent.d.ts +17 -10
- package/dist/NativeNavigation.d.ts +24 -18
- package/dist/Navigation.d.ts +34 -19
- package/dist/Navigation.js +225 -90
- package/dist/NavigationComponentWrap.d.ts +5 -3
- package/dist/NavigationComponentWrap.js +3 -6
- package/dist/Navigator.d.ts +32 -42
- package/dist/Navigator.js +117 -91
- package/dist/Options.d.ts +15 -3
- package/dist/Route.d.ts +149 -17
- package/dist/defineRoutes.d.ts +19 -0
- package/dist/defineRoutes.js +6 -0
- package/dist/handler/DispatchCommandHandler.d.ts +25 -6
- package/dist/handler/DispatchCommandHandler.js +99 -17
- package/dist/handler/LayoutCommandHandler.d.ts +8 -7
- package/dist/handler/LayoutCommandHandler.js +24 -15
- package/dist/handler/LeaveGuardHandler.d.ts +17 -0
- package/dist/handler/LeaveGuardHandler.js +350 -0
- package/dist/handler/LifecycleEventHandler.d.ts +30 -0
- package/dist/handler/LifecycleEventHandler.js +169 -0
- package/dist/handler/PresentationCoordinator.d.ts +24 -0
- package/dist/handler/PresentationCoordinator.js +449 -0
- package/dist/handler/ResultEventHandler.d.ts +21 -9
- package/dist/handler/ResultEventHandler.js +96 -13
- package/dist/handler/TabEventHandler.d.ts +8 -0
- package/dist/handler/TabEventHandler.js +25 -0
- package/dist/hooks.d.ts +7 -2
- package/dist/hooks.js +46 -4
- package/dist/index.d.ts +24 -0
- package/dist/index.js +3 -2
- package/dist/reveal.d.ts +46 -0
- package/dist/reveal.js +431 -0
- package/dist/routeConfigRegistry.d.ts +6 -0
- package/dist/routeConfigRegistry.js +19 -0
- package/dist/routeGraph.d.ts +12 -0
- package/dist/routeGraph.js +68 -0
- package/dist/router/drawer.d.ts +2 -2
- package/dist/router/drawer.js +6 -3
- package/dist/router/index.d.ts +8 -5
- package/dist/router/index.js +106 -58
- package/dist/router/screen.d.ts +2 -2
- package/dist/router/screen.js +1 -1
- package/dist/router/stack.d.ts +2 -2
- package/dist/router/stack.js +59 -30
- package/dist/router/tabs.d.ts +3 -2
- package/dist/router/tabs.js +4 -1
- package/dist/store.d.ts +4 -2
- package/dist/store.js +4 -0
- package/dist/testing.d.ts +79 -0
- package/dist/testing.js +251 -0
- package/ios/HBDGlobalStyle.h +29 -0
- package/ios/{GlobalStyle.mm → HBDGlobalStyle.mm} +43 -29
- package/ios/HybridNavigation.h +5 -1
- package/ios/Navigator/HBDDrawerNavigator.mm +24 -8
- package/ios/Navigator/HBDNavigatorRegistry.mm +1 -0
- package/ios/Navigator/HBDScreenNavigator.mm +278 -58
- package/ios/Navigator/HBDStackNavigator.mm +152 -61
- package/ios/Navigator/HBDTabNavigator.mm +60 -14
- package/ios/React/HBDNativeNavigation.mm +162 -123
- package/ios/React/HBDNavigator.h +37 -5
- package/ios/React/HBDOrientationCoordinator.h +29 -0
- package/ios/React/HBDOrientationCoordinator.mm +309 -0
- package/ios/React/HBDReactBridgeManager.h +46 -20
- package/ios/React/HBDReactBridgeManager.mm +496 -108
- package/ios/React/HBDSceneLifecycleStateMachine.h +38 -0
- package/ios/React/HBDSceneLifecycleStateMachine.mm +180 -0
- package/ios/View/HBDRootView.h +2 -0
- package/ios/View/HBDRootView.mm +148 -0
- package/ios/View/UIImage+WithBadge.h +3 -3
- package/ios/View/UIImage+WithBadge.mm +10 -15
- package/ios/ViewController/HBDDrawerController.mm +126 -5
- package/ios/ViewController/HBDNavigationController.mm +31 -4
- package/ios/ViewController/HBDReactViewController.h +6 -0
- package/ios/ViewController/HBDReactViewController.mm +220 -106
- package/ios/ViewController/HBDTabBarController.h +15 -0
- package/ios/ViewController/HBDTabBarController.mm +227 -45
- package/ios/ViewController/HBDTabBarRenderer.h +28 -0
- package/ios/ViewController/HBDViewController.h +11 -3
- package/ios/ViewController/HBDViewController.mm +209 -159
- package/ios/ViewController/UINavigationController+HBD.h +2 -2
- package/ios/ViewController/UINavigationController+HBD.mm +3 -3
- package/ios/ViewController/UIViewController+HBD.h +18 -10
- package/ios/ViewController/UIViewController+HBD.mm +90 -65
- package/package.json +3 -1
- package/src/DeepLink.ts +41 -14
- package/src/NativeEvent.ts +18 -11
- package/src/NativeNavigation.ts +29 -31
- package/src/Navigation.ts +377 -120
- package/src/NavigationComponentWrap.tsx +18 -9
- package/src/Navigator.ts +219 -152
- package/src/Options.ts +12 -3
- package/src/Route.ts +228 -17
- package/src/defineRoutes.ts +46 -0
- package/src/handler/DispatchCommandHandler.ts +154 -21
- package/src/handler/LayoutCommandHandler.ts +40 -17
- package/src/handler/LeaveGuardHandler.ts +436 -0
- package/src/handler/LifecycleEventHandler.ts +219 -0
- package/src/handler/PresentationCoordinator.ts +560 -0
- package/src/handler/ResultEventHandler.ts +126 -19
- package/src/handler/TabEventHandler.ts +31 -0
- package/src/hooks.ts +75 -7
- package/src/index.ts +37 -2
- package/src/reveal.ts +565 -0
- package/src/routeConfigRegistry.ts +26 -0
- package/src/routeGraph.ts +87 -0
- package/src/router/drawer.ts +8 -5
- package/src/router/index.ts +139 -63
- package/src/router/screen.ts +3 -3
- package/src/router/stack.ts +80 -29
- package/src/router/tabs.ts +16 -7
- package/src/store.ts +6 -1
- package/src/testing.ts +395 -0
- package/testing.d.ts +1 -0
- package/testing.js +3 -0
- package/android/src/main/java/androidx/fragment/app/InternalFragment.java +0 -22
- package/android/src/main/java/com/navigation/androidx/SystemUI30.java +0 -87
- package/android/src/main/java/com/reactnative/hybridnavigation/NativeGarden.java +0 -176
- package/android/src/main/java/com/reactnative/hybridnavigation/ReactTabBar.java +0 -130
- package/android/src/main/res/layout/nav_tab_bar_react.xml +0 -32
- package/android/src/main/res/layout/nav_tab_bar_react_indeterminate.xml +0 -32
- package/dist/NativeGarden.d.ts +0 -13
- package/dist/NativeGarden.js +0 -2
- package/dist/handler/VisibilityEventHandler.d.ts +0 -13
- package/dist/handler/VisibilityEventHandler.js +0 -39
- package/ios/GlobalStyle.h +0 -15
- package/ios/React/HBDNativeGarden.h +0 -10
- package/ios/React/HBDNativeGarden.mm +0 -111
- package/src/NativeGarden.ts +0 -16
- package/src/handler/VisibilityEventHandler.ts +0 -52
|
@@ -1,8 +1,13 @@
|
|
|
1
1
|
package com.navigation.androidx;
|
|
2
2
|
|
|
3
|
+
import android.annotation.SuppressLint;
|
|
3
4
|
import android.app.Activity;
|
|
4
5
|
import android.content.Context;
|
|
5
6
|
import android.content.ContextWrapper;
|
|
7
|
+
import android.content.res.TypedArray;
|
|
8
|
+
import android.graphics.Canvas;
|
|
9
|
+
import android.graphics.Color;
|
|
10
|
+
import android.graphics.Paint;
|
|
6
11
|
import android.graphics.Rect;
|
|
7
12
|
import android.os.Build;
|
|
8
13
|
import android.util.AttributeSet;
|
|
@@ -18,21 +23,91 @@ import android.window.OnBackAnimationCallback;
|
|
|
18
23
|
import android.window.OnBackInvokedCallback;
|
|
19
24
|
import android.window.OnBackInvokedDispatcher;
|
|
20
25
|
|
|
26
|
+
import androidx.activity.ComponentActivity;
|
|
27
|
+
import androidx.annotation.NonNull;
|
|
28
|
+
import androidx.annotation.Nullable;
|
|
29
|
+
import androidx.core.view.GravityCompat;
|
|
30
|
+
import androidx.customview.widget.ViewDragHelper;
|
|
31
|
+
|
|
21
32
|
import com.facebook.react.uimanager.RootView;
|
|
22
33
|
import com.facebook.react.uimanager.events.NativeGestureUtil;
|
|
23
34
|
|
|
24
|
-
import java.lang.reflect.Field;
|
|
25
|
-
import java.lang.reflect.InvocationTargetException;
|
|
26
|
-
import java.lang.reflect.Method;
|
|
27
35
|
import java.util.ArrayList;
|
|
28
36
|
import java.util.Collections;
|
|
37
|
+
import java.util.List;
|
|
38
|
+
import java.util.concurrent.CopyOnWriteArrayList;
|
|
29
39
|
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
40
|
+
public class HybridDrawerLayout extends ViewGroup {
|
|
41
|
+
|
|
42
|
+
public static final int STATE_IDLE = 0;
|
|
43
|
+
public static final int STATE_DRAGGING = 1;
|
|
44
|
+
public static final int STATE_SETTLING = 2;
|
|
45
|
+
|
|
46
|
+
public static final int LOCK_MODE_UNLOCKED = 0;
|
|
47
|
+
public static final int LOCK_MODE_LOCKED_CLOSED = 1;
|
|
48
|
+
public static final int LOCK_MODE_LOCKED_OPEN = 2;
|
|
49
|
+
|
|
50
|
+
public interface DrawerListener {
|
|
51
|
+
void onDrawerSlide(@NonNull View drawerView, float slideOffset);
|
|
52
|
+
void onDrawerOpened(@NonNull View drawerView);
|
|
53
|
+
void onDrawerClosed(@NonNull View drawerView);
|
|
54
|
+
void onDrawerStateChanged(int newState);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
public static abstract class SimpleDrawerListener implements DrawerListener {
|
|
58
|
+
@Override
|
|
59
|
+
public void onDrawerSlide(@NonNull View drawerView, float slideOffset) {
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
@Override
|
|
63
|
+
public void onDrawerOpened(@NonNull View drawerView) {
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
@Override
|
|
67
|
+
public void onDrawerClosed(@NonNull View drawerView) {
|
|
68
|
+
}
|
|
34
69
|
|
|
35
|
-
|
|
70
|
+
@Override
|
|
71
|
+
public void onDrawerStateChanged(int newState) {
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
public static class LayoutParams extends MarginLayoutParams {
|
|
76
|
+
private static final int[] LAYOUT_ATTRS = new int[]{android.R.attr.layout_gravity};
|
|
77
|
+
public int gravity = Gravity.NO_GRAVITY;
|
|
78
|
+
|
|
79
|
+
public LayoutParams(@NonNull Context context, @Nullable AttributeSet attrs) {
|
|
80
|
+
super(context, attrs);
|
|
81
|
+
TypedArray typedArray = context.obtainStyledAttributes(attrs, LAYOUT_ATTRS);
|
|
82
|
+
try {
|
|
83
|
+
gravity = typedArray.getInt(0, Gravity.NO_GRAVITY);
|
|
84
|
+
} finally {
|
|
85
|
+
typedArray.recycle();
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
public LayoutParams(int width, int height) {
|
|
90
|
+
super(width, height);
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
public LayoutParams(int width, int height, int gravity) {
|
|
94
|
+
super(width, height);
|
|
95
|
+
this.gravity = gravity;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
public LayoutParams(@NonNull LayoutParams source) {
|
|
99
|
+
super(source);
|
|
100
|
+
this.gravity = source.gravity;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
public LayoutParams(@NonNull MarginLayoutParams source) {
|
|
104
|
+
super(source);
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
public LayoutParams(@NonNull ViewGroup.LayoutParams source) {
|
|
108
|
+
super(source);
|
|
109
|
+
}
|
|
110
|
+
}
|
|
36
111
|
|
|
37
112
|
private static final int DRAG_NONE = 0;
|
|
38
113
|
private static final int DRAG_OPEN = 1;
|
|
@@ -45,39 +120,52 @@ public class HybridDrawerLayout extends DrawerLayout {
|
|
|
45
120
|
private static final float OPEN_SETTLE_THRESHOLD = 0.22f;
|
|
46
121
|
private static final float CLOSE_SETTLE_THRESHOLD = 0.78f;
|
|
47
122
|
private static final float DRAWER_CLOSED_EPSILON = 0.01f;
|
|
123
|
+
private static final float DRAWER_OPEN_EPSILON = 0.99f;
|
|
48
124
|
|
|
49
125
|
private final int openEdgeWidth;
|
|
50
126
|
private final int systemGestureExclusionWidth;
|
|
51
127
|
private final int openGestureTriggerDistance;
|
|
52
128
|
private final int settleVelocity;
|
|
53
129
|
private final int touchSlop;
|
|
130
|
+
private final ViewDragHelper dragHelper;
|
|
131
|
+
private final Paint scrimPaint = new Paint();
|
|
132
|
+
private final List<DrawerListener> listeners = new CopyOnWriteArrayList<>();
|
|
133
|
+
|
|
134
|
+
private int scrimColor = Color.TRANSPARENT;
|
|
135
|
+
private float drawerElevation = 0f;
|
|
136
|
+
private int lockMode = LOCK_MODE_UNLOCKED;
|
|
137
|
+
private int drawerState = STATE_IDLE;
|
|
138
|
+
private float drawerProgress = 0f;
|
|
139
|
+
private boolean drawerOpened = false;
|
|
140
|
+
private boolean pendingOpenNotify = false;
|
|
141
|
+
private boolean pendingCloseNotify = false;
|
|
142
|
+
|
|
54
143
|
private float downX;
|
|
55
144
|
private float downY;
|
|
56
145
|
private float dragStartProgress;
|
|
57
146
|
private boolean closeDragCandidate;
|
|
58
147
|
private boolean openDragCandidate;
|
|
148
|
+
private boolean tapOutsideDrawerCandidate;
|
|
59
149
|
private boolean openGestureEnabled;
|
|
60
150
|
private boolean nativeGestureStarted;
|
|
61
151
|
private int activeDragMode = DRAG_NONE;
|
|
62
152
|
private View activeDrawerChild;
|
|
63
153
|
private View activeNativeGestureView;
|
|
64
154
|
private VelocityTracker velocityTracker;
|
|
155
|
+
|
|
65
156
|
private OnBackInvokedCallback backGestureCallback;
|
|
66
157
|
private boolean backGestureCallbackRegistered;
|
|
67
158
|
private boolean backGestureActive;
|
|
68
|
-
private float backGestureProgress;
|
|
69
|
-
private Method getDrawerViewOffsetMethod;
|
|
70
|
-
private Method moveDrawerToOffsetMethod;
|
|
71
159
|
|
|
72
|
-
public HybridDrawerLayout(Context context) {
|
|
160
|
+
public HybridDrawerLayout(@NonNull Context context) {
|
|
73
161
|
this(context, null);
|
|
74
162
|
}
|
|
75
163
|
|
|
76
|
-
public HybridDrawerLayout(Context context, AttributeSet attrs) {
|
|
164
|
+
public HybridDrawerLayout(@NonNull Context context, @Nullable AttributeSet attrs) {
|
|
77
165
|
this(context, attrs, 0);
|
|
78
166
|
}
|
|
79
167
|
|
|
80
|
-
public HybridDrawerLayout(Context context, AttributeSet attrs, int defStyle) {
|
|
168
|
+
public HybridDrawerLayout(@NonNull Context context, @Nullable AttributeSet attrs, int defStyle) {
|
|
81
169
|
super(context, attrs, defStyle);
|
|
82
170
|
float density = getResources().getDisplayMetrics().density;
|
|
83
171
|
openEdgeWidth = Math.round(OPEN_EDGE_WIDTH_DP * density);
|
|
@@ -85,7 +173,95 @@ public class HybridDrawerLayout extends DrawerLayout {
|
|
|
85
173
|
touchSlop = ViewConfiguration.get(context).getScaledTouchSlop();
|
|
86
174
|
openGestureTriggerDistance = Math.max(touchSlop * 2, Math.round(OPEN_GESTURE_ACTIVATION_DISTANCE_DP * density));
|
|
87
175
|
settleVelocity = Math.round(SETTLE_VELOCITY_DP * density);
|
|
88
|
-
|
|
176
|
+
dragHelper = ViewDragHelper.create(this, 1.0f, new ViewDragHelper.Callback() {
|
|
177
|
+
@Override
|
|
178
|
+
public boolean tryCaptureView(@NonNull View child, int pointerId) {
|
|
179
|
+
return isDrawerChild(child);
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
@Override
|
|
183
|
+
public int getViewHorizontalDragRange(@NonNull View child) {
|
|
184
|
+
return isDrawerChild(child) ? child.getWidth() : 0;
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
@Override
|
|
188
|
+
public int clampViewPositionHorizontal(@NonNull View child, int left, int dx) {
|
|
189
|
+
int width = child.getWidth();
|
|
190
|
+
if (isStartDrawerOnLeft(child)) {
|
|
191
|
+
return Math.max(-width, Math.min(0, left));
|
|
192
|
+
}
|
|
193
|
+
int parentWidth = getWidth();
|
|
194
|
+
return Math.max(parentWidth - width, Math.min(parentWidth, left));
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
@Override
|
|
198
|
+
public int clampViewPositionVertical(@NonNull View child, int top, int dy) {
|
|
199
|
+
return child.getTop();
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
@Override
|
|
203
|
+
public void onViewPositionChanged(@NonNull View changedView, int left, int top, int dx, int dy) {
|
|
204
|
+
int drawerWidth = changedView.getWidth();
|
|
205
|
+
if (drawerWidth <= 0) {
|
|
206
|
+
return;
|
|
207
|
+
}
|
|
208
|
+
float progress;
|
|
209
|
+
if (isStartDrawerOnLeft(changedView)) {
|
|
210
|
+
progress = (left + drawerWidth) / (float) drawerWidth;
|
|
211
|
+
} else {
|
|
212
|
+
progress = (getWidth() - left) / (float) drawerWidth;
|
|
213
|
+
}
|
|
214
|
+
updateDrawerProgressInternal(changedView, progress);
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
@Override
|
|
218
|
+
public void onViewDragStateChanged(int state) {
|
|
219
|
+
if (activeDragMode != DRAG_NONE || backGestureActive) {
|
|
220
|
+
return;
|
|
221
|
+
}
|
|
222
|
+
int mappedState = switch (state) {
|
|
223
|
+
case ViewDragHelper.STATE_DRAGGING -> STATE_DRAGGING;
|
|
224
|
+
case ViewDragHelper.STATE_SETTLING -> STATE_SETTLING;
|
|
225
|
+
default -> STATE_IDLE;
|
|
226
|
+
};
|
|
227
|
+
setDrawerState(mappedState);
|
|
228
|
+
if (mappedState == STATE_IDLE) {
|
|
229
|
+
finalizeDrawerSettle();
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
});
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
public void addDrawerListener(@NonNull DrawerListener listener) {
|
|
236
|
+
if (!listeners.contains(listener)) {
|
|
237
|
+
listeners.add(listener);
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
public void removeDrawerListener(@NonNull DrawerListener listener) {
|
|
242
|
+
listeners.remove(listener);
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
public void setScrimColor(int color) {
|
|
246
|
+
scrimColor = color;
|
|
247
|
+
invalidate();
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
public void setDrawerElevation(float elevation) {
|
|
251
|
+
drawerElevation = elevation;
|
|
252
|
+
View drawer = findDrawerChild();
|
|
253
|
+
if (drawer != null) {
|
|
254
|
+
drawer.setElevation(elevation);
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
public void setDrawerLockMode(int lockMode, int edgeGravity) {
|
|
259
|
+
this.lockMode = lockMode;
|
|
260
|
+
if (lockMode == LOCK_MODE_LOCKED_CLOSED && isDrawerVisible(edgeGravity)) {
|
|
261
|
+
closeDrawer(edgeGravity);
|
|
262
|
+
} else if (lockMode == LOCK_MODE_LOCKED_OPEN && !isDrawerOpen(edgeGravity)) {
|
|
263
|
+
openDrawer(edgeGravity);
|
|
264
|
+
}
|
|
89
265
|
}
|
|
90
266
|
|
|
91
267
|
public void setOpenGestureEnabled(boolean enabled) {
|
|
@@ -94,6 +270,180 @@ public class HybridDrawerLayout extends DrawerLayout {
|
|
|
94
270
|
updateBackGestureCallback();
|
|
95
271
|
}
|
|
96
272
|
|
|
273
|
+
public boolean isDrawerOpen(int drawerGravity) {
|
|
274
|
+
return pendingOpenNotify || (!pendingCloseNotify && (drawerOpened || drawerProgress >= DRAWER_OPEN_EPSILON));
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
public boolean isDrawerVisible(int drawerGravity) {
|
|
278
|
+
return drawerProgress > DRAWER_CLOSED_EPSILON;
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
public void openDrawer(int gravity) {
|
|
282
|
+
View drawerChild = findDrawerChild();
|
|
283
|
+
if (drawerChild == null) {
|
|
284
|
+
return;
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
if (!isLaidOut() || drawerChild.getWidth() <= 0) {
|
|
288
|
+
drawerProgress = 1f;
|
|
289
|
+
pendingOpenNotify = true;
|
|
290
|
+
pendingCloseNotify = false;
|
|
291
|
+
drawerChild.setVisibility(VISIBLE);
|
|
292
|
+
requestLayout();
|
|
293
|
+
return;
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
drawerChild.setVisibility(VISIBLE);
|
|
297
|
+
int targetLeft = computeDrawerLeft(drawerChild, 1f);
|
|
298
|
+
if (drawerChild.getLeft() == targetLeft && drawerProgress >= DRAWER_OPEN_EPSILON) {
|
|
299
|
+
updateDrawerProgressInternal(drawerChild, 1f);
|
|
300
|
+
dispatchDrawerOpened(drawerChild);
|
|
301
|
+
return;
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
setDrawerState(STATE_SETTLING);
|
|
305
|
+
if (dragHelper.smoothSlideViewTo(drawerChild, targetLeft, drawerChild.getTop())) {
|
|
306
|
+
postInvalidateOnAnimation();
|
|
307
|
+
} else {
|
|
308
|
+
positionDrawerToProgress(drawerChild, 1f);
|
|
309
|
+
setDrawerState(STATE_IDLE);
|
|
310
|
+
dispatchDrawerOpened(drawerChild);
|
|
311
|
+
}
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
public void closeDrawer(int gravity) {
|
|
315
|
+
View drawerChild = findDrawerChild();
|
|
316
|
+
if (drawerChild == null) {
|
|
317
|
+
return;
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
if (!isLaidOut() || drawerChild.getWidth() <= 0) {
|
|
321
|
+
drawerProgress = 0f;
|
|
322
|
+
pendingCloseNotify = drawerOpened;
|
|
323
|
+
pendingOpenNotify = false;
|
|
324
|
+
drawerChild.setVisibility(INVISIBLE);
|
|
325
|
+
requestLayout();
|
|
326
|
+
return;
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
int targetLeft = computeDrawerLeft(drawerChild, 0f);
|
|
330
|
+
if (drawerChild.getLeft() == targetLeft && drawerProgress <= DRAWER_CLOSED_EPSILON) {
|
|
331
|
+
updateDrawerProgressInternal(drawerChild, 0f);
|
|
332
|
+
drawerChild.setVisibility(INVISIBLE);
|
|
333
|
+
dispatchDrawerClosed(drawerChild);
|
|
334
|
+
return;
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
setDrawerState(STATE_SETTLING);
|
|
338
|
+
if (dragHelper.smoothSlideViewTo(drawerChild, targetLeft, drawerChild.getTop())) {
|
|
339
|
+
postInvalidateOnAnimation();
|
|
340
|
+
} else {
|
|
341
|
+
positionDrawerToProgress(drawerChild, 0f);
|
|
342
|
+
drawerChild.setVisibility(INVISIBLE);
|
|
343
|
+
setDrawerState(STATE_IDLE);
|
|
344
|
+
dispatchDrawerClosed(drawerChild);
|
|
345
|
+
}
|
|
346
|
+
}
|
|
347
|
+
|
|
348
|
+
@Override
|
|
349
|
+
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
|
|
350
|
+
int widthSize = MeasureSpec.getSize(widthMeasureSpec);
|
|
351
|
+
int heightSize = MeasureSpec.getSize(heightMeasureSpec);
|
|
352
|
+
setMeasuredDimension(widthSize, heightSize);
|
|
353
|
+
|
|
354
|
+
int count = getChildCount();
|
|
355
|
+
for (int i = 0; i < count; i++) {
|
|
356
|
+
View child = getChildAt(i);
|
|
357
|
+
if (child.getVisibility() == GONE) {
|
|
358
|
+
continue;
|
|
359
|
+
}
|
|
360
|
+
|
|
361
|
+
LayoutParams lp = (LayoutParams) child.getLayoutParams();
|
|
362
|
+
if (isDrawerChild(child)) {
|
|
363
|
+
int horizontalMargins = lp.leftMargin + lp.rightMargin;
|
|
364
|
+
int verticalMargins = lp.topMargin + lp.bottomMargin;
|
|
365
|
+
int drawerWidthSpec = getChildMeasureSpec(widthMeasureSpec, Math.max(0, horizontalMargins), lp.width);
|
|
366
|
+
int drawerHeightSpec = getChildMeasureSpec(heightMeasureSpec, Math.max(0, verticalMargins), lp.height);
|
|
367
|
+
child.measure(drawerWidthSpec, drawerHeightSpec);
|
|
368
|
+
child.setElevation(drawerElevation);
|
|
369
|
+
} else {
|
|
370
|
+
int contentWidthSpec = MeasureSpec.makeMeasureSpec(
|
|
371
|
+
Math.max(0, widthSize - lp.leftMargin - lp.rightMargin),
|
|
372
|
+
MeasureSpec.EXACTLY
|
|
373
|
+
);
|
|
374
|
+
int contentHeightSpec = MeasureSpec.makeMeasureSpec(
|
|
375
|
+
Math.max(0, heightSize - lp.topMargin - lp.bottomMargin),
|
|
376
|
+
MeasureSpec.EXACTLY
|
|
377
|
+
);
|
|
378
|
+
child.measure(contentWidthSpec, contentHeightSpec);
|
|
379
|
+
}
|
|
380
|
+
}
|
|
381
|
+
}
|
|
382
|
+
|
|
383
|
+
@Override
|
|
384
|
+
protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
|
|
385
|
+
int width = right - left;
|
|
386
|
+
int height = bottom - top;
|
|
387
|
+
int count = getChildCount();
|
|
388
|
+
|
|
389
|
+
for (int i = 0; i < count; i++) {
|
|
390
|
+
View child = getChildAt(i);
|
|
391
|
+
if (child.getVisibility() == GONE) {
|
|
392
|
+
continue;
|
|
393
|
+
}
|
|
394
|
+
|
|
395
|
+
LayoutParams lp = (LayoutParams) child.getLayoutParams();
|
|
396
|
+
if (isDrawerChild(child)) {
|
|
397
|
+
int childWidth = child.getMeasuredWidth();
|
|
398
|
+
int childHeight = child.getMeasuredHeight();
|
|
399
|
+
int childLeft = computeDrawerLeft(child, drawerProgress, width, childWidth);
|
|
400
|
+
int childTop = lp.topMargin;
|
|
401
|
+
child.layout(childLeft, childTop, childLeft + childWidth, childTop + Math.min(height, childHeight));
|
|
402
|
+
child.setVisibility(drawerProgress > 0f ? VISIBLE : INVISIBLE);
|
|
403
|
+
} else {
|
|
404
|
+
child.layout(
|
|
405
|
+
lp.leftMargin,
|
|
406
|
+
lp.topMargin,
|
|
407
|
+
lp.leftMargin + child.getMeasuredWidth(),
|
|
408
|
+
lp.topMargin + child.getMeasuredHeight()
|
|
409
|
+
);
|
|
410
|
+
}
|
|
411
|
+
}
|
|
412
|
+
|
|
413
|
+
View drawerChild = findDrawerChild();
|
|
414
|
+
if (drawerChild != null) {
|
|
415
|
+
if (pendingOpenNotify) {
|
|
416
|
+
pendingOpenNotify = false;
|
|
417
|
+
dispatchDrawerSlide(drawerChild, 1f);
|
|
418
|
+
dispatchDrawerOpened(drawerChild);
|
|
419
|
+
} else if (pendingCloseNotify) {
|
|
420
|
+
pendingCloseNotify = false;
|
|
421
|
+
dispatchDrawerSlide(drawerChild, 0f);
|
|
422
|
+
dispatchDrawerClosed(drawerChild);
|
|
423
|
+
}
|
|
424
|
+
}
|
|
425
|
+
}
|
|
426
|
+
|
|
427
|
+
@Override
|
|
428
|
+
protected boolean drawChild(@NonNull Canvas canvas, @NonNull View child, long drawingTime) {
|
|
429
|
+
boolean result = super.drawChild(canvas, child, drawingTime);
|
|
430
|
+
if (scrimColor != Color.TRANSPARENT && !isDrawerChild(child) && drawerProgress > 0f) {
|
|
431
|
+
int baseAlpha = (scrimColor & 0xff000000) >>> 24;
|
|
432
|
+
int alpha = (int) (baseAlpha * drawerProgress);
|
|
433
|
+
int color = (alpha << 24) | (scrimColor & 0x00ffffff);
|
|
434
|
+
scrimPaint.setColor(color);
|
|
435
|
+
canvas.drawRect(0, 0, getWidth(), getHeight(), scrimPaint);
|
|
436
|
+
}
|
|
437
|
+
return result;
|
|
438
|
+
}
|
|
439
|
+
|
|
440
|
+
@Override
|
|
441
|
+
public void computeScroll() {
|
|
442
|
+
if (dragHelper.continueSettling(true)) {
|
|
443
|
+
postInvalidateOnAnimation();
|
|
444
|
+
}
|
|
445
|
+
}
|
|
446
|
+
|
|
97
447
|
@Override
|
|
98
448
|
public void requestDisallowInterceptTouchEvent(boolean disallowIntercept) {
|
|
99
449
|
if (disallowIntercept && (openDragCandidate || activeDragMode != DRAG_NONE)) {
|
|
@@ -138,6 +488,15 @@ public class HybridDrawerLayout extends DrawerLayout {
|
|
|
138
488
|
return handleActiveDrawerDrag(event);
|
|
139
489
|
}
|
|
140
490
|
} else if (action == MotionEvent.ACTION_UP || action == MotionEvent.ACTION_CANCEL) {
|
|
491
|
+
if (tapOutsideDrawerCandidate && action == MotionEvent.ACTION_UP && isDrawerVisible(GravityCompat.START)) {
|
|
492
|
+
float dx = Math.abs(event.getX() - downX);
|
|
493
|
+
float dy = Math.abs(event.getY() - downY);
|
|
494
|
+
if (dx <= touchSlop && dy <= touchSlop && lockMode != LOCK_MODE_LOCKED_OPEN) {
|
|
495
|
+
closeDrawer(GravityCompat.START);
|
|
496
|
+
resetTouchTracking();
|
|
497
|
+
return true;
|
|
498
|
+
}
|
|
499
|
+
}
|
|
141
500
|
resetTouchTracking();
|
|
142
501
|
}
|
|
143
502
|
|
|
@@ -146,20 +505,15 @@ public class HybridDrawerLayout extends DrawerLayout {
|
|
|
146
505
|
|
|
147
506
|
@Override
|
|
148
507
|
public boolean onInterceptTouchEvent(MotionEvent event) {
|
|
149
|
-
|
|
150
|
-
if (activeDragMode != DRAG_NONE) {
|
|
508
|
+
if (activeDragMode != DRAG_NONE || tapOutsideDrawerCandidate) {
|
|
151
509
|
return true;
|
|
152
510
|
}
|
|
153
511
|
|
|
154
|
-
|
|
155
|
-
return isDrawerVisible(GravityCompat.START) && super.onInterceptTouchEvent(event);
|
|
156
|
-
}
|
|
157
|
-
|
|
512
|
+
int action = event.getActionMasked();
|
|
158
513
|
if (!isDrawerVisible(GravityCompat.START)) {
|
|
159
514
|
if (!openGestureEnabled || !openDragCandidate) {
|
|
160
515
|
return false;
|
|
161
516
|
}
|
|
162
|
-
|
|
163
517
|
if (action == MotionEvent.ACTION_MOVE && isVerticalGesture(event)) {
|
|
164
518
|
openDragCandidate = false;
|
|
165
519
|
} else if (action == MotionEvent.ACTION_UP || action == MotionEvent.ACTION_CANCEL) {
|
|
@@ -168,13 +522,39 @@ public class HybridDrawerLayout extends DrawerLayout {
|
|
|
168
522
|
return false;
|
|
169
523
|
}
|
|
170
524
|
|
|
171
|
-
return
|
|
525
|
+
return false;
|
|
526
|
+
}
|
|
527
|
+
|
|
528
|
+
@SuppressLint("ClickableViewAccessibility")
|
|
529
|
+
@Override
|
|
530
|
+
public boolean onTouchEvent(MotionEvent event) {
|
|
531
|
+
return activeDragMode != DRAG_NONE || tapOutsideDrawerCandidate;
|
|
172
532
|
}
|
|
173
533
|
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
534
|
+
@Override
|
|
535
|
+
protected ViewGroup.LayoutParams generateDefaultLayoutParams() {
|
|
536
|
+
return new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
|
|
537
|
+
}
|
|
538
|
+
|
|
539
|
+
@Override
|
|
540
|
+
protected ViewGroup.LayoutParams generateLayoutParams(ViewGroup.LayoutParams p) {
|
|
541
|
+
if (p instanceof LayoutParams lp) {
|
|
542
|
+
return new LayoutParams(lp);
|
|
543
|
+
}
|
|
544
|
+
if (p instanceof MarginLayoutParams mlp) {
|
|
545
|
+
return new LayoutParams(mlp);
|
|
546
|
+
}
|
|
547
|
+
return new LayoutParams(p);
|
|
548
|
+
}
|
|
549
|
+
|
|
550
|
+
@Override
|
|
551
|
+
protected boolean checkLayoutParams(ViewGroup.LayoutParams p) {
|
|
552
|
+
return p instanceof LayoutParams && super.checkLayoutParams(p);
|
|
553
|
+
}
|
|
554
|
+
|
|
555
|
+
@Override
|
|
556
|
+
public ViewGroup.LayoutParams generateLayoutParams(AttributeSet attrs) {
|
|
557
|
+
return new LayoutParams(getContext(), attrs);
|
|
178
558
|
}
|
|
179
559
|
|
|
180
560
|
private void updateBackGestureCallback() {
|
|
@@ -216,18 +596,17 @@ public class HybridDrawerLayout extends DrawerLayout {
|
|
|
216
596
|
backGestureCallbackRegistered = false;
|
|
217
597
|
backGestureCallback = null;
|
|
218
598
|
backGestureActive = false;
|
|
219
|
-
backGestureProgress = 0;
|
|
220
599
|
}
|
|
221
600
|
|
|
222
601
|
private OnBackAnimationCallback createBackGestureCallback() {
|
|
223
602
|
return new OnBackAnimationCallback() {
|
|
224
603
|
@Override
|
|
225
|
-
public void onBackStarted(BackEvent backEvent) {
|
|
604
|
+
public void onBackStarted(@NonNull BackEvent backEvent) {
|
|
226
605
|
beginBackGesture(backEvent);
|
|
227
606
|
}
|
|
228
607
|
|
|
229
608
|
@Override
|
|
230
|
-
public void onBackProgressed(BackEvent backEvent) {
|
|
609
|
+
public void onBackProgressed(@NonNull BackEvent backEvent) {
|
|
231
610
|
progressBackGesture(backEvent);
|
|
232
611
|
}
|
|
233
612
|
|
|
@@ -245,9 +624,9 @@ public class HybridDrawerLayout extends DrawerLayout {
|
|
|
245
624
|
|
|
246
625
|
private void beginBackGesture(BackEvent backEvent) {
|
|
247
626
|
backGestureActive = openGestureEnabled
|
|
627
|
+
&& lockMode != LOCK_MODE_LOCKED_CLOSED
|
|
248
628
|
&& backEvent.getSwipeEdge() == BackEvent.EDGE_LEFT
|
|
249
629
|
&& isDrawerClosed();
|
|
250
|
-
backGestureProgress = 0;
|
|
251
630
|
|
|
252
631
|
if (backGestureActive) {
|
|
253
632
|
activeDrawerChild = findDrawerChild();
|
|
@@ -255,8 +634,10 @@ public class HybridDrawerLayout extends DrawerLayout {
|
|
|
255
634
|
backGestureActive = false;
|
|
256
635
|
return;
|
|
257
636
|
}
|
|
637
|
+
dragHelper.abort();
|
|
638
|
+
setDrawerState(STATE_DRAGGING);
|
|
258
639
|
performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY);
|
|
259
|
-
|
|
640
|
+
positionDrawerToProgress(activeDrawerChild, 0f);
|
|
260
641
|
}
|
|
261
642
|
}
|
|
262
643
|
|
|
@@ -264,17 +645,17 @@ public class HybridDrawerLayout extends DrawerLayout {
|
|
|
264
645
|
if (!backGestureActive || activeDrawerChild == null) {
|
|
265
646
|
return;
|
|
266
647
|
}
|
|
267
|
-
|
|
268
|
-
backGestureProgress = backEvent.getProgress();
|
|
269
|
-
moveDrawerToProgress(activeDrawerChild, backGestureProgress);
|
|
648
|
+
positionDrawerToProgress(activeDrawerChild, backEvent.getProgress());
|
|
270
649
|
}
|
|
271
650
|
|
|
272
651
|
private void cancelBackGesture() {
|
|
273
652
|
if (backGestureActive) {
|
|
653
|
+
backGestureActive = false;
|
|
654
|
+
activeDrawerChild = null;
|
|
274
655
|
closeDrawer(GravityCompat.START);
|
|
656
|
+
return;
|
|
275
657
|
}
|
|
276
658
|
backGestureActive = false;
|
|
277
|
-
backGestureProgress = 0;
|
|
278
659
|
activeDrawerChild = null;
|
|
279
660
|
}
|
|
280
661
|
|
|
@@ -284,10 +665,9 @@ public class HybridDrawerLayout extends DrawerLayout {
|
|
|
284
665
|
return;
|
|
285
666
|
}
|
|
286
667
|
|
|
287
|
-
openDrawer(GravityCompat.START);
|
|
288
668
|
backGestureActive = false;
|
|
289
|
-
backGestureProgress = 0;
|
|
290
669
|
activeDrawerChild = null;
|
|
670
|
+
openDrawer(GravityCompat.START);
|
|
291
671
|
}
|
|
292
672
|
|
|
293
673
|
private void invokeFallbackBack() {
|
|
@@ -296,25 +676,13 @@ public class HybridDrawerLayout extends DrawerLayout {
|
|
|
296
676
|
}
|
|
297
677
|
|
|
298
678
|
Activity activity = findActivity();
|
|
299
|
-
if (activity instanceof
|
|
300
|
-
|
|
301
|
-
} else if (activity != null) {
|
|
302
|
-
activity.onBackPressed();
|
|
679
|
+
if (activity instanceof ComponentActivity componentActivity) {
|
|
680
|
+
componentActivity.getOnBackPressedDispatcher().onBackPressed();
|
|
303
681
|
}
|
|
304
682
|
|
|
305
683
|
post(this::updateBackGestureCallback);
|
|
306
684
|
}
|
|
307
685
|
|
|
308
|
-
private Method findDrawerLayoutMethod(String name, Class<?>... parameterTypes) {
|
|
309
|
-
try {
|
|
310
|
-
Method method = DrawerLayout.class.getDeclaredMethod(name, parameterTypes);
|
|
311
|
-
method.setAccessible(true);
|
|
312
|
-
return method;
|
|
313
|
-
} catch (NoSuchMethodException ignored) {
|
|
314
|
-
return null;
|
|
315
|
-
}
|
|
316
|
-
}
|
|
317
|
-
|
|
318
686
|
private void updateSystemGestureExclusionRect() {
|
|
319
687
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
|
|
320
688
|
if (openGestureEnabled) {
|
|
@@ -326,48 +694,64 @@ public class HybridDrawerLayout extends DrawerLayout {
|
|
|
326
694
|
}
|
|
327
695
|
}
|
|
328
696
|
|
|
329
|
-
private void setDrawerEdgeSize(int edgeSize) {
|
|
330
|
-
try {
|
|
331
|
-
Field leftDraggerField = DrawerLayout.class.getDeclaredField("mLeftDragger");
|
|
332
|
-
leftDraggerField.setAccessible(true);
|
|
333
|
-
ViewDragHelper leftDragger = (ViewDragHelper) leftDraggerField.get(this);
|
|
334
|
-
Field edgeSizeField = leftDragger.getClass().getDeclaredField("mEdgeSize");
|
|
335
|
-
edgeSizeField.setAccessible(true);
|
|
336
|
-
edgeSizeField.setInt(leftDragger, edgeSize);
|
|
337
|
-
} catch (NoSuchFieldException | IllegalAccessException | ClassCastException ignored) {
|
|
338
|
-
}
|
|
339
|
-
}
|
|
340
|
-
|
|
341
697
|
private void beginTouchTracking(MotionEvent event) {
|
|
342
698
|
downX = event.getX();
|
|
343
699
|
downY = event.getY();
|
|
344
|
-
dragStartProgress =
|
|
700
|
+
dragStartProgress = 0f;
|
|
345
701
|
activeDragMode = DRAG_NONE;
|
|
346
702
|
activeDrawerChild = findDrawerChild();
|
|
347
|
-
float
|
|
348
|
-
|
|
349
|
-
|
|
703
|
+
float currentProgress = drawerProgress;
|
|
704
|
+
boolean drawerVisible = currentProgress > DRAWER_CLOSED_EPSILON;
|
|
705
|
+
closeDragCandidate = drawerVisible && lockMode != LOCK_MODE_LOCKED_OPEN;
|
|
706
|
+
openDragCandidate = openGestureEnabled
|
|
707
|
+
&& lockMode != LOCK_MODE_LOCKED_CLOSED
|
|
708
|
+
&& !drawerVisible
|
|
709
|
+
&& isInsideOpenEdge(activeDrawerChild, downX);
|
|
710
|
+
tapOutsideDrawerCandidate = drawerVisible && isPointOutsideOpenDrawer(activeDrawerChild, downX);
|
|
350
711
|
nativeGestureStarted = false;
|
|
351
712
|
activeNativeGestureView = findNativeGestureView(this, downX, downY);
|
|
713
|
+
|
|
352
714
|
recycleVelocityTracker();
|
|
353
715
|
velocityTracker = VelocityTracker.obtain();
|
|
354
716
|
velocityTracker.addMovement(event);
|
|
355
717
|
}
|
|
356
718
|
|
|
719
|
+
private boolean isInsideOpenEdge(@Nullable View drawerChild, float x) {
|
|
720
|
+
if (drawerChild == null || isStartDrawerOnLeft(drawerChild)) {
|
|
721
|
+
return x <= openEdgeWidth;
|
|
722
|
+
}
|
|
723
|
+
return x >= getWidth() - openEdgeWidth;
|
|
724
|
+
}
|
|
725
|
+
|
|
726
|
+
private boolean isPointOutsideOpenDrawer(@Nullable View drawerChild, float x) {
|
|
727
|
+
if (drawerChild == null) {
|
|
728
|
+
return false;
|
|
729
|
+
}
|
|
730
|
+
int drawerWidth = drawerChild.getWidth();
|
|
731
|
+
if (drawerWidth <= 0) {
|
|
732
|
+
return false;
|
|
733
|
+
}
|
|
734
|
+
float visibleEdge = drawerWidth * drawerProgress;
|
|
735
|
+
if (isStartDrawerOnLeft(drawerChild)) {
|
|
736
|
+
return x > visibleEdge;
|
|
737
|
+
}
|
|
738
|
+
return x < getWidth() - visibleEdge;
|
|
739
|
+
}
|
|
740
|
+
|
|
357
741
|
private boolean tryStartDrawerDrag(MotionEvent event) {
|
|
358
|
-
if (
|
|
359
|
-
openDragCandidate = false;
|
|
360
|
-
closeDragCandidate = false;
|
|
742
|
+
if (!openDragCandidate && !closeDragCandidate) {
|
|
361
743
|
return false;
|
|
362
744
|
}
|
|
363
745
|
|
|
364
|
-
float
|
|
746
|
+
float rawDx = event.getX() - downX;
|
|
747
|
+
float directedDx = (activeDrawerChild == null || isStartDrawerOnLeft(activeDrawerChild)) ? rawDx : -rawDx;
|
|
365
748
|
float dy = Math.abs(event.getY() - downY);
|
|
366
|
-
|
|
749
|
+
|
|
750
|
+
if (openDragCandidate && directedDx > openGestureTriggerDistance && directedDx > dy * HORIZONTAL_ACTIVATION_RATIO) {
|
|
367
751
|
return startDrawerDrag(DRAG_OPEN, event);
|
|
368
752
|
}
|
|
369
753
|
|
|
370
|
-
if (closeDragCandidate &&
|
|
754
|
+
if (closeDragCandidate && directedDx < -touchSlop && Math.abs(directedDx) > dy * HORIZONTAL_ACTIVATION_RATIO) {
|
|
371
755
|
return startDrawerDrag(DRAG_CLOSE, event);
|
|
372
756
|
}
|
|
373
757
|
|
|
@@ -387,10 +771,15 @@ public class HybridDrawerLayout extends DrawerLayout {
|
|
|
387
771
|
return false;
|
|
388
772
|
}
|
|
389
773
|
|
|
774
|
+
dragHelper.abort();
|
|
390
775
|
activeDragMode = dragMode;
|
|
391
|
-
|
|
776
|
+
tapOutsideDrawerCandidate = false;
|
|
777
|
+
dragStartProgress = drawerProgress;
|
|
778
|
+
setDrawerState(STATE_DRAGGING);
|
|
392
779
|
notifyNativeGestureStarted(event);
|
|
393
|
-
getParent()
|
|
780
|
+
if (getParent() != null) {
|
|
781
|
+
getParent().requestDisallowInterceptTouchEvent(true);
|
|
782
|
+
}
|
|
394
783
|
performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY);
|
|
395
784
|
return true;
|
|
396
785
|
}
|
|
@@ -409,9 +798,14 @@ public class HybridDrawerLayout extends DrawerLayout {
|
|
|
409
798
|
|
|
410
799
|
if (action == MotionEvent.ACTION_UP || action == MotionEvent.ACTION_CANCEL) {
|
|
411
800
|
applyDrawerDragProgress(event);
|
|
412
|
-
|
|
801
|
+
float velocityX = getXVelocity();
|
|
802
|
+
if (!isStartDrawerOnLeft(activeDrawerChild)) {
|
|
803
|
+
velocityX = -velocityX;
|
|
804
|
+
}
|
|
805
|
+
int dragMode = activeDragMode;
|
|
413
806
|
notifyNativeGestureEnded(event);
|
|
414
807
|
resetTouchTracking();
|
|
808
|
+
settleDrawerDrag(dragMode, action == MotionEvent.ACTION_CANCEL, velocityX);
|
|
415
809
|
return true;
|
|
416
810
|
}
|
|
417
811
|
|
|
@@ -424,25 +818,22 @@ public class HybridDrawerLayout extends DrawerLayout {
|
|
|
424
818
|
return;
|
|
425
819
|
}
|
|
426
820
|
|
|
427
|
-
float
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
private void settleDrawerDrag(boolean cancelled, float velocityX) {
|
|
432
|
-
if (activeDrawerChild == null) {
|
|
433
|
-
return;
|
|
821
|
+
float deltaX = event.getX() - downX;
|
|
822
|
+
if (!isStartDrawerOnLeft(activeDrawerChild)) {
|
|
823
|
+
deltaX = -deltaX;
|
|
434
824
|
}
|
|
825
|
+
float progress = dragStartProgress + deltaX / drawerWidth;
|
|
826
|
+
positionDrawerToProgress(activeDrawerChild, progress);
|
|
827
|
+
}
|
|
435
828
|
|
|
829
|
+
private void settleDrawerDrag(int dragMode, boolean cancelled, float velocityX) {
|
|
436
830
|
boolean shouldOpen;
|
|
437
831
|
if (cancelled) {
|
|
438
|
-
shouldOpen =
|
|
832
|
+
shouldOpen = dragMode == DRAG_CLOSE;
|
|
833
|
+
} else if (dragMode == DRAG_OPEN) {
|
|
834
|
+
shouldOpen = drawerProgress >= OPEN_SETTLE_THRESHOLD || velocityX >= settleVelocity;
|
|
439
835
|
} else {
|
|
440
|
-
|
|
441
|
-
if (activeDragMode == DRAG_OPEN) {
|
|
442
|
-
shouldOpen = progress >= OPEN_SETTLE_THRESHOLD || velocityX >= settleVelocity;
|
|
443
|
-
} else {
|
|
444
|
-
shouldOpen = progress >= CLOSE_SETTLE_THRESHOLD && velocityX >= -settleVelocity;
|
|
445
|
-
}
|
|
836
|
+
shouldOpen = drawerProgress >= CLOSE_SETTLE_THRESHOLD && velocityX >= -settleVelocity;
|
|
446
837
|
}
|
|
447
838
|
|
|
448
839
|
if (shouldOpen) {
|
|
@@ -452,76 +843,105 @@ public class HybridDrawerLayout extends DrawerLayout {
|
|
|
452
843
|
}
|
|
453
844
|
}
|
|
454
845
|
|
|
455
|
-
private void
|
|
456
|
-
|
|
457
|
-
if (
|
|
846
|
+
private void positionDrawerToProgress(@NonNull View drawerChild, float progress) {
|
|
847
|
+
float clamped = clampProgress(progress);
|
|
848
|
+
if (clamped > 0f) {
|
|
458
849
|
drawerChild.setVisibility(VISIBLE);
|
|
459
850
|
}
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
851
|
+
int targetLeft = computeDrawerLeft(drawerChild, clamped);
|
|
852
|
+
int dx = targetLeft - drawerChild.getLeft();
|
|
853
|
+
if (dx != 0) {
|
|
854
|
+
drawerChild.offsetLeftAndRight(dx);
|
|
463
855
|
}
|
|
464
|
-
|
|
465
|
-
if (
|
|
856
|
+
updateDrawerProgressInternal(drawerChild, clamped);
|
|
857
|
+
if (clamped == 0f) {
|
|
466
858
|
drawerChild.setVisibility(INVISIBLE);
|
|
467
859
|
}
|
|
468
860
|
invalidate();
|
|
469
861
|
}
|
|
470
862
|
|
|
471
|
-
private
|
|
472
|
-
|
|
473
|
-
|
|
863
|
+
private void updateDrawerProgressInternal(@NonNull View drawerChild, float progress) {
|
|
864
|
+
float clamped = clampProgress(progress);
|
|
865
|
+
drawerProgress = clamped;
|
|
866
|
+
if (clamped > 0f && drawerChild.getVisibility() != VISIBLE) {
|
|
867
|
+
drawerChild.setVisibility(VISIBLE);
|
|
868
|
+
} else if (clamped == 0f && drawerChild.getVisibility() != INVISIBLE) {
|
|
869
|
+
drawerChild.setVisibility(INVISIBLE);
|
|
474
870
|
}
|
|
871
|
+
dispatchDrawerSlide(drawerChild, clamped);
|
|
872
|
+
invalidate();
|
|
873
|
+
}
|
|
475
874
|
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
875
|
+
private void finalizeDrawerSettle() {
|
|
876
|
+
View drawerChild = findDrawerChild();
|
|
877
|
+
if (drawerChild == null) {
|
|
878
|
+
return;
|
|
879
|
+
}
|
|
880
|
+
if (drawerProgress >= DRAWER_OPEN_EPSILON) {
|
|
881
|
+
drawerProgress = 1f;
|
|
882
|
+
dispatchDrawerSlide(drawerChild, 1f);
|
|
883
|
+
dispatchDrawerOpened(drawerChild);
|
|
884
|
+
} else if (drawerProgress <= DRAWER_CLOSED_EPSILON) {
|
|
885
|
+
drawerProgress = 0f;
|
|
886
|
+
drawerChild.setVisibility(INVISIBLE);
|
|
887
|
+
dispatchDrawerSlide(drawerChild, 0f);
|
|
888
|
+
dispatchDrawerClosed(drawerChild);
|
|
481
889
|
}
|
|
482
890
|
}
|
|
483
891
|
|
|
484
|
-
private void
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
892
|
+
private void setDrawerState(int newState) {
|
|
893
|
+
if (drawerState == newState) {
|
|
894
|
+
return;
|
|
895
|
+
}
|
|
896
|
+
drawerState = newState;
|
|
897
|
+
for (DrawerListener listener : listeners) {
|
|
898
|
+
listener.onDrawerStateChanged(newState);
|
|
899
|
+
}
|
|
491
900
|
}
|
|
492
901
|
|
|
493
|
-
private
|
|
494
|
-
|
|
495
|
-
|
|
902
|
+
private void dispatchDrawerSlide(@NonNull View drawerView, float slideOffset) {
|
|
903
|
+
for (DrawerListener listener : listeners) {
|
|
904
|
+
listener.onDrawerSlide(drawerView, slideOffset);
|
|
496
905
|
}
|
|
906
|
+
}
|
|
497
907
|
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
if (value instanceof Float) {
|
|
502
|
-
return clampProgress((Float) value);
|
|
503
|
-
}
|
|
504
|
-
} catch (IllegalAccessException | InvocationTargetException ignored) {
|
|
505
|
-
}
|
|
908
|
+
private void dispatchDrawerOpened(@NonNull View drawerView) {
|
|
909
|
+
if (drawerOpened) {
|
|
910
|
+
return;
|
|
506
911
|
}
|
|
912
|
+
drawerOpened = true;
|
|
913
|
+
for (DrawerListener listener : listeners) {
|
|
914
|
+
listener.onDrawerOpened(drawerView);
|
|
915
|
+
}
|
|
916
|
+
}
|
|
507
917
|
|
|
508
|
-
|
|
509
|
-
if (
|
|
510
|
-
return
|
|
918
|
+
private void dispatchDrawerClosed(@NonNull View drawerView) {
|
|
919
|
+
if (!drawerOpened) {
|
|
920
|
+
return;
|
|
511
921
|
}
|
|
922
|
+
drawerOpened = false;
|
|
923
|
+
for (DrawerListener listener : listeners) {
|
|
924
|
+
listener.onDrawerClosed(drawerView);
|
|
925
|
+
}
|
|
926
|
+
}
|
|
927
|
+
|
|
928
|
+
private int computeDrawerLeft(@NonNull View drawerChild, float progress) {
|
|
929
|
+
return computeDrawerLeft(drawerChild, progress, getWidth(), drawerChild.getWidth());
|
|
930
|
+
}
|
|
512
931
|
|
|
932
|
+
private int computeDrawerLeft(@NonNull View drawerChild, float progress, int parentWidth, int drawerWidth) {
|
|
513
933
|
if (isStartDrawerOnLeft(drawerChild)) {
|
|
514
|
-
return
|
|
934
|
+
return Math.round((progress - 1f) * drawerWidth);
|
|
515
935
|
}
|
|
516
|
-
return
|
|
936
|
+
return Math.round(parentWidth - progress * drawerWidth);
|
|
517
937
|
}
|
|
518
938
|
|
|
519
939
|
private float clampProgress(float progress) {
|
|
520
|
-
return Math.max(
|
|
940
|
+
return Math.max(0f, Math.min(1f, progress));
|
|
521
941
|
}
|
|
522
942
|
|
|
523
943
|
private boolean isDrawerClosed() {
|
|
524
|
-
return
|
|
944
|
+
return drawerProgress <= DRAWER_CLOSED_EPSILON;
|
|
525
945
|
}
|
|
526
946
|
|
|
527
947
|
private void notifyNativeGestureStarted(MotionEvent event) {
|
|
@@ -548,18 +968,18 @@ public class HybridDrawerLayout extends DrawerLayout {
|
|
|
548
968
|
recycleVelocityTracker();
|
|
549
969
|
closeDragCandidate = false;
|
|
550
970
|
openDragCandidate = false;
|
|
971
|
+
tapOutsideDrawerCandidate = false;
|
|
551
972
|
activeDragMode = DRAG_NONE;
|
|
552
973
|
activeDrawerChild = null;
|
|
553
974
|
activeNativeGestureView = null;
|
|
554
|
-
dragStartProgress =
|
|
975
|
+
dragStartProgress = 0f;
|
|
555
976
|
nativeGestureStarted = false;
|
|
556
977
|
}
|
|
557
978
|
|
|
558
979
|
private float getXVelocity() {
|
|
559
980
|
if (velocityTracker == null) {
|
|
560
|
-
return
|
|
981
|
+
return 0f;
|
|
561
982
|
}
|
|
562
|
-
|
|
563
983
|
velocityTracker.computeCurrentVelocity(1000);
|
|
564
984
|
return velocityTracker.getXVelocity();
|
|
565
985
|
}
|
|
@@ -568,11 +988,11 @@ public class HybridDrawerLayout extends DrawerLayout {
|
|
|
568
988
|
if (velocityTracker == null) {
|
|
569
989
|
return;
|
|
570
990
|
}
|
|
571
|
-
|
|
572
991
|
velocityTracker.recycle();
|
|
573
992
|
velocityTracker = null;
|
|
574
993
|
}
|
|
575
994
|
|
|
995
|
+
@Nullable
|
|
576
996
|
private View findDrawerChild() {
|
|
577
997
|
for (int i = getChildCount() - 1; i >= 0; i--) {
|
|
578
998
|
View child = getChildAt(i);
|
|
@@ -583,9 +1003,9 @@ public class HybridDrawerLayout extends DrawerLayout {
|
|
|
583
1003
|
return null;
|
|
584
1004
|
}
|
|
585
1005
|
|
|
1006
|
+
@Nullable
|
|
586
1007
|
private View findNativeGestureView(View view, float x, float y) {
|
|
587
|
-
if (view instanceof ViewGroup) {
|
|
588
|
-
ViewGroup group = (ViewGroup) view;
|
|
1008
|
+
if (view instanceof ViewGroup group) {
|
|
589
1009
|
for (int i = group.getChildCount() - 1; i >= 0; i--) {
|
|
590
1010
|
View child = group.getChildAt(i);
|
|
591
1011
|
if (child.getVisibility() != VISIBLE || !isPointInsideChild(child, x, y)) {
|
|
@@ -600,7 +1020,6 @@ public class HybridDrawerLayout extends DrawerLayout {
|
|
|
600
1020
|
}
|
|
601
1021
|
}
|
|
602
1022
|
}
|
|
603
|
-
|
|
604
1023
|
return view instanceof RootView ? view : null;
|
|
605
1024
|
}
|
|
606
1025
|
|
|
@@ -611,13 +1030,14 @@ public class HybridDrawerLayout extends DrawerLayout {
|
|
|
611
1030
|
&& y >= top && y < top + child.getHeight();
|
|
612
1031
|
}
|
|
613
1032
|
|
|
1033
|
+
@Nullable
|
|
614
1034
|
private Activity findActivity() {
|
|
615
1035
|
Context context = getContext();
|
|
616
|
-
while (context instanceof ContextWrapper) {
|
|
617
|
-
if (context instanceof Activity) {
|
|
618
|
-
return
|
|
1036
|
+
while (context instanceof ContextWrapper wrapper) {
|
|
1037
|
+
if (context instanceof Activity activity) {
|
|
1038
|
+
return activity;
|
|
619
1039
|
}
|
|
620
|
-
context =
|
|
1040
|
+
context = wrapper.getBaseContext();
|
|
621
1041
|
}
|
|
622
1042
|
return null;
|
|
623
1043
|
}
|