@momo-kits/foundation 0.164.1-beta.2 → 0.164.1-beta.3

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.
@@ -374,9 +374,16 @@ const getSwipeGestureValue = (
374
374
  * one light tick once the swipe back has travelled far enough to read as
375
375
  * recognised. iOS only, mirroring `gestureEnabled` in getStackOptions.
376
376
  *
377
- * the listener is scoped to the `swiping === 1` window on purpose: the same
378
- * animated value also drives the programmatic push and pop animations, so an
379
- * unscoped listener would buzz on every navigation.
377
+ * both listeners are installed on mount and never lazily inside the gesture:
378
+ * on the New Architecture `addListener` queues `startListeningToAnimatedNodeValue`
379
+ * via `queueOperationBlock`, and that queue is only drained by a React mount
380
+ * commit — which never happens during a native driven pan. subscribing when the
381
+ * swipe starts installs an observer that the release flush tears down again
382
+ * before a single frame is delivered, so it must stay on mount.
383
+ *
384
+ * `gesture` also drives the programmatic push and pop animations, so it is the
385
+ * JS `isSwiping` flag, not the subscription lifetime, that keeps the tick
386
+ * exclusive to a real finger drag.
380
387
  */
381
388
  const useSwipeBackHaptic = () => {
382
389
  const { navigator } = useContext<any>(ApplicationContext);
@@ -393,47 +400,45 @@ const useSwipeBackHaptic = () => {
393
400
  return;
394
401
  }
395
402
 
403
+ /**
404
+ * `animation` identity is not stable, so this effect can re-run mid swipe.
405
+ * seed from the live value instead of waiting for a 0 -> 1 transition that
406
+ * has already been missed
407
+ */
408
+ let isSwiping = readAnimatedValue(swiping, 0) === 1;
396
409
  let hasFired = false;
397
- let gestureListener: string | undefined;
398
410
 
399
- const detachGesture = () => {
400
- if (gestureListener !== undefined) {
401
- gesture.removeListener(gestureListener);
402
- gestureListener = undefined;
403
- }
404
- hasFired = false;
405
- };
411
+ /**
412
+ * sign, not magnitude: a leftward overdrag reports a negative
413
+ * translation and must not count as progress toward dismissal
414
+ */
415
+ const direction = readAnimatedValue(inverted, 1);
406
416
 
407
417
  const swipingListener = swiping.addListener(({ value }) => {
408
- if (value !== 1) {
409
- detachGesture();
418
+ isSwiping = value === 1;
419
+ if (!isSwiping) {
420
+ hasFired = false;
421
+ }
422
+ });
423
+
424
+ const gestureListener = gesture.addListener(({ value: translation }) => {
425
+ if (!isSwiping) {
410
426
  return;
411
427
  }
412
428
 
413
- if (gestureListener !== undefined) {
429
+ if (translation * direction < SWIPE_BACK_HAPTIC_THRESHOLD) {
430
+ hasFired = false;
414
431
  return;
415
432
  }
416
433
 
417
- /**
418
- * sign, not magnitude: a leftward overdrag reports a negative
419
- * translation and must not count as progress toward dismissal
420
- */
421
- const direction = readAnimatedValue(inverted, 1);
422
- gestureListener = gesture.addListener(({ value: translation }) => {
423
- if (translation * direction < SWIPE_BACK_HAPTIC_THRESHOLD) {
424
- hasFired = false;
425
- return;
426
- }
427
-
428
- if (!hasFired) {
429
- hasFired = true;
430
- navigator?.maxApi?.triggerEventVibration?.('light');
431
- }
432
- });
434
+ if (!hasFired) {
435
+ hasFired = true;
436
+ navigator?.maxApi?.triggerEventVibration?.('light');
437
+ }
433
438
  });
434
439
 
435
440
  return () => {
436
- detachGesture();
441
+ gesture.removeListener(gestureListener);
437
442
  swiping.removeListener(swipingListener);
438
443
  };
439
444
  }, [animation, navigator]);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@momo-kits/foundation",
3
- "version": "0.164.1-beta.2",
3
+ "version": "0.164.1-beta.3",
4
4
  "description": "React Native Component Kits",
5
5
  "main": "index.ts",
6
6
  "scripts": {},