@lynx-js/lynx-ui-swiper 3.130.0 → 3.131.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/CHANGELOG.md CHANGED
@@ -1,5 +1,14 @@
1
1
  # @lynx-js/lynx-ui-swiper
2
2
 
3
+ ## 3.131.0
4
+
5
+ ### Patch Changes
6
+
7
+ - Preserve two recent touch samples when measuring swipe velocity so Android devices with sparse touch move events still page correctly. ([#122](https://github.com/lynx-family/lynx-ui/pull/122))
8
+
9
+ - Updated dependencies [[`bc167c5`](https://github.com/lynx-family/lynx-ui/commit/bc167c5d03cdb344156e897c4d2d69f95bf7d29b)]:
10
+ - @lynx-js/lynx-ui-common@3.131.0
11
+
3
12
  ## 3.130.0
4
13
 
5
14
  ### Patch Changes
@@ -1 +1 @@
1
- {"version":3,"file":"useVelocity.d.ts","sourceRoot":"","sources":["../../src/hooks/useVelocity.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAA;AAEhD,OAAO,EAAE,cAAc,EAAE,MAAM,UAAU,CAAA;AACzC,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,UAAU,CAAA;AAE3C,wBAAgB,WAAW,CAAC,EAAE,GAAG,EAAE,EAAE;IAAE,GAAG,EAAE,WAAW,CAAC,OAAO,CAAC,CAAC,KAAK,CAAC,CAAA;CAAE;;;;;;+BA4DrC,UAAU,CAAC,UAAU;EAWxD"}
1
+ {"version":3,"file":"useVelocity.d.ts","sourceRoot":"","sources":["../../src/hooks/useVelocity.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAA;AAEhD,OAAO,EAAE,cAAc,EAAE,MAAM,UAAU,CAAA;AACzC,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,UAAU,CAAA;AAE3C,wBAAgB,WAAW,CAAC,EAAE,GAAG,EAAE,EAAE;IAAE,GAAG,EAAE,WAAW,CAAC,OAAO,CAAC,CAAC,KAAK,CAAC,CAAA;CAAE;;;;;;+BA8DrC,UAAU,CAAC,UAAU;EAWxD"}
@@ -8,12 +8,12 @@ function useVelocity({ RTL }) {
8
8
  timeQueueRef.current = [];
9
9
  positionQueueRef.current = [];
10
10
  };
11
- const pruneQueue = (ms)=>{
11
+ const pruneQueue = (ms, minLength = 0)=>{
12
12
  'main thread';
13
13
  const timeQueue = timeQueueRef.current;
14
14
  const positionQueue = positionQueueRef.current;
15
15
  const nowTs = Date.now();
16
- while(timeQueue.length > 0 && timeQueue[0] < nowTs - ms){
16
+ while(timeQueue.length > minLength && timeQueue[0] < nowTs - ms){
17
17
  timeQueue.shift();
18
18
  positionQueue.shift();
19
19
  }
@@ -41,7 +41,7 @@ function useVelocity({ RTL }) {
41
41
  const positionQueue = positionQueueRef.current;
42
42
  positionQueue.push(position);
43
43
  timeQueue.push(Date.now());
44
- pruneQueue(50);
44
+ pruneQueue(50, 2);
45
45
  };
46
46
  function velocityTouchStart() {
47
47
  'main thread';
@@ -1 +1 @@
1
- {"version":3,"file":"hooks/useVelocity.jsx","sources":["webpack://@lynx-js/lynx-ui-swiper/./src/hooks/useVelocity.ts"],"sourcesContent":["// Copyright 2026 The Lynx Authors. All rights reserved.\n// Licensed under the Apache License Version 2.0 that can be found in the\n// LICENSE file in the root directory of this source tree.\n\nimport { useMainThreadRef } from '@lynx-js/react'\n\nimport type { MainThread } from '@lynx-js/types'\n\nimport { SwipeDirection } from '../types'\nimport type { SwiperProps } from '../types'\n\nexport function useVelocity({ RTL }: { RTL: SwiperProps<unknown>['RTL'] }) {\n const positionQueueRef = useMainThreadRef<number[]>([])\n const timeQueueRef = useMainThreadRef<number[]>([])\n\n const reset = () => {\n 'main thread'\n timeQueueRef.current = []\n positionQueueRef.current = []\n }\n\n const pruneQueue = (ms: number) => {\n 'main thread'\n const timeQueue = timeQueueRef.current\n const positionQueue = positionQueueRef.current\n\n const nowTs = Date.now()\n // pull old values off of the queue\n while (timeQueue.length > 0 && timeQueue[0] < nowTs - ms) {\n timeQueue.shift()\n positionQueue.shift()\n }\n }\n\n const getVelocity = () => {\n 'main thread'\n pruneQueue(500)\n const timeQueue = timeQueueRef.current\n const positionQueue = positionQueueRef.current\n const { length } = timeQueue\n if (length < 2) {\n return {\n velocity: 0,\n direction: SwipeDirection.REVERT,\n }\n }\n const distance = RTL\n ? positionQueue[0] - positionQueue[length - 1]\n : positionQueue[length - 1] - positionQueue[0]\n const time = (timeQueue[length - 1] - timeQueue[0]) / 1000\n return {\n velocity: distance / time,\n direction: distance > 0 ? SwipeDirection.REVERT : SwipeDirection.NORMAL,\n }\n }\n\n const updatePosition = (position: number) => {\n 'main thread'\n const timeQueue = timeQueueRef.current\n const positionQueue = positionQueueRef.current\n\n positionQueue.push(position)\n timeQueue.push(Date.now())\n pruneQueue(50)\n }\n\n function velocityTouchStart() {\n 'main thread'\n reset()\n }\n\n function velocityTouchMove(event: MainThread.TouchEvent) {\n 'main thread'\n\n updatePosition(event.detail.x)\n }\n\n return {\n getVelocity,\n velocityTouchStart,\n velocityTouchMove,\n }\n}\n"],"names":["useVelocity","RTL","positionQueueRef","useMainThreadRef","timeQueueRef","reset","pruneQueue","ms","timeQueue","positionQueue","nowTs","Date","getVelocity","length","SwipeDirection","distance","time","updatePosition","position","velocityTouchStart","velocityTouchMove","event"],"mappings":";;AAWO,SAASA,YAAY,EAAEC,GAAG,EAAwC;IACvE,MAAMC,mBAAmBC,iBAA2B,EAAE;IACtD,MAAMC,eAAeD,iBAA2B,EAAE;IAElD,MAAME,QAAQ;QACZ;QACAD,aAAa,OAAO,GAAG,EAAE;QACzBF,iBAAiB,OAAO,GAAG,EAAE;IAC/B;IAEA,MAAMI,aAAa,CAACC;QAClB;QACA,MAAMC,YAAYJ,aAAa,OAAO;QACtC,MAAMK,gBAAgBP,iBAAiB,OAAO;QAE9C,MAAMQ,QAAQC,KAAK,GAAG;QAEtB,MAAOH,UAAU,MAAM,GAAG,KAAKA,SAAS,CAAC,EAAE,GAAGE,QAAQH,GAAI;YACxDC,UAAU,KAAK;YACfC,cAAc,KAAK;QACrB;IACF;IAEA,MAAMG,cAAc;QAClB;QACAN,WAAW;QACX,MAAME,YAAYJ,aAAa,OAAO;QACtC,MAAMK,gBAAgBP,iBAAiB,OAAO;QAC9C,MAAM,EAAEW,MAAM,EAAE,GAAGL;QACnB,IAAIK,SAAS,GACX,OAAO;YACL,UAAU;YACV,WAAWC,eAAe,MAAM;QAClC;QAEF,MAAMC,WAAWd,MACbQ,aAAa,CAAC,EAAE,GAAGA,aAAa,CAACI,SAAS,EAAE,GAC5CJ,aAAa,CAACI,SAAS,EAAE,GAAGJ,aAAa,CAAC,EAAE;QAChD,MAAMO,OAAQR,AAAAA,CAAAA,SAAS,CAACK,SAAS,EAAE,GAAGL,SAAS,CAAC,EAAC,IAAK;QACtD,OAAO;YACL,UAAUO,WAAWC;YACrB,WAAWD,WAAW,IAAID,eAAe,MAAM,GAAGA,eAAe,MAAM;QACzE;IACF;IAEA,MAAMG,iBAAiB,CAACC;QACtB;QACA,MAAMV,YAAYJ,aAAa,OAAO;QACtC,MAAMK,gBAAgBP,iBAAiB,OAAO;QAE9CO,cAAc,IAAI,CAACS;QACnBV,UAAU,IAAI,CAACG,KAAK,GAAG;QACvBL,WAAW;IACb;IAEA,SAASa;QACP;QACAd;IACF;IAEA,SAASe,kBAAkBC,KAA4B;QACrD;QAEAJ,eAAeI,MAAM,MAAM,CAAC,CAAC;IAC/B;IAEA,OAAO;QACLT;QACAO;QACAC;IACF;AACF"}
1
+ {"version":3,"file":"hooks/useVelocity.jsx","sources":["webpack://@lynx-js/lynx-ui-swiper/./src/hooks/useVelocity.ts"],"sourcesContent":["// Copyright 2026 The Lynx Authors. All rights reserved.\n// Licensed under the Apache License Version 2.0 that can be found in the\n// LICENSE file in the root directory of this source tree.\n\nimport { useMainThreadRef } from '@lynx-js/react'\n\nimport type { MainThread } from '@lynx-js/types'\n\nimport { SwipeDirection } from '../types'\nimport type { SwiperProps } from '../types'\n\nexport function useVelocity({ RTL }: { RTL: SwiperProps<unknown>['RTL'] }) {\n const positionQueueRef = useMainThreadRef<number[]>([])\n const timeQueueRef = useMainThreadRef<number[]>([])\n\n const reset = () => {\n 'main thread'\n timeQueueRef.current = []\n positionQueueRef.current = []\n }\n\n const pruneQueue = (ms: number, minLength = 0) => {\n 'main thread'\n const timeQueue = timeQueueRef.current\n const positionQueue = positionQueueRef.current\n\n const nowTs = Date.now()\n // pull old values off of the queue\n while (timeQueue.length > minLength && timeQueue[0] < nowTs - ms) {\n timeQueue.shift()\n positionQueue.shift()\n }\n }\n\n const getVelocity = () => {\n 'main thread'\n pruneQueue(500)\n const timeQueue = timeQueueRef.current\n const positionQueue = positionQueueRef.current\n const { length } = timeQueue\n if (length < 2) {\n return {\n velocity: 0,\n direction: SwipeDirection.REVERT,\n }\n }\n const distance = RTL\n ? positionQueue[0] - positionQueue[length - 1]\n : positionQueue[length - 1] - positionQueue[0]\n const time = (timeQueue[length - 1] - timeQueue[0]) / 1000\n return {\n velocity: distance / time,\n direction: distance > 0 ? SwipeDirection.REVERT : SwipeDirection.NORMAL,\n }\n }\n\n const updatePosition = (position: number) => {\n 'main thread'\n const timeQueue = timeQueueRef.current\n const positionQueue = positionQueueRef.current\n\n positionQueue.push(position)\n timeQueue.push(Date.now())\n // Keep one older sample around so sparse touchmove delivery can still\n // produce a release velocity from the latest two points.\n pruneQueue(50, 2)\n }\n\n function velocityTouchStart() {\n 'main thread'\n reset()\n }\n\n function velocityTouchMove(event: MainThread.TouchEvent) {\n 'main thread'\n\n updatePosition(event.detail.x)\n }\n\n return {\n getVelocity,\n velocityTouchStart,\n velocityTouchMove,\n }\n}\n"],"names":["useVelocity","RTL","positionQueueRef","useMainThreadRef","timeQueueRef","reset","pruneQueue","ms","minLength","timeQueue","positionQueue","nowTs","Date","getVelocity","length","SwipeDirection","distance","time","updatePosition","position","velocityTouchStart","velocityTouchMove","event"],"mappings":";;AAWO,SAAS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QACAf;IACF;IAEA,SAASgB,kBAAkBC,KAA4B;QACrD;QAEAJ,eAAeI,MAAM,MAAM,CAAC,CAAC;IAC/B;IAEA,OAAO;QACLT;QACAO;QACAC;IACF;AACF"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lynx-js/lynx-ui-swiper",
3
- "version": "3.130.0",
3
+ "version": "3.131.0",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "git+https://github.com/lynx-family/lynx-ui.git",
@@ -26,7 +26,7 @@
26
26
  ],
27
27
  "dependencies": {
28
28
  "@lynx-js/react-use": "0.0.7",
29
- "@lynx-js/lynx-ui-common": "3.130.0"
29
+ "@lynx-js/lynx-ui-common": "3.131.0"
30
30
  },
31
31
  "devDependencies": {
32
32
  "@lynx-js/react": "0.113.0",
@@ -19,14 +19,14 @@ export function useVelocity({ RTL }: { RTL: SwiperProps<unknown>['RTL'] }) {
19
19
  positionQueueRef.current = []
20
20
  }
21
21
 
22
- const pruneQueue = (ms: number) => {
22
+ const pruneQueue = (ms: number, minLength = 0) => {
23
23
  'main thread'
24
24
  const timeQueue = timeQueueRef.current
25
25
  const positionQueue = positionQueueRef.current
26
26
 
27
27
  const nowTs = Date.now()
28
28
  // pull old values off of the queue
29
- while (timeQueue.length > 0 && timeQueue[0] < nowTs - ms) {
29
+ while (timeQueue.length > minLength && timeQueue[0] < nowTs - ms) {
30
30
  timeQueue.shift()
31
31
  positionQueue.shift()
32
32
  }
@@ -61,7 +61,9 @@ export function useVelocity({ RTL }: { RTL: SwiperProps<unknown>['RTL'] }) {
61
61
 
62
62
  positionQueue.push(position)
63
63
  timeQueue.push(Date.now())
64
- pruneQueue(50)
64
+ // Keep one older sample around so sparse touchmove delivery can still
65
+ // produce a release velocity from the latest two points.
66
+ pruneQueue(50, 2)
65
67
  }
66
68
 
67
69
  function velocityTouchStart() {