@momo-kits/foundation 0.164.1-beta.4 → 0.164.1-beta.5

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.
@@ -335,11 +335,20 @@ const useNativeCanGoBack = () => {
335
335
  };
336
336
 
337
337
  /**
338
- * finger travel that reads as "swipe back recognised". flat px on purpose:
339
- * scaling it by screen width would move the tick to a different physical
340
- * thumb distance on every device
338
+ * fraction of screen width at which releasing commits the pop. deliberately
339
+ * pinned to react-navigation's own rule: Card.tsx (GestureState.END,
340
+ * @react-navigation/stack 7.4.2) closes the card when
341
+ * `(translation + velocity * gestureVelocityImpact) * inverted > distance / 2`
342
+ * with `distance = layout.width` for a horizontal gesture, and exposes no
343
+ * option to override it. so the tick means "release now and you go back"
344
+ * instead of marking a distance of its own — keep the two in sync.
345
+ *
346
+ * mid drag only translation is known, velocity exists solely at release, so a
347
+ * short fast flick can commit without ever crossing this and pops with no
348
+ * tick. that asymmetry is intended: modelling velocity per frame would tick
349
+ * on swipes that then do not commit, which is the worse error
341
350
  */
342
- const SWIPE_BACK_HAPTIC_THRESHOLD = 100;
351
+ const SWIPE_BACK_HAPTIC_COMMIT_RATIO = 0.5;
343
352
 
344
353
  const readAnimatedValue = (node: unknown, fallback: number): number => {
345
354
  const getValue = (node as { __getValue?: () => unknown } | undefined)
@@ -371,8 +380,8 @@ const getSwipeGestureValue = (
371
380
  };
372
381
 
373
382
  /**
374
- * one light tick once the swipe back has travelled far enough to read as
375
- * recognised. iOS only, mirroring `gestureEnabled` in getStackOptions.
383
+ * one light tick once the swipe back passes the point where releasing commits
384
+ * the pop. iOS only, mirroring `gestureEnabled` in getStackOptions.
376
385
  *
377
386
  * both listeners are installed on mount and never lazily inside the gesture:
378
387
  * on the New Architecture `addListener` queues `startListeningToAnimatedNodeValue`
@@ -401,7 +410,7 @@ const useSwipeBackHaptic = () => {
401
410
  return;
402
411
  }
403
412
 
404
- const { swiping, inverted, current } = animation;
413
+ const { swiping, inverted, current, layouts } = animation;
405
414
  const gesture = getSwipeGestureValue(current?.progress);
406
415
  if (!gesture || typeof swiping?.addListener !== 'function') {
407
416
  return;
@@ -420,6 +429,14 @@ const useSwipeBackHaptic = () => {
420
429
  */
421
430
  const direction = readAnimatedValue(inverted, 1);
422
431
 
432
+ /**
433
+ * plain JS numbers, not animated nodes (`StackCardInterpolationProps`).
434
+ * screen layout can still be unmeasured on an early render, and a zero
435
+ * width would put the threshold at 0 and tick the moment the finger moves
436
+ */
437
+ const commitThreshold =
438
+ (layouts?.screen?.width ?? 0) * SWIPE_BACK_HAPTIC_COMMIT_RATIO;
439
+
423
440
  const swipingListener = swiping.addListener(({ value }) => {
424
441
  isSwiping = value === 1;
425
442
  if (!isSwiping) {
@@ -428,11 +445,11 @@ const useSwipeBackHaptic = () => {
428
445
  });
429
446
 
430
447
  const gestureListener = gesture.addListener(({ value: translation }) => {
431
- if (!isSwiping) {
448
+ if (!isSwiping || commitThreshold <= 0) {
432
449
  return;
433
450
  }
434
451
 
435
- if (translation * direction < SWIPE_BACK_HAPTIC_THRESHOLD) {
452
+ if (translation * direction < commitThreshold) {
436
453
  hasFired.current = false;
437
454
  return;
438
455
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@momo-kits/foundation",
3
- "version": "0.164.1-beta.4",
3
+ "version": "0.164.1-beta.5",
4
4
  "description": "React Native Component Kits",
5
5
  "main": "index.ts",
6
6
  "scripts": {},