@lynx-js/lynx-ui-swiper 3.130.0 → 3.132.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,29 @@
1
1
  # @lynx-js/lynx-ui-swiper
2
2
 
3
+ ## 3.132.0
4
+
5
+ ### Minor Changes
6
+
7
+ - Allow SwiperItem to receive item metadata from Swiper context. In normal usage, users can now write `<SwiperItem>` directly without passing `index`, `realIndex`, or `key={realIndex}`. ([#152](https://github.com/lynx-family/lynx-ui/pull/152))
8
+
9
+ ```diff
10
+ {({ index, realIndex }) => (
11
+ - <SwiperItem index={index} realIndex={realIndex} key={realIndex}>
12
+ + <SwiperItem>
13
+ {content}
14
+ </SwiperItem>
15
+ )}
16
+ ```
17
+
18
+ ## 3.131.0
19
+
20
+ ### Patch Changes
21
+
22
+ - 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))
23
+
24
+ - Updated dependencies [[`bc167c5`](https://github.com/lynx-family/lynx-ui/commit/bc167c5d03cdb344156e897c4d2d69f95bf7d29b)]:
25
+ - @lynx-js/lynx-ui-common@3.131.0
26
+
3
27
  ## 3.130.0
4
28
 
5
29
  ### Patch Changes
package/README.md CHANGED
@@ -31,8 +31,8 @@ The `Swiper` component is composed of the following sub-components:
31
31
 
32
32
  ```tsx
33
33
  <Swiper>
34
- {({ index, realIndex }) => (
35
- <SwiperItem index={index} realIndex={realIndex} key={realIndex}>
34
+ {({ index }) => (
35
+ <SwiperItem>
36
36
  {/* Your item content */}
37
37
  </SwiperItem>
38
38
  )}
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/Swiper/index.tsx"],"names":[],"mappings":"AA4BA,OAAO,KAAK,EAEV,WAAW,EACX,SAAS,EAEV,MAAM,UAAU,CAAA;AAIjB,OAAO,cAAc,CAAA;AAErB;;GAEG;AACH,QAAA,MAAM,MAAM,GACT,CAAC;sCAqCwD,OAAO;2EAqUlE,CAAA;AAED,QAAA,MAAM,cAAc,EAIf,OAAO,MAAM,CAAA;AAElB,OAAO,EAAE,cAAc,IAAI,MAAM,EAAE,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/Swiper/index.tsx"],"names":[],"mappings":"AA4BA,OAAO,KAAK,EAEV,WAAW,EACX,SAAS,EAEV,MAAM,UAAU,CAAA;AAIjB,OAAO,cAAc,CAAA;AAErB;;GAEG;AACH,QAAA,MAAM,MAAM,GACT,CAAC;sCAqCwD,OAAO;2EAuVlE,CAAA;AAED,QAAA,MAAM,cAAc,EAIf,OAAO,MAAM,CAAA;AAElB,OAAO,EAAE,cAAc,IAAI,MAAM,EAAE,CAAA"}
@@ -9,7 +9,7 @@ import { useModeConfig } from "../hooks/useModeConfig.jsx";
9
9
  import { useOffset } from "../hooks/useOffset.jsx";
10
10
  import { useOffsetLimit } from "../hooks/useOffsetLimit.jsx";
11
11
  import { useReset } from "../hooks/useReset.jsx";
12
- import { SwiperContext } from "../store/index.jsx";
12
+ import { SwiperContext, SwiperItemContext } from "../store/index.jsx";
13
13
  import { easeOut } from "../utils/index.jsx";
14
14
  import { comparePropsWithObject } from "../utils/compareProps.jsx";
15
15
  import "./styles.css";
@@ -205,6 +205,14 @@ const Swiper = forwardRef(({ data = [], itemWidth, containerWidth = lynx.__globa
205
205
  swipeTo,
206
206
  cancelAnimation: cancelAnimationJS
207
207
  }));
208
+ function renderSwiperItem(props) {
209
+ return <SwiperItemContext.Provider key={props.realIndex} value={{
210
+ index: props.index,
211
+ realIndex: props.realIndex
212
+ }}>
213
+ {children(props)}
214
+ </SwiperItemContext.Provider>;
215
+ }
208
216
  const { bounceStartView, bounceEndView } = useBounceView({
209
217
  startBounceItem,
210
218
  endBounceItem,
@@ -227,13 +235,13 @@ const Swiper = forwardRef(({ data = [], itemWidth, containerWidth = lynx.__globa
227
235
  {loop ? <>
228
236
  {Array.from({
229
237
  length: loopDuplicateCount
230
- }, (_, i)=>loopDuplicateCount - i - 1).map((i)=>children({
238
+ }, (_, i)=>loopDuplicateCount - i - 1).map((i)=>renderSwiperItem({
231
239
  index: data.length - i - 1,
232
240
  item: data[data.length - i - 1],
233
241
  realIndex: -i - 1
234
242
  }))}
235
243
  </> : null}
236
- {data.map((item, index)=>children({
244
+ {data.map((item, index)=>renderSwiperItem({
237
245
  index,
238
246
  item,
239
247
  realIndex: index
@@ -241,7 +249,7 @@ const Swiper = forwardRef(({ data = [], itemWidth, containerWidth = lynx.__globa
241
249
  {loop ? <>
242
250
  {Array.from({
243
251
  length: loopDuplicateCount
244
- }, (_, i)=>i).map((i)=>children({
252
+ }, (_, i)=>i).map((i)=>renderSwiperItem({
245
253
  index: i,
246
254
  item: data[i],
247
255
  realIndex: data.length + i
@@ -1 +1 @@
1
- {"version":3,"file":"Swiper/index.jsx","sources":["webpack://@lynx-js/lynx-ui-swiper/./src/Swiper/index.tsx"],"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 {\n forwardRef,\n memo,\n useImperativeHandle,\n useMainThreadRef,\n useMemo,\n} from '@lynx-js/react'\nimport type { ForwardedRef } from '@lynx-js/react'\n\nimport { useTouchEmulation } from '@lynx-js/react-use'\nimport type { MainThread } from '@lynx-js/types'\n\nimport { LOOP_COUNT } from '../const'\nimport { useBounceConfig } from '../hooks/useBounceConfig'\nimport { useBounceView } from '../hooks/useBounceView'\nimport { useChange } from '../hooks/useChange'\nimport useFirstScreenStyle, {\n getInnerContainerWidthMT,\n} from '../hooks/useFirstScreenStyle'\nimport { useModeConfig } from '../hooks/useModeConfig'\nimport { useOffset } from '../hooks/useOffset'\nimport { useOffsetLimit } from '../hooks/useOffsetLimit'\nimport { useReset } from '../hooks/useReset'\nimport { SwiperContext } from '../store'\nimport type {\n SwipeDirection,\n SwiperProps,\n SwiperRef,\n UpdateSwiperInnerContainerOptions,\n} from '../types'\nimport { easeOut } from '../utils'\nimport { comparePropsWithObject } from '../utils/compareProps'\n\nimport './styles.css'\n\n/**\n * Swiper Component\n */\nconst Swiper = forwardRef(\n <T,>(\n {\n data = [],\n itemWidth,\n containerWidth = lynx.__globalProps.screenWidth\n ?? SystemInfo.pixelWidth / SystemInfo.pixelRatio,\n loop = false,\n mode,\n autoPlay = false,\n autoPlayInterval = 2000,\n duration = 500,\n itemHeight = 'auto',\n initialIndex = 0,\n onChange,\n onSwipeStart,\n onSwipeStop,\n modeConfig: _modeConfig,\n offsetLimit: _offsetLimit,\n bounceConfig,\n children,\n 'main-thread:easing': easing = easeOut,\n 'main-thread:customAnimation': customAnimation,\n 'main-thread:onOffsetChange': onOffsetChange,\n customAnimationFirstScreen,\n swiperKey,\n resetOnReuse,\n trackStyle = {},\n style = {},\n loopDuplicateCount: rawLoopDuplicateCount = LOOP_COUNT,\n experimentalHorizontalSwipeOnly = false,\n consumeSlideEvent = [\n [-180, -135],\n [-45, 45],\n [135, 180],\n ],\n blockNativeEvent = false,\n RTL = false,\n }: SwiperProps<T> & { experimentalHorizontalSwipeOnly?: boolean },\n ref: ForwardedRef<SwiperRef>,\n ) => {\n const dataCount = data.length\n\n const loopDuplicateCount = Math.min(rawLoopDuplicateCount, dataCount)\n\n const containerRef = useMainThreadRef<MainThread.Element>(null)\n const childrenMapRef = useMainThreadRef<Record<number, MainThread.Element>>(\n {},\n )\n const { modeConfig, spaceBetween } = useModeConfig({\n mode,\n modeConfig: _modeConfig,\n })\n const offsetLimit = useOffsetLimit({\n offsetLimit: _offsetLimit,\n loop,\n itemWidth,\n containerWidth,\n modeConfig,\n dataCount,\n spaceBetween,\n })\n\n const {\n enableBounce,\n startBounceItem,\n endBounceItem,\n startBounceItemWidth,\n endBounceItemWidth,\n onStartBounceItemBounce,\n onEndBounceItemBounce,\n } = useBounceConfig(bounceConfig)\n\n function setChildrenRef(refI: MainThread.Element, key: number) {\n 'main thread'\n childrenMapRef.current[key] = refI\n }\n\n const contextValue = useMemo(\n () => ({\n loop,\n itemWidth,\n itemHeight,\n setChildrenRef,\n modeConfig,\n initialIndex,\n customAnimationFirstScreen,\n spaceBetween,\n RTL,\n }),\n [loop, itemWidth, itemHeight, spaceBetween, RTL],\n )\n\n const { setChangeOffset, setChangeSwipeStartMT, setChangeSwipeStopMT } =\n useChange({\n onChange,\n size: itemWidth,\n spaceBetween,\n containerWidth,\n dataCount,\n modeConfig,\n offsetLimit,\n onSwipeStart,\n onSwipeStop,\n 'main-thread:onOffsetChange': onOffsetChange,\n })\n\n function setOffset(offset: number) {\n 'main thread'\n const container = containerRef.current\n if (container) {\n container.setStyleProperties({\n transform: `translate(${offset}px, 0)`,\n transition: 'none',\n })\n }\n }\n\n function updateSwiperInnerContainerSizeMT(\n updateOptions: UpdateSwiperInnerContainerOptions,\n ) {\n 'main thread'\n const container = containerRef.current\n if (container) {\n const width = getInnerContainerWidthMT(updateOptions)\n // These values should get from function params, instead of closure, to make it is updated\n const {\n loop: _loop,\n loopDuplicateCount: _loopDuplicateCount,\n itemWidth: _itemWidth,\n spaceBetween: _spaceBetween,\n itemHeight: _itemHeight,\n } = updateOptions\n\n if (updateOptions.mode === 'custom') {\n // @ts-expect-error CSS types accepting number\n container.setStyleProperties({\n ...trackStyle,\n height: `${_itemHeight}px`,\n })\n } else {\n const insetInlineStartKey = RTL ? 'inset-inline-start' : 'left'\n // @ts-expect-error CSS types accepting number\n container.setStyleProperties({\n ...trackStyle,\n [insetInlineStartKey]: _loop\n ? `${-_loopDuplicateCount * (_itemWidth + _spaceBetween)}px`\n : '0px',\n width,\n height: `${_itemHeight}px`,\n })\n }\n }\n }\n\n function onChildrenOffsetUpdate(offset: number) {\n 'main thread'\n const startCount = loop ? -loopDuplicateCount : 0\n const endCount = loop ? dataCount + loopDuplicateCount : dataCount\n for (let i = startCount; i < endCount; i++) {\n const child = childrenMapRef.current[i]\n const childOffset = offset + i * (itemWidth + spaceBetween)\n if (!customAnimation || !child) {\n return\n }\n const childStyles =\n customAnimation(childOffset / (itemWidth + spaceBetween), i)\n || {}\n child.setStyleProperties(childStyles as Record<string, string>)\n }\n }\n\n function onOffsetUpdate(offset: number, direction: SwipeDirection) {\n 'main thread'\n if (modeConfig.mode === 'normal') {\n let effectiveOffset = offset\n if (modeConfig.align === 'center') {\n effectiveOffset = offset + (containerWidth - itemWidth) / 2\n } else if (modeConfig.align === 'end') {\n effectiveOffset = offset + containerWidth - itemWidth\n }\n setOffset(RTL ? -effectiveOffset : effectiveOffset)\n onChildrenOffsetUpdate(offset)\n } else {\n onChildrenOffsetUpdate(offset)\n }\n setChangeOffset(offset, direction)\n }\n\n function onSwipeStartMT() {\n 'main thread'\n setChangeSwipeStartMT()\n }\n\n function onSwipeStopMT() {\n 'main thread'\n setChangeSwipeStopMT()\n }\n\n // `containerStyle` is only used at firstScreen\n // After that, we use MTS to update styles imperatively\n const { containerStyle } = useFirstScreenStyle({\n itemWidth,\n containerWidth,\n loop,\n initialIndex,\n dataCount,\n modeConfig,\n itemHeight,\n offsetLimit,\n loopDuplicateCount,\n RTL,\n spaceBetween,\n swiperKey,\n trackStyle,\n })\n\n const {\n handleTouchMove,\n handleTouchStart,\n handleTouchEnd,\n swipeNext,\n swipePrev,\n swipeTo,\n resetOffsetMT,\n cancelAnimationJS,\n startAutoPlayMT,\n } = useOffset(\n {\n autoPlay,\n autoPlayInterval,\n loop,\n size: itemWidth,\n spaceBetween,\n dataCount,\n duration,\n easing,\n offsetLimit,\n initialIndex,\n modeConfig,\n containerWidth,\n enableBounce,\n startBounceItemWidth,\n endBounceItemWidth,\n onStartBounceItemBounce,\n onEndBounceItemBounce,\n experimentalHorizontalSwipeOnly,\n onSwipeStartMT,\n onSwipeStopMT,\n consumeSlideEvent,\n RTL,\n },\n onOffsetUpdate,\n )\n\n const { setContainerRef } = useReset({\n swiperKey,\n itemHeight,\n itemWidth,\n containerWidth,\n loop,\n dataCount,\n modeConfig,\n resetOffsetMT,\n resetOnReuse,\n initialIndex,\n loopDuplicateCount,\n updateSwiperInnerContainerSizeMT,\n startAutoPlayMT,\n spaceBetween,\n })\n\n const touchHandlers = useTouchEmulation({\n onTouchCancelMT: handleTouchEnd,\n onTouchEndMT: handleTouchEnd,\n onTouchMoveMT: handleTouchMove,\n onTouchStartMT: handleTouchStart,\n })\n\n useImperativeHandle(ref, () => ({\n swipeNext,\n swipePrev,\n swipeTo,\n cancelAnimation: cancelAnimationJS,\n }))\n\n const { bounceStartView, bounceEndView } = useBounceView({\n startBounceItem,\n endBounceItem,\n loop,\n mode: modeConfig.mode,\n itemWidth,\n count: dataCount,\n RTL,\n containerWidth,\n })\n\n return (\n <SwiperContext.Provider value={contextValue}>\n <view\n class='swiper-root'\n style={{\n ...style,\n width: `${containerWidth}px`,\n height: `${itemHeight}px`,\n direction: RTL === 'lynx-rtl' ? 'lynx-rtl' : (RTL ? 'rtl' : 'ltr'),\n }}\n {...touchHandlers}\n consume-slide-event={consumeSlideEvent}\n block-native-event={blockNativeEvent}\n >\n <view\n class='swiper-track'\n style={containerStyle}\n ref={setContainerRef}\n main-thread:ref={containerRef}\n implicit-animation='false'\n >\n {bounceStartView}\n {loop\n ? (\n <>\n {Array.from(\n { length: loopDuplicateCount },\n (_, i) => loopDuplicateCount - i - 1,\n ).map((i) =>\n children({\n index: data.length - i - 1,\n item: data[data.length - i - 1],\n realIndex: -i - 1,\n })\n )}\n </>\n )\n : null}\n {data.map((item: T, index: number) =>\n children({\n index,\n item,\n realIndex: index,\n })\n )}\n {loop\n ? (\n <>\n {Array.from({ length: loopDuplicateCount }, (_, i) => i).map((\n i,\n ) =>\n children({\n index: i,\n item: data[i],\n realIndex: data.length + i,\n })\n )}\n </>\n )\n : null}\n {bounceEndView}\n </view>\n </view>\n </SwiperContext.Provider>\n )\n },\n)\n\nconst MemoizedSwiper = memo(\n Swiper,\n (prevProps, nextProps) =>\n comparePropsWithObject(prevProps, nextProps, ['modeConfig', 'bounces']),\n) as typeof Swiper\n\nexport { MemoizedSwiper as Swiper }\n"],"names":["Swiper","forwardRef","data","itemWidth","containerWidth","lynx","SystemInfo","loop","mode","autoPlay","autoPlayInterval","duration","itemHeight","initialIndex","onChange","onSwipeStart","onSwipeStop","_modeConfig","_offsetLimit","bounceConfig","children","easing","easeOut","customAnimation","onOffsetChange","customAnimationFirstScreen","swiperKey","resetOnReuse","trackStyle","style","rawLoopDuplicateCount","LOOP_COUNT","experimentalHorizontalSwipeOnly","consumeSlideEvent","blockNativeEvent","RTL","ref","dataCount","loopDuplicateCount","Math","containerRef","useMainThreadRef","childrenMapRef","modeConfig","spaceBetween","useModeConfig","offsetLimit","useOffsetLimit","enableBounce","startBounceItem","endBounceItem","startBounceItemWidth","endBounceItemWidth","onStartBounceItemBounce","onEndBounceItemBounce","useBounceConfig","setChildrenRef","refI","key","contextValue","useMemo","setChangeOffset","setChangeSwipeStartMT","setChangeSwipeStopMT","useChange","setOffset","offset","container","updateSwiperInnerContainerSizeMT","updateOptions","width","getInnerContainerWidthMT","_loop","_loopDuplicateCount","_itemWidth","_spaceBetween","_itemHeight","insetInlineStartKey","onChildrenOffsetUpdate","startCount","endCount","i","child","childOffset","childStyles","onOffsetUpdate","direction","effectiveOffset","onSwipeStartMT","onSwipeStopMT","containerStyle","useFirstScreenStyle","handleTouchMove","handleTouchStart","handleTouchEnd","swipeNext","swipePrev","swipeTo","resetOffsetMT","cancelAnimationJS","startAutoPlayMT","useOffset","setContainerRef","useReset","touchHandlers","useTouchEmulation","useImperativeHandle","bounceStartView","bounceEndView","useBounceView","SwiperContext","view","Array","_","item","index","MemoizedSwiper","memo","prevProps","nextProps","comparePropsWithObject"],"mappings":";;;;;;;;;;;;;;;AA0CA,MAAMA,SAASC,WACb,CACE,EACEC,OAAO,EAAE,EACTC,SAAS,EACTC,iBAAiBC,KAAK,aAAa,CAAC,WAAW,IAC1CC,WAAW,UAAU,GAAGA,WAAW,UAAU,EAClDC,OAAO,KAAK,EACZC,IAAI,E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,CAACyG,MAAM,IAAI,CAAC;QAAE,QAAQ1E;IAAmB,GAAG,CAAC2E,GAAGhC,IAAMA,GAAG,GAAG,CAAC,CAC3DA,IAEA7D,SAAS;YACP,OAAO6D;YACP,MAAM/E,IAAI,CAAC+E,EAAE;YACb,WAAW/E,KAAK,MAAM,GAAG+E;QAC3B,IACA;gBACJ,MAEA,KAAK;YACT,CAAC2B,cAAc;UACjB,EAAEG,KAAK;QACT,EAAEA,KAAK;MACT,EAAED,cAAc;AAEpB;AAGF,MAAMM,iBAAiBC,KACrBrH,QACA,CAACsH,WAAWC,YACVC,uBAAuBF,WAAWC,WAAW;QAAC;QAAc;KAAU"}
1
+ {"version":3,"file":"Swiper/index.jsx","sources":["webpack://@lynx-js/lynx-ui-swiper/./src/Swiper/index.tsx"],"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 {\n forwardRef,\n memo,\n useImperativeHandle,\n useMainThreadRef,\n useMemo,\n} from '@lynx-js/react'\nimport type { ForwardedRef } from '@lynx-js/react'\n\nimport { useTouchEmulation } from '@lynx-js/react-use'\nimport type { MainThread } from '@lynx-js/types'\n\nimport { LOOP_COUNT } from '../const'\nimport { useBounceConfig } from '../hooks/useBounceConfig'\nimport { useBounceView } from '../hooks/useBounceView'\nimport { useChange } from '../hooks/useChange'\nimport useFirstScreenStyle, {\n getInnerContainerWidthMT,\n} from '../hooks/useFirstScreenStyle'\nimport { useModeConfig } from '../hooks/useModeConfig'\nimport { useOffset } from '../hooks/useOffset'\nimport { useOffsetLimit } from '../hooks/useOffsetLimit'\nimport { useReset } from '../hooks/useReset'\nimport { SwiperContext, SwiperItemContext } from '../store'\nimport type {\n SwipeDirection,\n SwiperProps,\n SwiperRef,\n UpdateSwiperInnerContainerOptions,\n} from '../types'\nimport { easeOut } from '../utils'\nimport { comparePropsWithObject } from '../utils/compareProps'\n\nimport './styles.css'\n\n/**\n * Swiper Component\n */\nconst Swiper = forwardRef(\n <T,>(\n {\n data = [],\n itemWidth,\n containerWidth = lynx.__globalProps.screenWidth\n ?? SystemInfo.pixelWidth / SystemInfo.pixelRatio,\n loop = false,\n mode,\n autoPlay = false,\n autoPlayInterval = 2000,\n duration = 500,\n itemHeight = 'auto',\n initialIndex = 0,\n onChange,\n onSwipeStart,\n onSwipeStop,\n modeConfig: _modeConfig,\n offsetLimit: _offsetLimit,\n bounceConfig,\n children,\n 'main-thread:easing': easing = easeOut,\n 'main-thread:customAnimation': customAnimation,\n 'main-thread:onOffsetChange': onOffsetChange,\n customAnimationFirstScreen,\n swiperKey,\n resetOnReuse,\n trackStyle = {},\n style = {},\n loopDuplicateCount: rawLoopDuplicateCount = LOOP_COUNT,\n experimentalHorizontalSwipeOnly = false,\n consumeSlideEvent = [\n [-180, -135],\n [-45, 45],\n [135, 180],\n ],\n blockNativeEvent = false,\n RTL = false,\n }: SwiperProps<T> & { experimentalHorizontalSwipeOnly?: boolean },\n ref: ForwardedRef<SwiperRef>,\n ) => {\n const dataCount = data.length\n\n const loopDuplicateCount = Math.min(rawLoopDuplicateCount, dataCount)\n\n const containerRef = useMainThreadRef<MainThread.Element>(null)\n const childrenMapRef = useMainThreadRef<Record<number, MainThread.Element>>(\n {},\n )\n const { modeConfig, spaceBetween } = useModeConfig({\n mode,\n modeConfig: _modeConfig,\n })\n const offsetLimit = useOffsetLimit({\n offsetLimit: _offsetLimit,\n loop,\n itemWidth,\n containerWidth,\n modeConfig,\n dataCount,\n spaceBetween,\n })\n\n const {\n enableBounce,\n startBounceItem,\n endBounceItem,\n startBounceItemWidth,\n endBounceItemWidth,\n onStartBounceItemBounce,\n onEndBounceItemBounce,\n } = useBounceConfig(bounceConfig)\n\n function setChildrenRef(refI: MainThread.Element, key: number) {\n 'main thread'\n childrenMapRef.current[key] = refI\n }\n\n const contextValue = useMemo(\n () => ({\n loop,\n itemWidth,\n itemHeight,\n setChildrenRef,\n modeConfig,\n initialIndex,\n customAnimationFirstScreen,\n spaceBetween,\n RTL,\n }),\n [loop, itemWidth, itemHeight, spaceBetween, RTL],\n )\n\n const { setChangeOffset, setChangeSwipeStartMT, setChangeSwipeStopMT } =\n useChange({\n onChange,\n size: itemWidth,\n spaceBetween,\n containerWidth,\n dataCount,\n modeConfig,\n offsetLimit,\n onSwipeStart,\n onSwipeStop,\n 'main-thread:onOffsetChange': onOffsetChange,\n })\n\n function setOffset(offset: number) {\n 'main thread'\n const container = containerRef.current\n if (container) {\n container.setStyleProperties({\n transform: `translate(${offset}px, 0)`,\n transition: 'none',\n })\n }\n }\n\n function updateSwiperInnerContainerSizeMT(\n updateOptions: UpdateSwiperInnerContainerOptions,\n ) {\n 'main thread'\n const container = containerRef.current\n if (container) {\n const width = getInnerContainerWidthMT(updateOptions)\n // These values should get from function params, instead of closure, to make it is updated\n const {\n loop: _loop,\n loopDuplicateCount: _loopDuplicateCount,\n itemWidth: _itemWidth,\n spaceBetween: _spaceBetween,\n itemHeight: _itemHeight,\n } = updateOptions\n\n if (updateOptions.mode === 'custom') {\n // @ts-expect-error CSS types accepting number\n container.setStyleProperties({\n ...trackStyle,\n height: `${_itemHeight}px`,\n })\n } else {\n const insetInlineStartKey = RTL ? 'inset-inline-start' : 'left'\n // @ts-expect-error CSS types accepting number\n container.setStyleProperties({\n ...trackStyle,\n [insetInlineStartKey]: _loop\n ? `${-_loopDuplicateCount * (_itemWidth + _spaceBetween)}px`\n : '0px',\n width,\n height: `${_itemHeight}px`,\n })\n }\n }\n }\n\n function onChildrenOffsetUpdate(offset: number) {\n 'main thread'\n const startCount = loop ? -loopDuplicateCount : 0\n const endCount = loop ? dataCount + loopDuplicateCount : dataCount\n for (let i = startCount; i < endCount; i++) {\n const child = childrenMapRef.current[i]\n const childOffset = offset + i * (itemWidth + spaceBetween)\n if (!customAnimation || !child) {\n return\n }\n const childStyles =\n customAnimation(childOffset / (itemWidth + spaceBetween), i)\n || {}\n child.setStyleProperties(childStyles as Record<string, string>)\n }\n }\n\n function onOffsetUpdate(offset: number, direction: SwipeDirection) {\n 'main thread'\n if (modeConfig.mode === 'normal') {\n let effectiveOffset = offset\n if (modeConfig.align === 'center') {\n effectiveOffset = offset + (containerWidth - itemWidth) / 2\n } else if (modeConfig.align === 'end') {\n effectiveOffset = offset + containerWidth - itemWidth\n }\n setOffset(RTL ? -effectiveOffset : effectiveOffset)\n onChildrenOffsetUpdate(offset)\n } else {\n onChildrenOffsetUpdate(offset)\n }\n setChangeOffset(offset, direction)\n }\n\n function onSwipeStartMT() {\n 'main thread'\n setChangeSwipeStartMT()\n }\n\n function onSwipeStopMT() {\n 'main thread'\n setChangeSwipeStopMT()\n }\n\n // `containerStyle` is only used at firstScreen\n // After that, we use MTS to update styles imperatively\n const { containerStyle } = useFirstScreenStyle({\n itemWidth,\n containerWidth,\n loop,\n initialIndex,\n dataCount,\n modeConfig,\n itemHeight,\n offsetLimit,\n loopDuplicateCount,\n RTL,\n spaceBetween,\n swiperKey,\n trackStyle,\n })\n\n const {\n handleTouchMove,\n handleTouchStart,\n handleTouchEnd,\n swipeNext,\n swipePrev,\n swipeTo,\n resetOffsetMT,\n cancelAnimationJS,\n startAutoPlayMT,\n } = useOffset(\n {\n autoPlay,\n autoPlayInterval,\n loop,\n size: itemWidth,\n spaceBetween,\n dataCount,\n duration,\n easing,\n offsetLimit,\n initialIndex,\n modeConfig,\n containerWidth,\n enableBounce,\n startBounceItemWidth,\n endBounceItemWidth,\n onStartBounceItemBounce,\n onEndBounceItemBounce,\n experimentalHorizontalSwipeOnly,\n onSwipeStartMT,\n onSwipeStopMT,\n consumeSlideEvent,\n RTL,\n },\n onOffsetUpdate,\n )\n\n const { setContainerRef } = useReset({\n swiperKey,\n itemHeight,\n itemWidth,\n containerWidth,\n loop,\n dataCount,\n modeConfig,\n resetOffsetMT,\n resetOnReuse,\n initialIndex,\n loopDuplicateCount,\n updateSwiperInnerContainerSizeMT,\n startAutoPlayMT,\n spaceBetween,\n })\n\n const touchHandlers = useTouchEmulation({\n onTouchCancelMT: handleTouchEnd,\n onTouchEndMT: handleTouchEnd,\n onTouchMoveMT: handleTouchMove,\n onTouchStartMT: handleTouchStart,\n })\n\n useImperativeHandle(ref, () => ({\n swipeNext,\n swipePrev,\n swipeTo,\n cancelAnimation: cancelAnimationJS,\n }))\n\n function renderSwiperItem(props: {\n item: T\n index: number\n realIndex: number\n }) {\n return (\n <SwiperItemContext.Provider\n key={props.realIndex}\n value={{\n index: props.index,\n realIndex: props.realIndex,\n }}\n >\n {children(props)}\n </SwiperItemContext.Provider>\n )\n }\n\n const { bounceStartView, bounceEndView } = useBounceView({\n startBounceItem,\n endBounceItem,\n loop,\n mode: modeConfig.mode,\n itemWidth,\n count: dataCount,\n RTL,\n containerWidth,\n })\n\n return (\n <SwiperContext.Provider value={contextValue}>\n <view\n class='swiper-root'\n style={{\n ...style,\n width: `${containerWidth}px`,\n height: `${itemHeight}px`,\n direction: RTL === 'lynx-rtl' ? 'lynx-rtl' : (RTL ? 'rtl' : 'ltr'),\n }}\n {...touchHandlers}\n consume-slide-event={consumeSlideEvent}\n block-native-event={blockNativeEvent}\n >\n <view\n class='swiper-track'\n style={containerStyle}\n ref={setContainerRef}\n main-thread:ref={containerRef}\n implicit-animation='false'\n >\n {bounceStartView}\n {loop\n ? (\n <>\n {Array.from(\n { length: loopDuplicateCount },\n (_, i) => loopDuplicateCount - i - 1,\n ).map((i) =>\n renderSwiperItem({\n index: data.length - i - 1,\n item: data[data.length - i - 1],\n realIndex: -i - 1,\n })\n )}\n </>\n )\n : null}\n {data.map((item: T, index: number) =>\n renderSwiperItem({\n index,\n item,\n realIndex: index,\n })\n )}\n {loop\n ? (\n <>\n {Array.from({ length: loopDuplicateCount }, (_, i) => i).map((\n i,\n ) =>\n renderSwiperItem({\n index: i,\n item: data[i],\n realIndex: data.length + i,\n })\n )}\n </>\n )\n : null}\n {bounceEndView}\n </view>\n </view>\n </SwiperContext.Provider>\n )\n },\n)\n\nconst MemoizedSwiper = memo(\n Swiper,\n (prevProps, nextProps) =>\n comparePropsWithObject(prevProps, nextProps, ['modeConfig', 'bounces']),\n) as typeof Swiper\n\nexport { MemoizedSwiper as Swiper }\n"],"names":["Swiper","forwardRef","data","itemWidth","containerWidth","lynx","SystemInfo","loop","mode","autoPlay","autoPlayInterval","duration","itemHeight","initialIndex","onChange","onSwipeStart","onSwipeStop","_modeConfig","_offsetLimit","bounceConfig","children","easing","easeOut","customAnimation","onOffsetChange","customAnimationFirstScreen","swiperKey","resetOnReuse","trackStyle","style","rawLoopDuplicateCount","LOOP_COUNT","experimentalHorizontalSwipeOnly","consumeSlideEvent","blockNativeEvent","RTL","ref","dataCount","loopDuplicateCount","Math","containerRef","useMainThreadRef","childrenMapRef","modeConfig","spaceBetween","useModeConfig","offsetLimit","useOffsetLimit","enableBounce","startBounceItem","endBounceItem","startBounceItemWidth","endBounceItemWidth","onStartBounceItemBounce","onEndBounceItemBounce","useBounceConfig","setChildrenRef","refI","key","contextValue","useMemo","setChangeOffset","setChangeSwipeStartMT","setChangeSwipeStopMT","useChange","setOffset","offset","container","updateSwiperInnerContainerSizeMT","updateOptions","width","getInnerContainerWidthMT","_loop","_loopDuplicateCount","_itemWidth","_spaceBetween","_itemHeight","insetInlineStartKey","onChildrenOffsetUpdate","startCount","endCount","i","child","childOffset","childStyles","onOffsetUpdate","direction","effectiveOffset","onSwipeStartMT","onSwipeStopMT","containerStyle","useFirstScreenStyle","handleTouchMove","handleTouchStart","handleTouchEnd","swipeNext","swipePrev","swipeTo","resetOffsetMT","cancelAnimationJS","startAutoPlayMT","useOffset","setContainerRef","useReset","touchHandlers","useTouchEmulation","useImperativeHandle","renderSwiperItem","props","SwiperItemContext","bounceStartView","bounceEndView","useBounceView","SwiperContext","view","Array","_","item","index","MemoizedSwiper","memo","prevProps","nextProps","comparePropsWithObject"],"mappings":";;;;;;;;;;;;;;;AA0CA,MAAMA,SAASC,WACb,CACE,EACEC,OAAO,EAAE,EACTC,SAAS,EACTC,iBAAiBC,KAAK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CAACA,IACL0B,iBAAiB;YACf,OAAOzG,KAAK,MAAM,GAAG+E,IAAI;YACzB,MAAM/E,IAAI,CAACA,KAAK,MAAM,GAAG+E,IAAI,EAAE;YAC/B,WAAW,CAACA,IAAI;QAClB,IACA;gBACJ,MAEA,KAAK;YACT,CAAC/E,KAAK,GAAG,CAAC,CAACmH,MAASC,QAClBX,iBAAiB;YACfW;YACAD;YACA,WAAWC;QACb,IACA;YACF,CAAC/G,SAEK;kBACA,CAAC4G,MAAM,IAAI,CAAC;QAAE,QAAQ7E;IAAmB,GAAG,CAAC8E,GAAGnC,IAAMA,GAAG,GAAG,CAAC,CAC3DA,IAEA0B,iBAAiB;YACf,OAAO1B;YACP,MAAM/E,IAAI,CAAC+E,EAAE;YACb,WAAW/E,KAAK,MAAM,GAAG+E;QAC3B,IACA;gBACJ,MAEA,KAAK;YACT,CAAC8B,cAAc;UACjB,EAAEG,KAAK;QACT,EAAEA,KAAK;MACT,EAAED,cAAc;AAEpB;AAGF,MAAMM,iBAAiBC,KACrBxH,QACA,CAACyH,WAAWC,YACVC,uBAAuBF,WAAWC,WAAW;QAAC;QAAc;KAAU"}
@@ -7,7 +7,7 @@ export interface SwiperItemProps {
7
7
  * @iOS
8
8
  * @Harmony
9
9
  */
10
- index: number;
10
+ index?: number;
11
11
  /**
12
12
  * Children of SwiperItem
13
13
  * @Android
@@ -23,8 +23,9 @@ export interface SwiperItemProps {
23
23
  */
24
24
  style?: CSSProperties;
25
25
  /**
26
- * Real index of current SwiperItem, out of Swiper's data.
27
- * Same with `index`, but will be different from `index` when in loop mode.
26
+ * Physical index of current SwiperItem.
27
+ * Kept for compatibility with existing manual usage. This is resolved
28
+ * automatically when SwiperItem is rendered inside Swiper's children function.
28
29
  * @Android
29
30
  * @iOS
30
31
  * @Harmony
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/SwiperItem/index.tsx"],"names":[],"mappings":"AAYA,OAAO,KAAK,EAAE,YAAY,EA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runOnMainThread, useContext, useEffect, useMainThreadRef, useMemo } from "@lynx-js/react";
2
- import { SwiperContext } from "../store/index.jsx";
2
+ import { SwiperContext, SwiperItemContext } from "../store/index.jsx";
3
3
  function useFirstScreenStyle(props) {
4
4
  const { itemWidth, spaceBetween, itemHeight, itemRef, customAnimationFirstScreen, realIndex, modeConfig, initialIndex, RTL } = props;
5
5
  const containerStyle = useMemo(()=>{
@@ -57,8 +57,13 @@ function useFirstScreenStyle(props) {
57
57
  containerStyle
58
58
  };
59
59
  }
60
- const SwiperItem = ({ index, realIndex = index, children, overlap })=>{
60
+ const SwiperItem = ({ index, realIndex, children, overlap })=>{
61
61
  const { itemWidth, itemHeight, setChildrenRef, modeConfig, customAnimationFirstScreen, initialIndex = 0, spaceBetween, RTL } = useContext(SwiperContext);
62
+ const itemContext = useContext(SwiperItemContext);
63
+ const resolvedIndex = index ?? itemContext?.index;
64
+ const resolvedRealIndex = realIndex ?? itemContext?.realIndex ?? resolvedIndex;
65
+ const hasResolvedIndex = void 0 !== resolvedIndex;
66
+ const effectiveRealIndex = resolvedRealIndex ?? 0;
62
67
  const swiperItemRef = useMainThreadRef();
63
68
  const { containerStyle } = useFirstScreenStyle({
64
69
  itemWidth,
@@ -66,15 +71,16 @@ const SwiperItem = ({ index, realIndex = index, children, overlap })=>{
66
71
  spaceBetween,
67
72
  itemRef: swiperItemRef,
68
73
  modeConfig,
69
- realIndex,
74
+ realIndex: effectiveRealIndex,
70
75
  initialIndex,
71
76
  customAnimationFirstScreen,
72
77
  RTL
73
78
  });
79
+ if (!hasResolvedIndex) throw new Error('SwiperItem must be rendered inside Swiper children or receive an index prop.');
74
80
  function setRef(ref) {
75
81
  'main thread';
76
82
  swiperItemRef.current = ref;
77
- setChildrenRef(ref, realIndex ?? index);
83
+ setChildrenRef(ref, effectiveRealIndex);
78
84
  }
79
85
  return <view class='swiper-item' style={containerStyle} main-thread:ref={setRef} overlap={overlap}>
80
86
  {children}
@@ -1 +1 @@
1
- {"version":3,"file":"SwiperItem/index.jsx","sources":["webpack://@lynx-js/lynx-ui-swiper/./src/SwiperItem/index.tsx"],"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 {\n memo,\n runOnMainThread,\n useContext,\n useEffect,\n useMainThreadRef,\n useMemo,\n} from '@lynx-js/react'\nimport type { ReactElement, RefObject } from '@lynx-js/react'\n\nimport type { CSSProperties, MainThread } from '@lynx-js/types'\n\nimport { SwiperContext } from '../store'\nimport type { CompoundModeConfig, SwiperContextProps } from '../types'\n\nexport interface SwiperItemProps {\n /**\n * Index of current SwiperItem, out of Swiper's data.\n * @Android\n * @iOS\n * @Harmony\n */\n index: number\n /**\n * Children of SwiperItem\n * @Android\n * @iOS\n * @Harmony\n */\n children: ReactElement | ReactElement[]\n /**\n * Style of SwiperItem\n * @Android\n * @iOS\n * @Harmony\n */\n style?: CSSProperties\n /**\n * Real index of current SwiperItem, out of Swiper's data.\n * Same with `index`, but will be different from `index` when in loop mode.\n * @Android\n * @iOS\n * @Harmony\n */\n realIndex?: number\n /**\n * `overlap` attribute passed to SwiperItem's direct child.\n * This property is used only when opacity has issues.\n * Refer to {@link https://lynxjs.org/en/api/css/properties/opacity#opacity}\n * @Android\n * @iOS\n * @Harmony\n */\n overlap?: boolean\n}\n\ninterface IFirstScreenStyle extends\n Pick<\n SwiperContextProps,\n | 'itemWidth'\n | 'itemHeight'\n | 'initialIndex'\n | 'customAnimationFirstScreen'\n | 'RTL'\n >\n{\n itemRef: RefObject<MainThread.Element | undefined>\n spaceBetween: number\n realIndex: number\n modeConfig: CompoundModeConfig\n}\n\nfunction useFirstScreenStyle(props: IFirstScreenStyle) {\n const {\n itemWidth,\n spaceBetween,\n itemHeight,\n itemRef,\n customAnimationFirstScreen,\n realIndex,\n modeConfig,\n initialIndex,\n RTL,\n } = props\n\n const containerStyle = useMemo(() => {\n if (modeConfig.mode === 'normal') {\n let style: CSSProperties = {\n width: `${itemWidth}px`,\n height: `${itemHeight}px`,\n [RTL === true ? 'marginLeft' : 'marginRight']: `${spaceBetween}px`,\n }\n if (customAnimationFirstScreen) {\n const customStyle = customAnimationFirstScreen(\n -initialIndex + realIndex,\n realIndex,\n )\n style = {\n ...style,\n ...customStyle,\n }\n }\n\n return style\n } else if (modeConfig.mode === 'custom') {\n let style: CSSProperties = {\n width: `${itemWidth}px`,\n height: `${itemHeight}px`,\n position: 'absolute',\n }\n if (customAnimationFirstScreen) {\n const customStyle = customAnimationFirstScreen(\n -initialIndex + realIndex,\n realIndex,\n )\n style = {\n ...style,\n ...customStyle,\n }\n }\n\n return style\n }\n }, [])\n\n function updateMainThreadR(propsFromJS: {\n itemWidth: number\n itemHeight: SwiperContextProps['itemHeight']\n spaceBetween: number\n }) {\n 'main thread'\n if (itemRef.current) {\n itemRef.current.setStyleProperties({\n width: `${propsFromJS.itemWidth}px`,\n height: `${propsFromJS.itemHeight}px`,\n marginInlineEnd: `${propsFromJS.spaceBetween}px`,\n })\n }\n }\n\n useEffect(() => {\n runOnMainThread(updateMainThreadR)({\n itemWidth,\n itemHeight,\n spaceBetween,\n })\n }, [itemWidth, itemHeight, spaceBetween])\n\n return {\n containerStyle,\n }\n}\n\nconst SwiperItem = (\n { index, realIndex = index, children, overlap }: SwiperItemProps,\n) => {\n const {\n itemWidth,\n itemHeight,\n setChildrenRef,\n modeConfig,\n customAnimationFirstScreen,\n initialIndex = 0,\n spaceBetween,\n RTL,\n } = useContext(SwiperContext)\n const swiperItemRef = useMainThreadRef<MainThread.Element>()\n\n const { containerStyle } = useFirstScreenStyle({\n itemWidth,\n itemHeight,\n spaceBetween,\n itemRef: swiperItemRef,\n modeConfig,\n realIndex,\n initialIndex,\n customAnimationFirstScreen,\n RTL,\n })\n\n function setRef(ref: MainThread.Element) {\n 'main thread'\n swiperItemRef.current = ref\n setChildrenRef(ref, realIndex ?? index)\n }\n\n return (\n <view\n class='swiper-item'\n style={containerStyle}\n main-thread:ref={setRef}\n overlap={overlap}\n >\n {children}\n </view>\n )\n}\n\nconst MemoSwiperItem = memo(SwiperItem) as typeof SwiperItem\n\nexport { MemoSwiperItem as SwiperItem }\n"],"names":["useFirstScreenStyle","props","itemWidth","spaceBetween","itemHeight","itemRef","customAnimationFirstScreen","realIndex","modeConfig","initialIndex","RTL","containerStyle","useMemo","style","customStyle","updateMainThreadR","propsFromJS","useEffect","runOnMainThread","SwiperItem","index","children","overlap","setChildrenRef","useContext","SwiperContext","swiperItemRef","useMainThreadRef","setRef","ref","view","MemoSwiperItem","memo"],"mappings":";;AA4EA,SAASA,oBAAoBC,KAAwB;IACnD,MAAM,EACJC,SAAS,EACTC,YAAY,EACZC,UAAU,EACVC,OAAO,EACPC,0BAA0B,EAC1BC,SAAS,EACTC,UAAU,EACVC,YAAY,EACZC,GAAG,EACJ,GAAGT;IAEJ,MAAMU,iBAAiBC,QAAQ;QAC7B,IAAIJ,AAAoB,aAApBA,WAAW,IAAI,EAAe;YAChC,IAAIK,QAAuB;gBACzB,OAAO,GAAGX,UAAU,EAAE,CAAC;gBACvB,QAAQ,GAAGE,WAAW,EAAE,CAAC;gBACzB,CAACM,AAAQ,SAARA,MAAe,eAAe,cAAc,EAAE,GAAGP,aAAa,EAAE,CAAC;YACpE;YACA,IAAIG,4BAA4B;gBAC9B,MAAMQ,cAAcR,2BAClB,CAACG,eAAeF,WAChBA;gBAEFM,QAAQ;oBACN,GAAGA,KAAK;oBACR,GAAGC,WAAW;gBAChB;YACF;YAEA,OAAOD;QACT;QAAO,IAAIL,AAAoB,aAApBA,WAAW,IAAI,EAAe;YACvC,IAAIK,QAAuB;gBACzB,OAAO,GAAGX,UAAU,EAAE,CAAC;gBACvB,QAAQ,GAAGE,WAAW,EAAE,CAAC;gBACzB,UAAU;YACZ;YACA,IAAIE,4BAA4B;gBAC9B,MAAMQ,cAAcR,2BAClB,CAACG,eAAeF,WAChBA;gBAEFM,QAAQ;oBACN,GAAGA,KAAK;oBACR,GAAGC,WAAW;gBAChB;YACF;YAEA,OAAOD;QACT;IACF,GAAG,EAAE;IAEL,SAASE,kBAAkBC,WAI1B;QACC;QACA,IAAIX,QAAQ,OAAO,EACjBA,QAAQ,OAAO,CAAC,kBAAkB,CAAC;YACjC,OAAO,GAAGW,YAAY,SAAS,CAAC,EAAE,CAAC;YACnC,QAAQ,GAAGA,YAAY,UAAU,CAAC,EAAE,CAAC;YACrC,iBAAiB,GAAGA,YAAY,YAAY,CAAC,EAAE,CAAC;QAClD;IAEJ;IAEAC,UAAU;QACRC,gBAAgBH,mBAAmB;YACjCb;YACAE;YACAD;QACF;IACF,GAAG;QAACD;QAAWE;QAAYD;KAAa;IAExC,OAAO;QACLQ;IACF;AACF;AAEA,MAAMQ,aAAa,CACjB,EAAEC,KAAK,EAAEb,YAAYa,KAAK,EAAEC,QAAQ,EAAEC,OAAO,EAAmB;IAEhE,MAAM,EACJpB,SAAS,EACTE,UAAU,EACVmB,cAAc,EACdf,UAAU,EACVF,0BAA0B,EAC1BG,eAAe,CAAC,EAChBN,YAAY,EACZO,GAAG,EACJ,GAAGc,WAAWC;IACf,MAAMC,gBAAgBC;IAEtB,MAAM,EAAEhB,cAAc,EAAE,GAAGX,oBAAoB;QAC7CE;QACAE;QACAD;QACA,SAASuB;QACTlB;QACAD;QACAE;QACAH;QACAI;IACF;IAEA,SAASkB,OAAOC,GAAuB;QACrC;QACAH,cAAc,OAAO,GAAGG;QACxBN,eAAeM,KAAKtB,aAAaa;IACnC;IAEA,QACGU,KACC,MAAM,cACN,OAAOnB,gBACP,YAAY,KAAKiB,QACjB,SAASN,SACV;MACC,CAACD,SAAS;IACZ,EAAES;AAEN;AAEA,MAAMC,iBAAiBC,KAAKb"}
1
+ {"version":3,"file":"SwiperItem/index.jsx","sources":["webpack://@lynx-js/lynx-ui-swiper/./src/SwiperItem/index.tsx"],"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 {\n memo,\n runOnMainThread,\n useContext,\n useEffect,\n useMainThreadRef,\n useMemo,\n} from '@lynx-js/react'\nimport type { ReactElement, RefObject } from '@lynx-js/react'\n\nimport type { CSSProperties, MainThread } from '@lynx-js/types'\n\nimport { SwiperContext, SwiperItemContext } from '../store'\nimport type { CompoundModeConfig, SwiperContextProps } from '../types'\n\nexport interface SwiperItemProps {\n /**\n * Index of current SwiperItem, out of Swiper's data.\n * @Android\n * @iOS\n * @Harmony\n */\n index?: number\n /**\n * Children of SwiperItem\n * @Android\n * @iOS\n * @Harmony\n */\n children: ReactElement | ReactElement[]\n /**\n * Style of SwiperItem\n * @Android\n * @iOS\n * @Harmony\n */\n style?: CSSProperties\n /**\n * Physical index of current SwiperItem.\n * Kept for compatibility with existing manual usage. This is resolved\n * automatically when SwiperItem is rendered inside Swiper's children function.\n * @Android\n * @iOS\n * @Harmony\n */\n realIndex?: number\n /**\n * `overlap` attribute passed to SwiperItem's direct child.\n * This property is used only when opacity has issues.\n * Refer to {@link https://lynxjs.org/en/api/css/properties/opacity#opacity}\n * @Android\n * @iOS\n * @Harmony\n */\n overlap?: boolean\n}\n\ninterface IFirstScreenStyle extends\n Pick<\n SwiperContextProps,\n | 'itemWidth'\n | 'itemHeight'\n | 'initialIndex'\n | 'customAnimationFirstScreen'\n | 'RTL'\n >\n{\n itemRef: RefObject<MainThread.Element | undefined>\n spaceBetween: number\n realIndex: number\n modeConfig: CompoundModeConfig\n}\n\nfunction useFirstScreenStyle(props: IFirstScreenStyle) {\n const {\n itemWidth,\n spaceBetween,\n itemHeight,\n itemRef,\n customAnimationFirstScreen,\n realIndex,\n modeConfig,\n initialIndex,\n RTL,\n } = props\n\n const containerStyle = useMemo(() => {\n if (modeConfig.mode === 'normal') {\n let style: CSSProperties = {\n width: `${itemWidth}px`,\n height: `${itemHeight}px`,\n [RTL === true ? 'marginLeft' : 'marginRight']: `${spaceBetween}px`,\n }\n if (customAnimationFirstScreen) {\n const customStyle = customAnimationFirstScreen(\n -initialIndex + realIndex,\n realIndex,\n )\n style = {\n ...style,\n ...customStyle,\n }\n }\n\n return style\n } else if (modeConfig.mode === 'custom') {\n let style: CSSProperties = {\n width: `${itemWidth}px`,\n height: `${itemHeight}px`,\n position: 'absolute',\n }\n if (customAnimationFirstScreen) {\n const customStyle = customAnimationFirstScreen(\n -initialIndex + realIndex,\n realIndex,\n )\n style = {\n ...style,\n ...customStyle,\n }\n }\n\n return style\n }\n }, [])\n\n function updateMainThreadR(propsFromJS: {\n itemWidth: number\n itemHeight: SwiperContextProps['itemHeight']\n spaceBetween: number\n }) {\n 'main thread'\n if (itemRef.current) {\n itemRef.current.setStyleProperties({\n width: `${propsFromJS.itemWidth}px`,\n height: `${propsFromJS.itemHeight}px`,\n marginInlineEnd: `${propsFromJS.spaceBetween}px`,\n })\n }\n }\n\n useEffect(() => {\n runOnMainThread(updateMainThreadR)({\n itemWidth,\n itemHeight,\n spaceBetween,\n })\n }, [itemWidth, itemHeight, spaceBetween])\n\n return {\n containerStyle,\n }\n}\n\nconst SwiperItem = (\n { index, realIndex, children, overlap }: SwiperItemProps,\n) => {\n const {\n itemWidth,\n itemHeight,\n setChildrenRef,\n modeConfig,\n customAnimationFirstScreen,\n initialIndex = 0,\n spaceBetween,\n RTL,\n } = useContext(SwiperContext)\n const itemContext = useContext(SwiperItemContext)\n const resolvedIndex = index ?? itemContext?.index\n const resolvedRealIndex = realIndex ?? itemContext?.realIndex ?? resolvedIndex\n const hasResolvedIndex = resolvedIndex !== undefined\n const effectiveRealIndex = resolvedRealIndex ?? 0\n const swiperItemRef = useMainThreadRef<MainThread.Element>()\n\n const { containerStyle } = useFirstScreenStyle({\n itemWidth,\n itemHeight,\n spaceBetween,\n itemRef: swiperItemRef,\n modeConfig,\n realIndex: effectiveRealIndex,\n initialIndex,\n customAnimationFirstScreen,\n RTL,\n })\n\n if (!hasResolvedIndex) {\n throw new Error(\n 'SwiperItem must be rendered inside Swiper children or receive an index prop.',\n )\n }\n\n function setRef(ref: MainThread.Element) {\n 'main thread'\n swiperItemRef.current = ref\n setChildrenRef(ref, effectiveRealIndex)\n }\n\n return (\n <view\n class='swiper-item'\n style={containerStyle}\n main-thread:ref={setRef}\n overlap={overlap}\n >\n {children}\n </view>\n )\n}\n\nconst MemoSwiperItem = memo(SwiperItem) as typeof SwiperItem\n\nexport { MemoSwiperItem as SwiperItem }\n"],"names":["useFirstScreenStyle","props","itemWidth","spaceBetween","itemHeight","itemRef","customAnimationFirstScreen","realIndex","modeConfig","initialIndex","RTL","containerStyle","useMemo","style","customStyle","updateMainThreadR","propsFromJS","useEffect","runOnMainThread","SwiperItem","index","children","overlap","setChildrenRef","useContext","SwiperContext","itemContext","SwiperItemContext","resolvedIndex","resolvedRealIndex","hasResolvedIndex","undefined","effectiveRealIndex","swiperItemRef","useMainThreadRef","Error","setRef","ref","view","MemoSwiperItem","memo"],"mappings":";;AA6EA,SAASA,oBAAoBC,KAAwB;IACnD,MAAM,EACJC,SAAS,EACTC,YAAY,EACZC,UAAU,EACVC,OAAO,EACPC,0BAA0B,EAC1BC,SAAS,EACTC,UAAU,EACVC,YAAY,EACZC,GAAG,EACJ,GAAGT;IAEJ,MAAMU,iBAAiBC,QAAQ;QAC7B,IAAIJ,AAAoB,aAApBA,WAAW,IAAI,EAAe;YAChC,IAAIK,QAAuB;gBACzB,OAAO,GAAGX,UAAU,EAAE,CAAC;gBACvB,QAAQ,GAAGE,WAAW,EAAE,CAAC;gBACzB,CAACM,AAAQ,SAARA,MAAe,eAAe,cAAc,EAAE,GAAGP,aAAa,EAAE,CAAC;YACpE;YACA,IAAIG,4BAA4B;gBAC9B,MAAMQ,cAAcR,2BAClB,CAACG,eAAeF,WAChBA;gBAEFM,QAAQ;oBACN,GAAGA,KAAK;oBACR,GAAGC,WAAW;gBAChB;YACF;YAEA,OAAOD;QACT;QAAO,IAAIL,AAAoB,aAApBA,WAAW,IAAI,EAAe;YACvC,IAAIK,QAAuB;gBACzB,OAAO,GA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MAAM,IAAIK,MACR;IAIJ,SAASC,OAAOC,GAAuB;QACrC;QACAJ,cAAc,OAAO,GAAGI;QACxBd,eAAec,KAAKL;IACtB;IAEA,QACGM,KACC,MAAM,cACN,OAAO3B,gBACP,YAAY,KAAKyB,QACjB,SAASd,SACV;MACC,CAACD,SAAS;IACZ,EAAEiB;AAEN;AAEA,MAAMC,iBAAiBC,KAAKrB"}
@@ -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,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,IAAYC,YAAY,CAAC;QAC3C;QACA,MAAMC,YAAYL,aAAa,OAAO;QACtC,MAAMM,gBAAgBR,iBAAiB,OAAO;QAE9C,MAAMS,QAAQC,KAAK,GAAG;QAEtB,MAAOH,UAAU,MAAM,GAAGD,aAAaC,SAAS,CAAC,EAAE,GAAGE,QAAQJ,GAAI;YAChEE,UAAU,KAAK;YACfC,cAAc,KAAK;QACrB;IACF;IAEA,MAAMG,cAAc;QAClB;QACAP,WAAW;QACX,MAAMG,YAAYL,aAAa,OAAO;QACtC,MAAMM,gBAAgBR,iBAAiB,OAAO;QAC9C,MAAM,EAAEY,MAAM,EAAE,GAAGL;QACnB,IAAIK,SAAS,GACX,OAAO;YACL,UAAU;YACV,WAAWC,eAAe,MAAM;QAClC;QAEF,MAAMC,WAAWf,MACbS,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,YAAYL,aAAa,OAAO;QACtC,MAAMM,gBAAgBR,iBAAiB,OAAO;QAE9CQ,cAAc,IAAI,CAACS;QACnBV,UAAU,IAAI,CAACG,KAAK,GAAG;QAGvBN,WAAW,IAAI;IACjB;IAEA,SAASc;QACP;QACAf;IACF;IAEA,SAASgB,kBAAkBC,KAA4B;QACrD;QAEAJ,eAAeI,MAAM,MAAM,CAAC,CAAC;IAC/B;IAEA,OAAO;QACLT;QACAO;QACAC;IACF;AACF"}
@@ -1,3 +1,8 @@
1
1
  import type { SwiperContextProps } from '../types';
2
+ export interface SwiperItemContextProps {
3
+ index: number;
4
+ realIndex: number;
5
+ }
2
6
  export declare const SwiperContext: import("react").Context<SwiperContextProps>;
7
+ export declare const SwiperItemContext: import("react").Context<SwiperItemContextProps | undefined>;
3
8
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/store/index.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,UAAU,CAAA;AAElD,eAAO,MAAM,aAAa,6CAYxB,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/store/index.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,UAAU,CAAA;AAElD,MAAM,WAAW,sBAAsB;IACrC,KAAK,EAAE,MAAM,CAAA;IACb,SAAS,EAAE,MAAM,CAAA;CAClB;AAED,eAAO,MAAM,aAAa,6CAYxB,CAAA;AAEF,eAAO,MAAM,iBAAiB,6DAElB,CAAA"}
@@ -13,6 +13,7 @@ const SwiperContext = createContext({
13
13
  spaceBetween: 0,
14
14
  RTL: false
15
15
  });
16
- export { SwiperContext };
16
+ const SwiperItemContext = createContext(void 0);
17
+ export { SwiperContext, SwiperItemContext };
17
18
 
18
19
  //# sourceMappingURL=index.jsx.map
@@ -1 +1 @@
1
- {"version":3,"file":"store/index.jsx","sources":["webpack://@lynx-js/lynx-ui-swiper/./src/store/index.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 { createContext } from '@lynx-js/react'\n\nimport { noop } from '@lynx-js/lynx-ui-common'\n\nimport type { SwiperContextProps } from '../types'\n\nexport const SwiperContext = createContext<SwiperContextProps>({\n itemWidth: 350,\n itemHeight: 'auto',\n setChildrenRef: noop,\n modeConfig: {\n mode: 'normal',\n align: 'start',\n },\n initialIndex: 0,\n loop: false,\n spaceBetween: 0,\n RTL: false,\n})\n"],"names":["SwiperContext","createContext","noop"],"mappings":";;AAUO,MAAMA,gBAAgBC,cAAkC;IAC7D,WAAW;IACX,YAAY;IACZ,gBAAgBC;IAChB,YAAY;QACV,MAAM;QACN,OAAO;IACT;IACA,cAAc;IACd,MAAM;IACN,cAAc;IACd,KAAK;AACP"}
1
+ {"version":3,"file":"store/index.jsx","sources":["webpack://@lynx-js/lynx-ui-swiper/./src/store/index.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 { createContext } from '@lynx-js/react'\n\nimport { noop } from '@lynx-js/lynx-ui-common'\n\nimport type { SwiperContextProps } from '../types'\n\nexport interface SwiperItemContextProps {\n index: number\n realIndex: number\n}\n\nexport const SwiperContext = createContext<SwiperContextProps>({\n itemWidth: 350,\n itemHeight: 'auto',\n setChildrenRef: noop,\n modeConfig: {\n mode: 'normal',\n align: 'start',\n },\n initialIndex: 0,\n loop: false,\n spaceBetween: 0,\n RTL: false,\n})\n\nexport const SwiperItemContext = createContext<\n SwiperItemContextProps | undefined\n>(undefined)\n"],"names":["SwiperContext","createContext","noop","SwiperItemContext","undefined"],"mappings":";;AAeO,MAAMA,gBAAgBC,cAAkC;IAC7D,WAAW;IACX,YAAY;IACZ,gBAAgBC;IAChB,YAAY;QACV,MAAM;QACN,OAAO;IACT;IACA,cAAc;IACd,MAAM;IACN,cAAc;IACd,KAAK;AACP;AAEO,MAAMC,oBAAoBF,cAE/BG"}
@@ -38,7 +38,7 @@ export interface SwiperProps<T> {
38
38
  * itemWidth={350}
39
39
  * >
40
40
  * {({ index, item }) => (
41
- * <SwiperItem index={index} key={index}>
41
+ * <SwiperItem>
42
42
  * <image class="image" src={`${item}`}></image>
43
43
  * <text class="image-text">Number.{index}</text>
44
44
  * </SwiperItem>
@@ -441,8 +441,23 @@ export interface onBounceParams {
441
441
  offset: number;
442
442
  }
443
443
  export interface RenderFunctionProps<T> {
444
+ /**
445
+ * Data item of current SwiperItem.
446
+ * @zh 当前 SwiperItem 对应的数据项。
447
+ */
444
448
  item: T;
449
+ /**
450
+ * Logical index of current SwiperItem in Swiper's data.
451
+ * @zh 当前 SwiperItem 在 Swiper 数据中的逻辑索引。
452
+ */
445
453
  index: number;
454
+ /**
455
+ * Physical index of current SwiperItem.
456
+ * Kept for compatibility with existing manual SwiperItem wiring.
457
+ * SwiperItem receives this automatically when rendered inside Swiper's
458
+ * children function.
459
+ * @zh 当前 SwiperItem 的物理索引,为兼容已有手动传参用法保留。SwiperItem 在 Swiper 的 children 函数内渲染时会自动获取该值。
460
+ */
446
461
  realIndex: number;
447
462
  }
448
463
  //# sourceMappingURL=index.docs.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.docs.d.ts","sourceRoot":"","sources":["../../src/types/index.docs.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAA;AAElD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAA;AAEnD,MAAM,WAAW,WAAW,CAAC,CAAC;IAC5B;;;;;;OAMG;IACH,IAAI,EAAE,CAAC,EAAE,CAAA;IACT;;;;;;OAMG;IACH,SAAS,EAAE,MAAM,CAAA;IACjB;;;;;;OAMG;IACH,UAAU,CAAC,EAAE,MAAM,GAAG,MAAM,CAAA;IAC5B;;;;;;;;;;;;;;;;;;;;OAoBG;IACH,QAAQ,EAAE,CAAC,IAAI,EAAE,mBAAmB,CAAC,CAAC,CAAC,KAAK,YAAY,CAAA;IACxD;;;;;;;OAOG;IACH,cAAc,CAAC,EAAE,MAAM,CAAA;IACvB;;;;;;;OAOG;IACH,YAAY,CAAC,EAAE,MAAM,CAAA;IACrB;;;;;;;OAOG;IACH,IAAI,CAAC,EAAE,OAAO,CAAA;IACd;;;;;;;;OAQG;IACH,kBAAkB,CAAC,EAAE,MAAM,CAAA;IAC3B;;;;;;;OAOG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB;;;;;;OAMG;IAC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;IAC9B;;;;;;OAMG;IACH,aAAa,CAAC,EAAE,YAAY,CAAA;IAC5B;;;;;;OAMG;IACH,uBAAuB,CAAC,EAAE,CAAC,YAAY,EAAE,cAAc,KAAK,IAAI,CAAA;IAChE;;;;;;OAMG;IACH,qBAAqB,CAAC,EAAE,CAAC,YAAY,EAAE,cAAc,KAAK,IAAI,CAAA;IAC9D;;;;;;;;OAQG;IACH,oBAAoB,CAAC,EAAE,MAAM,CAAA;IAC7B;;;;;;;;OAQG;IACH,kBAAkB,CAAC,EAAE,MAAM,CAAA;CAC5B;AAED,MAAM,WAAW,SAAS;IACxB;;;;;;OAMG;IACH,OAAO,EAAE,CAAC,KAAK,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,cAAc,KAAK,IAAI,CAAA;IAC1D;;;;;;OAMG;IACH,SAAS,EAAE,MAAM,IAAI,CAAA;IACrB;;;;;;OAMG;IACH,SAAS,EAAE,MAAM,IAAI,CAAA;IACrB;;;;;;;;OAQG;IACH,eAAe,EAAE,MAAM,IAAI,CAAA;CAC5B;AAED,MAAM,WAAW,cAAc;IAC7B,IAAI,EAAE,OAAO,GAAG,KAAK,CAAA;IACrB,MAAM,EAAE,MAAM,CAAA;CACf;AAED,MAAM,WAAW,mBAAmB,CAAC,CAAC;IACpC;;;OAGG;IACH,IAAI,EAAE,CAAC,CAAA;IACP;;;OAGG;IACH,KAAK,EAAE,MAAM,CAAA;IACb;;;;;;OAMG;IACH,SAAS,EAAE,MAAM,CAAA;CAClB"}
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.132.0",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "git+https://github.com/lynx-family/lynx-ui.git",
@@ -25,11 +25,11 @@
25
25
  "dist/**"
26
26
  ],
27
27
  "dependencies": {
28
- "@lynx-js/react-use": "0.0.7",
29
- "@lynx-js/lynx-ui-common": "3.130.0"
28
+ "@lynx-js/react-use": "0.1.3",
29
+ "@lynx-js/lynx-ui-common": "3.131.0"
30
30
  },
31
31
  "devDependencies": {
32
- "@lynx-js/react": "0.113.0",
32
+ "@lynx-js/react": "0.114.0",
33
33
  "@lynx-js/types": "3.6.0",
34
34
  "@rslib/core": "^0.16.0",
35
35
  "@types/react": "^18.3.8",
@@ -25,7 +25,7 @@ import { useModeConfig } from '../hooks/useModeConfig'
25
25
  import { useOffset } from '../hooks/useOffset'
26
26
  import { useOffsetLimit } from '../hooks/useOffsetLimit'
27
27
  import { useReset } from '../hooks/useReset'
28
- import { SwiperContext } from '../store'
28
+ import { SwiperContext, SwiperItemContext } from '../store'
29
29
  import type {
30
30
  SwipeDirection,
31
31
  SwiperProps,
@@ -326,6 +326,24 @@ const Swiper = forwardRef(
326
326
  cancelAnimation: cancelAnimationJS,
327
327
  }))
328
328
 
329
+ function renderSwiperItem(props: {
330
+ item: T
331
+ index: number
332
+ realIndex: number
333
+ }) {
334
+ return (
335
+ <SwiperItemContext.Provider
336
+ key={props.realIndex}
337
+ value={{
338
+ index: props.index,
339
+ realIndex: props.realIndex,
340
+ }}
341
+ >
342
+ {children(props)}
343
+ </SwiperItemContext.Provider>
344
+ )
345
+ }
346
+
329
347
  const { bounceStartView, bounceEndView } = useBounceView({
330
348
  startBounceItem,
331
349
  endBounceItem,
@@ -366,7 +384,7 @@ const Swiper = forwardRef(
366
384
  { length: loopDuplicateCount },
367
385
  (_, i) => loopDuplicateCount - i - 1,
368
386
  ).map((i) =>
369
- children({
387
+ renderSwiperItem({
370
388
  index: data.length - i - 1,
371
389
  item: data[data.length - i - 1],
372
390
  realIndex: -i - 1,
@@ -376,7 +394,7 @@ const Swiper = forwardRef(
376
394
  )
377
395
  : null}
378
396
  {data.map((item: T, index: number) =>
379
- children({
397
+ renderSwiperItem({
380
398
  index,
381
399
  item,
382
400
  realIndex: index,
@@ -388,7 +406,7 @@ const Swiper = forwardRef(
388
406
  {Array.from({ length: loopDuplicateCount }, (_, i) => i).map((
389
407
  i,
390
408
  ) =>
391
- children({
409
+ renderSwiperItem({
392
410
  index: i,
393
411
  item: data[i],
394
412
  realIndex: data.length + i,
@@ -14,7 +14,7 @@ import type { ReactElement, RefObject } from '@lynx-js/react'
14
14
 
15
15
  import type { CSSProperties, MainThread } from '@lynx-js/types'
16
16
 
17
- import { SwiperContext } from '../store'
17
+ import { SwiperContext, SwiperItemContext } from '../store'
18
18
  import type { CompoundModeConfig, SwiperContextProps } from '../types'
19
19
 
20
20
  export interface SwiperItemProps {
@@ -24,7 +24,7 @@ export interface SwiperItemProps {
24
24
  * @iOS
25
25
  * @Harmony
26
26
  */
27
- index: number
27
+ index?: number
28
28
  /**
29
29
  * Children of SwiperItem
30
30
  * @Android
@@ -40,8 +40,9 @@ export interface SwiperItemProps {
40
40
  */
41
41
  style?: CSSProperties
42
42
  /**
43
- * Real index of current SwiperItem, out of Swiper's data.
44
- * Same with `index`, but will be different from `index` when in loop mode.
43
+ * Physical index of current SwiperItem.
44
+ * Kept for compatibility with existing manual usage. This is resolved
45
+ * automatically when SwiperItem is rendered inside Swiper's children function.
45
46
  * @Android
46
47
  * @iOS
47
48
  * @Harmony
@@ -156,7 +157,7 @@ function useFirstScreenStyle(props: IFirstScreenStyle) {
156
157
  }
157
158
 
158
159
  const SwiperItem = (
159
- { index, realIndex = index, children, overlap }: SwiperItemProps,
160
+ { index, realIndex, children, overlap }: SwiperItemProps,
160
161
  ) => {
161
162
  const {
162
163
  itemWidth,
@@ -168,6 +169,11 @@ const SwiperItem = (
168
169
  spaceBetween,
169
170
  RTL,
170
171
  } = useContext(SwiperContext)
172
+ const itemContext = useContext(SwiperItemContext)
173
+ const resolvedIndex = index ?? itemContext?.index
174
+ const resolvedRealIndex = realIndex ?? itemContext?.realIndex ?? resolvedIndex
175
+ const hasResolvedIndex = resolvedIndex !== undefined
176
+ const effectiveRealIndex = resolvedRealIndex ?? 0
171
177
  const swiperItemRef = useMainThreadRef<MainThread.Element>()
172
178
 
173
179
  const { containerStyle } = useFirstScreenStyle({
@@ -176,16 +182,22 @@ const SwiperItem = (
176
182
  spaceBetween,
177
183
  itemRef: swiperItemRef,
178
184
  modeConfig,
179
- realIndex,
185
+ realIndex: effectiveRealIndex,
180
186
  initialIndex,
181
187
  customAnimationFirstScreen,
182
188
  RTL,
183
189
  })
184
190
 
191
+ if (!hasResolvedIndex) {
192
+ throw new Error(
193
+ 'SwiperItem must be rendered inside Swiper children or receive an index prop.',
194
+ )
195
+ }
196
+
185
197
  function setRef(ref: MainThread.Element) {
186
198
  'main thread'
187
199
  swiperItemRef.current = ref
188
- setChildrenRef(ref, realIndex ?? index)
200
+ setChildrenRef(ref, effectiveRealIndex)
189
201
  }
190
202
 
191
203
  return (
@@ -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() {
@@ -8,6 +8,11 @@ import { noop } from '@lynx-js/lynx-ui-common'
8
8
 
9
9
  import type { SwiperContextProps } from '../types'
10
10
 
11
+ export interface SwiperItemContextProps {
12
+ index: number
13
+ realIndex: number
14
+ }
15
+
11
16
  export const SwiperContext = createContext<SwiperContextProps>({
12
17
  itemWidth: 350,
13
18
  itemHeight: 'auto',
@@ -21,3 +26,7 @@ export const SwiperContext = createContext<SwiperContextProps>({
21
26
  spaceBetween: 0,
22
27
  RTL: false,
23
28
  })
29
+
30
+ export const SwiperItemContext = createContext<
31
+ SwiperItemContextProps | undefined
32
+ >(undefined)
@@ -44,7 +44,7 @@ export interface SwiperProps<T> {
44
44
  * itemWidth={350}
45
45
  * >
46
46
  * {({ index, item }) => (
47
- * <SwiperItem index={index} key={index}>
47
+ * <SwiperItem>
48
48
  * <image class="image" src={`${item}`}></image>
49
49
  * <text class="image-text">Number.{index}</text>
50
50
  * </SwiperItem>
@@ -459,7 +459,22 @@ export interface onBounceParams {
459
459
  }
460
460
 
461
461
  export interface RenderFunctionProps<T> {
462
+ /**
463
+ * Data item of current SwiperItem.
464
+ * @zh 当前 SwiperItem 对应的数据项。
465
+ */
462
466
  item: T
467
+ /**
468
+ * Logical index of current SwiperItem in Swiper's data.
469
+ * @zh 当前 SwiperItem 在 Swiper 数据中的逻辑索引。
470
+ */
463
471
  index: number
472
+ /**
473
+ * Physical index of current SwiperItem.
474
+ * Kept for compatibility with existing manual SwiperItem wiring.
475
+ * SwiperItem receives this automatically when rendered inside Swiper's
476
+ * children function.
477
+ * @zh 当前 SwiperItem 的物理索引,为兼容已有手动传参用法保留。SwiperItem 在 Swiper 的 children 函数内渲染时会自动获取该值。
478
+ */
464
479
  realIndex: number
465
480
  }