react-native-snap-sheet 1.0.1 → 1.0.2

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.
Files changed (2) hide show
  1. package/package.json +2 -2
  2. package/src/snapsheet.js +8 -6
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-snap-sheet",
3
- "version": "1.0.1",
3
+ "version": "1.0.2",
4
4
  "description": "",
5
5
  "homepage": "https://github.com/deflexable/react-native-snap-sheet#readme",
6
6
  "bugs": {
@@ -19,7 +19,7 @@
19
19
  "test": "echo \"Error: no test specified\" && exit 1"
20
20
  },
21
21
  "dependencies": {
22
- "react-native-dodge-keyboard": "^1.0.1",
22
+ "react-native-dodge-keyboard": "^1.0.2",
23
23
  "react-native-push-back": "^1.0.0"
24
24
  }
25
25
  }
package/src/snapsheet.js CHANGED
@@ -162,10 +162,16 @@ const SnapSheet = forwardRef(function SnapSheet({
162
162
  onMoveShouldSetPanResponderCapture: (_, gesture) => {
163
163
  const { scrollY } = scrollRefObj.current[instantPrefferAnchor.current] || {};
164
164
 
165
+ const isMovingY = (minChange = 3) =>
166
+ gesture.dy > minChange &&
167
+ (gesture.dy / (gesture.dy + gesture.dx)) >= .75;
168
+
165
169
  const shouldCapture = !disabled && (
166
170
  !instantScrollEnabled.current ||
167
- (scrollY <= 0 && gesture.dy > 1) // If sheet is expanded & ScrollView is at top → capture downward drags
171
+ (scrollY <= 0 && isMovingY(5)) ||
172
+ (instantPrefferAnchor.current === undefined && isMovingY(10))
168
173
  );
174
+ if (shouldCapture) setScrollEnabled(false);
169
175
  // console.log('onMoveShouldSetPanResponderCapture shouldCapture:', shouldCapture, ' stats:', { gesture, scrollOffset: scrollY, instantScrollEnabled: instantScrollEnabled.current }, ' gesture.dy > 0:', gesture.dy > 1);
170
176
  return shouldCapture;
171
177
  },
@@ -234,11 +240,7 @@ const SnapSheet = forwardRef(function SnapSheet({
234
240
  const updatePrefferAnchor = () => {
235
241
  const rankedAnchors = Object.entries(scrollRefObj.current).sort((a, b) => compareReactPaths(a[1].location, b[1].location));
236
242
  const directAnchor = rankedAnchors.find(v => v[1].anchorId === currentAnchorId);
237
- if (directAnchor) return setPrefferedAnchor(directAnchor[0]);
238
-
239
- const normalAnchor = rankedAnchors.find(v => !!v[1].anchorId);
240
- if (normalAnchor) return setPrefferedAnchor(normalAnchor[0]);
241
- setPrefferedAnchor(rankedAnchors[0]?.[0]);
243
+ setPrefferedAnchor(directAnchor?.[0]);
242
244
  }
243
245
 
244
246
  const onAnchorScroll = (e, instanceId) => {