@lynx-js/lynx-ui-swiper 3.137.0 → 3.140.1
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 +16 -0
- package/dist/Swiper/index.d.ts.map +1 -1
- package/dist/Swiper/index.jsx +5 -3
- package/dist/Swiper/index.jsx.map +1 -1
- package/dist/hooks/useBounceConfig.d.ts +2 -2
- package/dist/hooks/useOffset.d.ts.map +1 -1
- package/dist/hooks/useOffset.jsx +2 -2
- package/dist/hooks/useOffset.jsx.map +1 -1
- package/dist/types/index.d.ts +3 -3
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/index.docs.d.ts +9 -4
- package/dist/types/index.docs.d.ts.map +1 -1
- package/dist/types/index.jsx.map +1 -1
- package/package.json +2 -2
- package/src/Swiper/index.tsx +10 -7
- package/src/hooks/useOffset.ts +4 -4
- package/src/types/index.docs.ts +10 -4
- package/src/types/index.ts +4 -4
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,21 @@
|
|
|
1
1
|
# @lynx-js/lynx-ui-swiper
|
|
2
2
|
|
|
3
|
+
## 3.140.1
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- Add PascalCase names for public hook types and normalize supporting type names, ([#355](https://github.com/lynx-family/lynx-ui/pull/355))
|
|
8
|
+
retaining deprecated aliases for existing public names.
|
|
9
|
+
|
|
10
|
+
## 3.139.0
|
|
11
|
+
|
|
12
|
+
### Patch Changes
|
|
13
|
+
|
|
14
|
+
- Default the Swiper root view's `z-index` to `0` so z-indexed items remain in the wrapper event chain and directional gesture consumption works in custom mode. ([#310](https://github.com/lynx-family/lynx-ui/pull/310))
|
|
15
|
+
|
|
16
|
+
- Updated dependencies [[`1a4ad19`](https://github.com/lynx-family/lynx-ui/commit/1a4ad190993d57425b4c377a7dd63882cc65a8d2)]:
|
|
17
|
+
- @lynx-js/lynx-ui-common@3.139.0
|
|
18
|
+
|
|
3
19
|
## 3.137.0
|
|
4
20
|
|
|
5
21
|
### Patch Changes
|
|
@@ -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;
|
|
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;2EA0VlE,CAAA;AAED,QAAA,MAAM,cAAc,EAIf,OAAO,MAAM,CAAA;AAElB,OAAO,EAAE,cAAc,IAAI,MAAM,EAAE,CAAA"}
|
package/dist/Swiper/index.jsx
CHANGED
|
@@ -223,13 +223,15 @@ const Swiper = forwardRef(({ data = [], itemWidth, containerWidth = lynx.__globa
|
|
|
223
223
|
RTL,
|
|
224
224
|
containerWidth
|
|
225
225
|
});
|
|
226
|
-
|
|
227
|
-
|
|
226
|
+
const rootStyle = {
|
|
227
|
+
zIndex: 0,
|
|
228
228
|
...style,
|
|
229
229
|
width: `${containerWidth}px`,
|
|
230
230
|
height: `${itemHeight}px`,
|
|
231
231
|
direction: 'lynx-rtl' === RTL ? 'lynx-rtl' : RTL ? 'rtl' : 'ltr'
|
|
232
|
-
}
|
|
232
|
+
};
|
|
233
|
+
return <SwiperContext.Provider value={contextValue}>
|
|
234
|
+
<view class='lynx-ui-swiper__root' style={rootStyle} {...touchHandlers} consume-slide-event={consumeSlideEvent} block-native-event={blockNativeEvent}>
|
|
233
235
|
<view class='lynx-ui-swiper__track' style={containerStyle} ref={setContainerRef} main-thread:ref={containerRef} implicit-animation='false'>
|
|
234
236
|
{bounceStartView}
|
|
235
237
|
{loop ? <>
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Swiper/index.jsx","sources":["../../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='lynx-ui-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='lynx-ui-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,aAAa,CAAC,WAAW,IAC1CC,WAAW,UAAU,GAAGA,WAAW,UAAU,EAClDC,OAAO,KAAK,EACZC,IAAI,EACJC,WAAW,KAAK,EAChBC,mBAAmB,IAAI,EACvBC,WAAW,GAAG,EACdC,aAAa,MAAM,EACnBC,eAAe,CAAC,EAChBC,QAAQ,EACRC,YAAY,EACZC,WAAW,EACX,YAAYC,WAAW,EACvB,aAAaC,YAAY,EACzBC,YAAY,EACZC,QAAQ,EACR,sBAAsBC,SAASC,OAAO,EAC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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"}
|
|
1
|
+
{"version":3,"file":"Swiper/index.jsx","sources":["../../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 { CSSProperties, 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 const rootStyle: CSSProperties = {\n zIndex: 0,\n ...style,\n width: `${containerWidth}px`,\n height: `${itemHeight}px`,\n direction: RTL === 'lynx-rtl' ? 'lynx-rtl' : (RTL ? 'rtl' : 'ltr'),\n }\n\n return (\n <SwiperContext.Provider value={contextValue}>\n <view\n class='lynx-ui-swiper__root'\n style={rootStyle}\n {...touchHandlers}\n consume-slide-event={consumeSlideEvent}\n block-native-event={blockNativeEvent}\n >\n <view\n class='lynx-ui-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","rootStyle","SwiperContext","view","Array","_","item","index","MemoizedSwiper","memo","prevProps","nextProps","comparePropsWithObject"],"mappings":";;;;;;;;;;;;;;;AA0CA,MAAMA,SAASC,WACb,CACE,EACEC,OAAO,EA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IAAmB,GAC7B,CAAC+E,GAAGpC,IAAM3C,qBAAqB2C,IAAI,GACnC,GAAG,CAAC,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,CAACoH,MAASC,QAClBZ,iBAAiB;YACfY;YACAD;YACA,WAAWC;QACb,IACA;YACF,CAAChH,SAEK;kBACA,CAAC6G,MAAM,IAAI,CAAC;QAAE,QAAQ9E;IAAmB,GAAG,CAAC+E,GAAGpC,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,EAAEI,KAAK;QACT,EAAEA,KAAK;MACT,EAAED,cAAc;AAEpB;AAGF,MAAMM,iBAAiBC,KACrBzH,QACA,CAAC0H,WAAWC,YACVC,uBAAuBF,WAAWC,WAAW;QAAC;QAAc;KAAU"}
|
|
@@ -5,8 +5,8 @@ declare function useBounceConfig(bounceConfig?: BounceConfig): {
|
|
|
5
5
|
endBounceItem: import("react").ReactElement<any, string | import("react").JSXElementConstructor<any>> | undefined;
|
|
6
6
|
startBounceItemWidth: number;
|
|
7
7
|
endBounceItemWidth: number;
|
|
8
|
-
onStartBounceItemBounce: ((bounceParams: import("../types/index.js").
|
|
9
|
-
onEndBounceItemBounce: ((bounceParams: import("../types/index.js").
|
|
8
|
+
onStartBounceItemBounce: ((bounceParams: import("../types/index.js").OnBounceParams) => void) | undefined;
|
|
9
|
+
onEndBounceItemBounce: ((bounceParams: import("../types/index.js").OnBounceParams) => void) | undefined;
|
|
10
10
|
};
|
|
11
11
|
export { useBounceConfig };
|
|
12
12
|
//# sourceMappingURL=useBounceConfig.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useOffset.d.ts","sourceRoot":"","sources":["../../src/hooks/useOffset.ts"],"names":[],"mappings":"AAWA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAA;AAQhD,OAAO,EAAE,cAAc,EAAE,MAAM,UAAU,CAAA;AACzC,OAAO,KAAK,EACV,YAAY,EACZ,kBAAkB,EAClB,iBAAiB,
|
|
1
|
+
{"version":3,"file":"useOffset.d.ts","sourceRoot":"","sources":["../../src/hooks/useOffset.ts"],"names":[],"mappings":"AAWA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAA;AAQhD,OAAO,EAAE,cAAc,EAAE,MAAM,UAAU,CAAA;AACzC,OAAO,KAAK,EACV,YAAY,EACZ,kBAAkB,EAClB,iBAAiB,EAEjB,YAAY,EACZ,cAAc,EACd,WAAW,EACZ,MAAM,UAAU,CAAA;AAGjB,UAAU,aAAc,SACtB,QAAQ,CACN,IAAI,CACF,WAAW,CAAC,OAAO,CAAC,EAClB,MAAM,GACN,UAAU,GACV,cAAc,GACd,gBAAgB,GAChB,UAAU,GACV,kBAAkB,GAClB,mBAAmB,GACnB,KAAK,CACR,CACF;IAED,SAAS,EAAE,MAAM,CAAA;IACjB,IAAI,EAAE,MAAM,CAAA;IACZ,YAAY,EAAE,MAAM,CAAA;IACpB,MAAM,EAAE,WAAW,CAAC,WAAW,CAAC,OAAO,CAAC,CAAC,oBAAoB,CAAC,CAAC,CAAA;IAC/D,UAAU,EAAE,kBAAkB,CAAA;IAC9B,YAAY,EAAE,OAAO,CAAA;IACrB,oBAAoB,EAAE,WAAW,CAAC,YAAY,CAAC,sBAAsB,CAAC,CAAC,CAAA;IACvE,kBAAkB,EAAE,WAAW,CAAC,YAAY,CAAC,oBAAoB,CAAC,CAAC,CAAA;IACnE,uBAAuB,EAAE,YAAY,CAAC,yBAAyB,CAAC,CAAA;IAChE,qBAAqB,EAAE,YAAY,CAAC,yBAAyB,CAAC,CAAA;IAC9D,+BAA+B,EAAE,OAAO,CAAA;IACxC,aAAa,EAAE,MAAM,IAAI,CAAA;IACzB,cAAc,EAAE,MAAM,IAAI,CAAA;IAC1B,WAAW,EAAE,iBAAiB,CAAA;CAC/B;AAmCD;;;GAGG;AACH,iBAAS,SAAS,CAChB,EACE,IAAI,EACJ,QAAQ,EACR,IAAI,EACJ,YAAY,EACZ,MAAM,EACN,SAAS,EACT,YAAY,EACZ,QAAQ,EACR,gBAAgB,EAChB,WAAW,EACX,YAAY,EACZ,oBAAoB,EACpB,kBAAkB,EAClB,uBAAuB,EACvB,qBAAqB,EACrB,+BAA+B,EAC/B,cAAc,EACd,aAAa,EACb,iBAAiB,EACjB,GAAG,GACJ,EAAE,aAAa,EAChB,cAAc,EAAE,CAAC,MAAM,EAAE,MAAM,EAAE,SAAS,EAAE,cAAc,KAAK,IAAI;;;8BA0WlC,UAAU,CAAC,UAAU;6BAgBtB,UAAU,CAAC,UAAU;4BA0BtB,UAAU,CAAC,UAAU;qBA5G5B,MAAM,YAAY,cAAc;0BAJ3B,cAAc;0BAJd,cAAc;kCAiJN,YAAY;;EA0ClD;AAED,OAAO,EAAE,SAAS,EAAE,CAAA"}
|
package/dist/hooks/useOffset.jsx
CHANGED
|
@@ -52,7 +52,7 @@ function useOffset({ loop, duration, size, spaceBetween, easing, dataCount, init
|
|
|
52
52
|
}
|
|
53
53
|
function setOffset(offset) {
|
|
54
54
|
'main thread';
|
|
55
|
-
if (isNaN(offset)) throw new Error('calcBounceOffset: invalid offset');
|
|
55
|
+
if (Number.isNaN(offset)) throw new Error('calcBounceOffset: invalid offset');
|
|
56
56
|
offsetRef.current = offset;
|
|
57
57
|
prevIndexRef.current = getCurrentIndex();
|
|
58
58
|
onOffsetUpdate(offset, directionRef.current);
|
|
@@ -324,7 +324,7 @@ function useOffset({ loop, duration, size, spaceBetween, easing, dataCount, init
|
|
|
324
324
|
});
|
|
325
325
|
else {
|
|
326
326
|
const currentIndex = prevIndexRef.current;
|
|
327
|
-
isNaN(currentIndex) ? swipeToMTS(0, {
|
|
327
|
+
Number.isNaN(currentIndex) ? swipeToMTS(0, {
|
|
328
328
|
animate: false
|
|
329
329
|
}) : swipeToMTS(currentIndex, {
|
|
330
330
|
animate: false
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hooks/useOffset.jsx","sources":["../../src/hooks/useOffset.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 {\n runOnBackground,\n runOnMainThread,\n useMainThreadRef,\n} from '@lynx-js/react'\n\nimport { useTapLock } from '@lynx-js/react-use'\nimport type { MainThread } from '@lynx-js/types'\n\nimport { limiter, normalizeLoopOffset, normalizeLoopTransition } from '../utils'\nimport { useAnimate } from './useAnimate'\nimport { useAutoplay } from './useAutoPlay'\nimport { useAxisLock } from './useAxisLock'\nimport { useSwipeCallback } from './useSwipeCallback'\nimport { useVelocity } from './useVelocity'\nimport { SwipeDirection } from '../types'\nimport type {\n BounceConfig,\n CompoundModeConfig,\n OffsetLimitResult,\n ResetOptions,\n SwipeToOptions,\n SwiperProps,\n onBounceParams,\n} from '../types'\nimport { useDirection } from './useDirection'\n\ninterface UseOffsetOpts extends\n Required<\n Pick<\n SwiperProps<unknown>,\n | 'loop'\n | 'duration'\n | 'initialIndex'\n | 'containerWidth'\n | 'autoPlay'\n | 'autoPlayInterval'\n | 'consumeSlideEvent'\n | 'RTL'\n >\n >\n{\n dataCount: number\n size: number\n spaceBetween: number\n easing: NonNullable<SwiperProps<unknown>['main-thread:easing']>\n modeConfig: CompoundModeConfig\n enableBounce: boolean\n startBounceItemWidth: NonNullable<BounceConfig['startBounceItemWidth']>\n endBounceItemWidth: NonNullable<BounceConfig['endBounceItemWidth']>\n onStartBounceItemBounce: BounceConfig['onStartBounceItemBounce']\n onEndBounceItemBounce: BounceConfig['onStartBounceItemBounce']\n experimentalHorizontalSwipeOnly: boolean\n onSwipeStopMT: () => void\n onSwipeStartMT: () => void\n offsetLimit: OffsetLimitResult\n}\n\n// TODO(@wangyang.ryan) Use Function from utils.\n// MTS imported from other files has bug now.\nfunction customRound(num: number, threshold = 0.5) {\n 'main thread'\n const decimal = num - Math.floor(num)\n\n // Check if the decimal part is greater than or equal to 0.9\n if (decimal >= threshold) {\n return Math.ceil(num)\n } else {\n return Math.floor(num)\n }\n}\n\nfunction rubberEffect(rubberDelta: number, bounceWidth: number): number {\n 'main thread'\n\n if (rubberDelta === 0 || bounceWidth === 0) {\n return 0\n }\n\n // Assumes the bounce should max out when the user swipes 2x the bounceWidth.\n const swipeLimit = bounceWidth * 2.0\n const scaleFactor = 1.5 // (2.0 + 1.0) / 2.0\n\n const absDelta = Math.abs(rubberDelta)\n const effectiveDelta = Math.min(absDelta, swipeLimit)\n\n const bounce = effectiveDelta / (effectiveDelta / bounceWidth + 1.0)\n\n return Math.sign(rubberDelta) * bounce * scaleFactor\n}\n\n/**\n * This hook are used to maintain a virtual offset, which does not necessarily reflect the actual\n * location of the swiper\n */\nfunction useOffset(\n {\n loop,\n duration,\n size,\n spaceBetween,\n easing,\n dataCount,\n initialIndex,\n autoPlay,\n autoPlayInterval,\n offsetLimit,\n enableBounce,\n startBounceItemWidth,\n endBounceItemWidth,\n onStartBounceItemBounce,\n onEndBounceItemBounce,\n experimentalHorizontalSwipeOnly,\n onSwipeStartMT,\n onSwipeStopMT,\n consumeSlideEvent,\n RTL,\n }: UseOffsetOpts,\n onOffsetUpdate: (offset: number, direction: SwipeDirection) => void,\n) {\n // fullSize contains size and spaceBetween\n const fullSize = size + spaceBetween\n function getInitialOffset() {\n return limiter(\n -fullSize * initialIndex,\n dataCount,\n size,\n spaceBetween,\n loop,\n offsetLimit,\n )\n }\n\n const touchStartRef = useMainThreadRef<number>(0)\n const touchStartCrossAxisRef = useMainThreadRef<number>(0)\n const lastScrollOffsetRef = useMainThreadRef<number>(getInitialOffset())\n const offsetRef = useMainThreadRef<number>(getInitialOffset())\n // To record the previous index before offset change\n const prevIndexRef = useMainThreadRef<number>(initialIndex)\n const { velocityTouchMove, velocityTouchStart, getVelocity } = useVelocity({\n RTL,\n })\n const { cancel: cancelAnimation, animate } = useAnimate()\n\n const reachedBounceRef = useMainThreadRef(false)\n const bounceDeltaRef = useMainThreadRef(0)\n\n const {\n directionRef,\n handleTouchStart: directionTouchStart,\n handleTouchMove: directionTouchMove,\n handleTouchEnd: directionTouchEnd,\n overrideDirection,\n } = useDirection({\n RTL,\n })\n\n function getCurrentIndex() {\n 'main thread'\n // Guard against dataCount=0 to prevent NaN from modulo by zero\n if (dataCount === 0) {\n return 0\n }\n const totalWidth = fullSize * dataCount\n const currentIndex = ((-offsetRef.current + totalWidth) % totalWidth)\n / fullSize\n return currentIndex\n }\n\n // Offset should only be updated by this function.\n function setOffset(offset: number) {\n 'main thread'\n if (isNaN(offset)) {\n throw new Error('calcBounceOffset: invalid offset')\n }\n offsetRef.current = offset\n prevIndexRef.current = getCurrentIndex()\n onOffsetUpdate(offset, directionRef.current)\n }\n\n function calcLimitCompact(offset: number, options?: {\n type: 'prev' | 'next'\n }): {\n offset: number\n reachingLimit: -1 | 0 | 1\n } {\n 'main thread'\n let reachingLimit: -1 | 0 | 1 = 0\n let finalOffset = offset\n if (dataCount === 0) {\n if (options?.type === 'prev') {\n return { offset: 0, reachingLimit: -1 }\n }\n return { offset: 0, reachingLimit: 1 }\n }\n if (!loop) {\n if (offset >= -offsetLimit.startLimit) {\n reachingLimit = -1\n finalOffset = -offsetLimit.startLimit\n } else if (offset <= -fullSize * (dataCount - 1) + offsetLimit.endLimit) {\n reachingLimit = 1\n finalOffset = -fullSize * (dataCount - 1) + offsetLimit.endLimit\n }\n }\n return { offset: finalOffset, reachingLimit }\n }\n\n function calcBounceOffsetAndLimit(offset: number) {\n 'main thread'\n const { offset: limitOffset, reachingLimit } = calcLimitCompact(offset)\n\n if (enableBounce && reachingLimit) {\n const bounceDelta = offset - limitOffset\n const bounceItemWidth = reachingLimit === -1\n ? startBounceItemWidth\n : (offsetLimit.isNotEnoughForScreen ? 0 : endBounceItemWidth)\n reachedBounceRef.current = true\n bounceDeltaRef.current = rubberEffect(bounceDelta, bounceItemWidth)\n return limitOffset + bounceDeltaRef.current\n }\n return limitOffset\n }\n\n // We use rounding as threshold of when will the swiper to apply paging.\n // When rounding is 0.7, then index 1.6 will be paged to 1, and 1.8 will be paged to 2\n function calcPaging(offset: number, rounding = 0.5) {\n 'main thread'\n const { offset: limitOffset, reachingLimit } = calcLimitCompact(offset)\n if (reachingLimit) {\n return limitOffset\n }\n\n return customRound(-offset / fullSize, rounding) * -fullSize\n }\n\n function calcLoop(start: number, end: number) {\n 'main thread'\n if (dataCount === 0) {\n return { offset: 0, finalOffset: 0 }\n }\n\n if (!loop) {\n return { offset: start, finalOffset: end }\n }\n\n return normalizeLoopTransition(start, end, fullSize * dataCount)\n }\n\n const {\n handleTouchMove: swipeCallbackTouchMove,\n handleTouchStart: swipeCallbackTouchStart,\n setSwipeEndMT,\n setSwipeStartMT,\n } = useSwipeCallback({\n onSwipeStartMT,\n onSwipeStopMT,\n })\n\n const {\n handleTouchStart: axisLockTouchStart,\n handleTouchMove: axisLockTouchMove,\n handleTouchEnd: axisLockTouchEnd,\n handleVelocity: axisLockVelocity,\n } = useAxisLock({\n consumeSlideEvent,\n experimentalHorizontalSwipeOnly,\n })\n\n const {\n handleTouchStart: tapLockTouchStart,\n handleTouchMove: tapLockTouchMove,\n handleTouchEnd: tapLockTouchEnd,\n } = useTapLock()\n\n function easingTo(start: number, end: number, onFinished?: () => void) {\n 'main thread'\n function onProgress(progress: number) {\n const interpolatedProgress = easing(progress / 100)\n const animeOffset = (end - start) * interpolatedProgress + start\n\n setOffset(animeOffset)\n }\n\n animate(duration, onProgress, onFinished)\n }\n\n function hasNextMTS() {\n 'main thread'\n const offset = offsetRef.current\n const { reachingLimit } = calcLimitCompact(offset)\n\n return reachingLimit !== 1\n }\n\n function hasPrevMTS() {\n 'main thread'\n const offset = offsetRef.current\n const { reachingLimit } = calcLimitCompact(offset)\n\n return reachingLimit !== -1\n }\n\n function swipeToMTS(index: number, options?: SwipeToOptions) {\n 'main thread'\n if (dataCount === 0) {\n setSwipeEndMT()\n return\n }\n\n const finalIndex = Math.max(Math.min(index, dataCount - 1), 0)\n const currentIndex = getCurrentIndex()\n const { offset: finalOffset } = calcLimitCompact(-finalIndex * fullSize)\n setSwipeStartMT()\n\n if (finalIndex > currentIndex) {\n overrideDirection(SwipeDirection.NORMAL)\n } else if (finalIndex < currentIndex) {\n overrideDirection(SwipeDirection.REVERT)\n } else {\n overrideDirection(SwipeDirection.NONE)\n }\n\n if (options?.animate) {\n easingTo(offsetRef.current, finalOffset, () => {\n if (options?.onFinished) {\n options.onFinished()\n }\n setSwipeEndMT()\n })\n } else {\n setOffset(finalOffset)\n setSwipeEndMT()\n }\n }\n\n function swipeNextMTS(options?: SwipeToOptions) {\n 'main thread'\n\n if (!hasNextMTS()) {\n setSwipeEndMT()\n return\n }\n\n setSwipeStartMT()\n let offset = offsetRef.current\n let finalOffset = calcPaging(offset - fullSize, 0.95)\n\n if (loop) {\n const result = calcLoop(offset, finalOffset)\n offset = result.offset\n finalOffset = result.finalOffset\n } else {\n const result = calcLimitCompact(finalOffset)\n finalOffset = result.offset\n }\n\n overrideDirection(SwipeDirection.NORMAL)\n\n if (options?.animate === false) {\n setOffset(finalOffset)\n setSwipeEndMT()\n } else {\n easingTo(offset, finalOffset, () => {\n if (options?.onFinished) {\n options.onFinished()\n }\n setSwipeEndMT()\n })\n }\n }\n\n function swipePrevMTS(options?: SwipeToOptions) {\n 'main thread'\n\n if (!hasPrevMTS()) {\n setSwipeEndMT()\n return\n }\n\n setSwipeStartMT()\n let offset = offsetRef.current\n let finalOffset = calcPaging(offset + fullSize, 0.05)\n if (loop) {\n const result = calcLoop(offset, finalOffset)\n offset = result.offset\n finalOffset = result.finalOffset\n } else {\n const result = calcLimitCompact(finalOffset)\n finalOffset = result.offset\n }\n\n overrideDirection(SwipeDirection.REVERT)\n\n if (options?.animate === false) {\n setOffset(finalOffset)\n setSwipeEndMT()\n } else {\n easingTo(offset, finalOffset, () => {\n if (options?.onFinished) {\n options.onFinished()\n }\n setSwipeEndMT()\n })\n }\n }\n\n function swipePrev(options?: SwipeToOptions) {\n runOnMainThread(swipePrevMTS)(options)\n }\n\n function swipeNext(options?: SwipeToOptions) {\n runOnMainThread(swipeNextMTS)(options)\n }\n\n function swipeTo(index: number, options?: SwipeToOptions) {\n runOnMainThread(swipeToMTS)(index, options)\n }\n\n function handleOnBounce(params: onBounceParams) {\n if (params.type === 'start' && onStartBounceItemBounce) {\n onStartBounceItemBounce(params)\n } else if (params.type === 'end' && onEndBounceItemBounce) {\n onEndBounceItemBounce(params)\n }\n }\n\n function handleBounceCallback(offset: number) {\n 'main thread'\n if (reachedBounceRef.current) {\n runOnBackground(handleOnBounce)({\n type: offset > 0 ? 'start' : 'end',\n offset: Math.abs(bounceDeltaRef.current),\n })\n reachedBounceRef.current = false\n bounceDeltaRef.current = 0\n }\n }\n\n const {\n pauseMT: pauseAutoPlayMT,\n startMT: startAutoPlayMT,\n } = useAutoplay({\n autoPlay,\n autoPlayInterval,\n prevMT: swipePrevMTS,\n nextMT: swipeNextMTS,\n duration,\n dataCount,\n })\n\n function handleVelocity() {\n 'main thread'\n const VELOCITY_THRESHOLD = 300\n\n if (axisLockVelocity()) {\n return false\n }\n\n const { velocity: velocityValue, direction } = getVelocity()\n if (Math.abs(velocityValue) > VELOCITY_THRESHOLD) {\n overrideDirection(direction)\n if (direction === SwipeDirection.NORMAL && hasNextMTS()) {\n swipeNextMTS({\n onFinished: () => {\n startAutoPlayMT()\n },\n })\n return true\n } else if (direction === SwipeDirection.REVERT && hasPrevMTS()) {\n swipePrevMTS({\n onFinished: () => {\n startAutoPlayMT()\n },\n })\n return true\n }\n }\n return false\n }\n\n function handleTouchStart(event: MainThread.TouchEvent) {\n 'main thread'\n lastScrollOffsetRef.current = offsetRef.current\n\n touchStartRef.current = event.detail.x\n\n touchStartCrossAxisRef.current = event.detail.y\n axisLockTouchStart(event)\n velocityTouchStart()\n tapLockTouchStart(event)\n cancelAnimation()\n swipeCallbackTouchStart(event)\n directionTouchStart(event)\n pauseAutoPlayMT()\n }\n\n function handleTouchMove(event: MainThread.TouchEvent) {\n 'main thread'\n\n // Guard against empty data to prevent state corruption\n if (dataCount === 0) {\n return\n }\n\n if (axisLockTouchMove(event) || tapLockTouchMove(event)) {\n return\n }\n\n const sign = RTL ? -1 : 1\n\n let offsetInner = sign * (event.detail.x - touchStartRef.current)\n + lastScrollOffsetRef.current\n offsetInner = calcBounceOffsetAndLimit(offsetInner)\n if (loop) {\n offsetInner = normalizeLoopOffset(offsetInner, fullSize * dataCount)\n }\n setOffset(offsetInner)\n velocityTouchMove(event)\n swipeCallbackTouchMove(event)\n directionTouchMove(event)\n }\n\n function handleTouchEnd(event: MainThread.TouchEvent) {\n 'main thread'\n let offset = offsetRef.current\n\n handleBounceCallback(offset)\n\n if (handleVelocity()) {\n return\n }\n axisLockTouchEnd()\n directionTouchEnd(event)\n\n let finalOffset = calcPaging(offset)\n if (loop) {\n const result = calcLoop(offset, finalOffset)\n offset = result.offset\n finalOffset = result.finalOffset\n } else {\n const result = calcLimitCompact(finalOffset)\n finalOffset = result.offset\n }\n\n tapLockTouchEnd(event)\n easingTo(offset, finalOffset, () => {\n setSwipeEndMT()\n startAutoPlayMT()\n })\n }\n\n function resetOffsetMT(resetOptions: ResetOptions) {\n 'main thread'\n cancelAnimation()\n if (dataCount === 0) {\n swipeToMTS(0)\n return\n }\n if (resetOptions.fullReset) {\n swipeToMTS(resetOptions.resetIndex!, {\n animate: false,\n })\n } else {\n const currentIndex = prevIndexRef.current\n // Guard against NaN from previous empty data state\n if (isNaN(currentIndex)) {\n swipeToMTS(0, {\n animate: false,\n })\n } else {\n swipeToMTS(currentIndex, {\n animate: false,\n })\n }\n }\n }\n\n function cancelAnimationJS() {\n runOnMainThread(cancelAnimation)()\n }\n\n return {\n startAutoPlayMT,\n offsetRef,\n handleTouchStart,\n handleTouchMove,\n handleTouchEnd,\n swipeTo,\n swipeNext,\n swipePrev,\n resetOffsetMT,\n cancelAnimationJS,\n }\n}\n\nexport { useOffset }\n"],"names":["customRound","num","threshold","decimal","Math","rubberEffect","rubberDelta","bounceWidth","swipeLimit","scaleFactor","absDelta","effectiveDelta","bounce","useOffset","loop","duration","size","spaceBetween","easing","dataCount","initialIndex","autoPlay","autoPlayInterval","offsetLimit","enableBounce","startBounceItemWidth","endBounceItemWidth","onStartBounceItemBounce","onEndBounceItemBounce","experimentalHorizontalSwipeOnly","onSwipeStartMT","onSwipeStopMT","consumeSlideEvent","RTL","onOffsetUpdate","fullSize","getInitialOffset","limiter","touchStartRef","useMainThreadRef","touchStartCrossAxisRef","lastScrollOffsetRef","offsetRef","prevIndexRef","velocityTouchMove","velocityTouchStart","getVelocity","useVelocity","cancelAnimation","animate","useAnimate","reachedBounceRef","bounceDeltaRef","directionRef","directionTouchStart","directionTouchMove","directionTouchEnd","overrideDirection","useDirection","getCurrentIndex","totalWidth","currentIndex","setOffset","offset","isNaN","Error","calcLimitCompact","options","reachingLimit","finalOffset","calcBounceOffsetAndLimit","limitOffset","bounceDelta","bounceItemWidth","calcPaging","rounding","calcLoop","start","end","normalizeLoopTransition","swipeCallbackTouchMove","swipeCallbackTouchStart","setSwipeEndMT","setSwipeStartMT","useSwipeCallback","axisLockTouchStart","axisLockTouchMove","axisLockTouchEnd","axisLockVelocity","useAxisLock","tapLockTouchStart","tapLockTouchMove","tapLockTouchEnd","useTapLock","easingTo","onFinished","onProgress","progress","interpolatedProgress","animeOffset","hasNextMTS","hasPrevMTS","swipeToMTS","index","finalIndex","SwipeDirection","swipeNextMTS","result","swipePrevMTS","swipePrev","runOnMainThread","swipeNext","swipeTo","handleOnBounce","params","handleBounceCallback","runOnBackground","pauseAutoPlayMT","startAutoPlayMT","useAutoplay","handleVelocity","VELOCITY_THRESHOLD","velocityValue","direction","handleTouchStart","event","handleTouchMove","sign","offsetInner","normalizeLoopOffset","handleTouchEnd","resetOffsetMT","resetOptions","cancelAnimationJS"],"mappings":";;;;;;;;;;AAgEA,SAASA,YAAYC,GAAW,EAAEC,YAAY,GAAG;IAC/C;IACA,MAAMC,UAAUF,MAAMG,KAAK,KAAK,CAACH;IAGjC,IAAIE,WAAWD,WACb,OAAOE,KAAK,IAAI,CAACH;IAEjB,OAAOG,KAAK,KAAK,CAACH;AAEtB;AAEA,SAASI,aAAaC,WAAmB,EAAEC,WAAmB;IAC5D;IAEA,IAAID,AAAgB,MAAhBA,eAAqBC,AAAgB,MAAhBA,aACvB,OAAO;IAIT,MAAMC,aAAaD,AAAc,MAAdA;IACnB,MAAME,cAAc;IAEpB,MAAMC,WAAWN,KAAK,GAAG,CAACE;IAC1B,MAAMK,iBAAiBP,KAAK,GAAG,CAACM,UAAUF;IAE1C,MAAMI,SAASD,iBAAkBA,CAAAA,iBAAiBJ,cAAc,GAAE;IAElE,OAAOH,KAAK,IAAI,CAACE,eAAeM,SAASH;AAC3C;AAMA,SAASI,UACP,EACEC,IAAI,EACJC,QAAQ,EACRC,IAAI,EACJC,YAAY,EACZC,MAAM,EACNC,SAAS,EACTC,YAAY,EACZC,QAAQ,EACRC,gBAAgB,EAChBC,WAAW,EACXC,YAAY,EACZC,oBAAoB,EACpBC,kBAAkB,EAClBC,uBAAuB,EACvBC,qBAAqB,EACrBC,+BAA+B,EAC/BC,cAAc,EACdC,aAAa,EACbC,iBAAiB,EACjBC,GAAG,EACW,EAChBC,cAAmE;IAGnE,MAAMC,WAAWnB,OAAOC;IACxB,SAASmB;QACP,OAAOC,QACL,CAACF,WAAWf,cACZD,WACAH,MACAC,cACAH,MACAS;IAEJ;IAEA,MAAMe,gBAAgBC,iBAAyB;IAC/C,MAAMC,yBAAyBD,iBAAyB;IACxD,MAAME,sBAAsBF,iBAAyBH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AI;QACAlB;QACAD;QACAF;QACAsB;QACAE;IACF;AACF"}
|
|
1
|
+
{"version":3,"file":"hooks/useOffset.jsx","sources":["../../src/hooks/useOffset.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 {\n runOnBackground,\n runOnMainThread,\n useMainThreadRef,\n} from '@lynx-js/react'\n\nimport { useTapLock } from '@lynx-js/react-use'\nimport type { MainThread } from '@lynx-js/types'\n\nimport { limiter, normalizeLoopOffset, normalizeLoopTransition } from '../utils'\nimport { useAnimate } from './useAnimate'\nimport { useAutoplay } from './useAutoPlay'\nimport { useAxisLock } from './useAxisLock'\nimport { useSwipeCallback } from './useSwipeCallback'\nimport { useVelocity } from './useVelocity'\nimport { SwipeDirection } from '../types'\nimport type {\n BounceConfig,\n CompoundModeConfig,\n OffsetLimitResult,\n OnBounceParams,\n ResetOptions,\n SwipeToOptions,\n SwiperProps,\n} from '../types'\nimport { useDirection } from './useDirection'\n\ninterface UseOffsetOpts extends\n Required<\n Pick<\n SwiperProps<unknown>,\n | 'loop'\n | 'duration'\n | 'initialIndex'\n | 'containerWidth'\n | 'autoPlay'\n | 'autoPlayInterval'\n | 'consumeSlideEvent'\n | 'RTL'\n >\n >\n{\n dataCount: number\n size: number\n spaceBetween: number\n easing: NonNullable<SwiperProps<unknown>['main-thread:easing']>\n modeConfig: CompoundModeConfig\n enableBounce: boolean\n startBounceItemWidth: NonNullable<BounceConfig['startBounceItemWidth']>\n endBounceItemWidth: NonNullable<BounceConfig['endBounceItemWidth']>\n onStartBounceItemBounce: BounceConfig['onStartBounceItemBounce']\n onEndBounceItemBounce: BounceConfig['onStartBounceItemBounce']\n experimentalHorizontalSwipeOnly: boolean\n onSwipeStopMT: () => void\n onSwipeStartMT: () => void\n offsetLimit: OffsetLimitResult\n}\n\n// TODO(@wangyang.ryan) Use Function from utils.\n// MTS imported from other files has bug now.\nfunction customRound(num: number, threshold = 0.5) {\n 'main thread'\n const decimal = num - Math.floor(num)\n\n // Check if the decimal part is greater than or equal to 0.9\n if (decimal >= threshold) {\n return Math.ceil(num)\n } else {\n return Math.floor(num)\n }\n}\n\nfunction rubberEffect(rubberDelta: number, bounceWidth: number): number {\n 'main thread'\n\n if (rubberDelta === 0 || bounceWidth === 0) {\n return 0\n }\n\n // Assumes the bounce should max out when the user swipes 2x the bounceWidth.\n const swipeLimit = bounceWidth * 2.0\n const scaleFactor = 1.5 // (2.0 + 1.0) / 2.0\n\n const absDelta = Math.abs(rubberDelta)\n const effectiveDelta = Math.min(absDelta, swipeLimit)\n\n const bounce = effectiveDelta / (effectiveDelta / bounceWidth + 1.0)\n\n return Math.sign(rubberDelta) * bounce * scaleFactor\n}\n\n/**\n * This hook are used to maintain a virtual offset, which does not necessarily reflect the actual\n * location of the swiper\n */\nfunction useOffset(\n {\n loop,\n duration,\n size,\n spaceBetween,\n easing,\n dataCount,\n initialIndex,\n autoPlay,\n autoPlayInterval,\n offsetLimit,\n enableBounce,\n startBounceItemWidth,\n endBounceItemWidth,\n onStartBounceItemBounce,\n onEndBounceItemBounce,\n experimentalHorizontalSwipeOnly,\n onSwipeStartMT,\n onSwipeStopMT,\n consumeSlideEvent,\n RTL,\n }: UseOffsetOpts,\n onOffsetUpdate: (offset: number, direction: SwipeDirection) => void,\n) {\n // fullSize contains size and spaceBetween\n const fullSize = size + spaceBetween\n function getInitialOffset() {\n return limiter(\n -fullSize * initialIndex,\n dataCount,\n size,\n spaceBetween,\n loop,\n offsetLimit,\n )\n }\n\n const touchStartRef = useMainThreadRef<number>(0)\n const touchStartCrossAxisRef = useMainThreadRef<number>(0)\n const lastScrollOffsetRef = useMainThreadRef<number>(getInitialOffset())\n const offsetRef = useMainThreadRef<number>(getInitialOffset())\n // To record the previous index before offset change\n const prevIndexRef = useMainThreadRef<number>(initialIndex)\n const { velocityTouchMove, velocityTouchStart, getVelocity } = useVelocity({\n RTL,\n })\n const { cancel: cancelAnimation, animate } = useAnimate()\n\n const reachedBounceRef = useMainThreadRef(false)\n const bounceDeltaRef = useMainThreadRef(0)\n\n const {\n directionRef,\n handleTouchStart: directionTouchStart,\n handleTouchMove: directionTouchMove,\n handleTouchEnd: directionTouchEnd,\n overrideDirection,\n } = useDirection({\n RTL,\n })\n\n function getCurrentIndex() {\n 'main thread'\n // Guard against dataCount=0 to prevent NaN from modulo by zero\n if (dataCount === 0) {\n return 0\n }\n const totalWidth = fullSize * dataCount\n const currentIndex = ((-offsetRef.current + totalWidth) % totalWidth)\n / fullSize\n return currentIndex\n }\n\n // Offset should only be updated by this function.\n function setOffset(offset: number) {\n 'main thread'\n if (Number.isNaN(offset)) {\n throw new Error('calcBounceOffset: invalid offset')\n }\n offsetRef.current = offset\n prevIndexRef.current = getCurrentIndex()\n onOffsetUpdate(offset, directionRef.current)\n }\n\n function calcLimitCompact(offset: number, options?: {\n type: 'prev' | 'next'\n }): {\n offset: number\n reachingLimit: -1 | 0 | 1\n } {\n 'main thread'\n let reachingLimit: -1 | 0 | 1 = 0\n let finalOffset = offset\n if (dataCount === 0) {\n if (options?.type === 'prev') {\n return { offset: 0, reachingLimit: -1 }\n }\n return { offset: 0, reachingLimit: 1 }\n }\n if (!loop) {\n if (offset >= -offsetLimit.startLimit) {\n reachingLimit = -1\n finalOffset = -offsetLimit.startLimit\n } else if (offset <= -fullSize * (dataCount - 1) + offsetLimit.endLimit) {\n reachingLimit = 1\n finalOffset = -fullSize * (dataCount - 1) + offsetLimit.endLimit\n }\n }\n return { offset: finalOffset, reachingLimit }\n }\n\n function calcBounceOffsetAndLimit(offset: number) {\n 'main thread'\n const { offset: limitOffset, reachingLimit } = calcLimitCompact(offset)\n\n if (enableBounce && reachingLimit) {\n const bounceDelta = offset - limitOffset\n const bounceItemWidth = reachingLimit === -1\n ? startBounceItemWidth\n : (offsetLimit.isNotEnoughForScreen ? 0 : endBounceItemWidth)\n reachedBounceRef.current = true\n bounceDeltaRef.current = rubberEffect(bounceDelta, bounceItemWidth)\n return limitOffset + bounceDeltaRef.current\n }\n return limitOffset\n }\n\n // We use rounding as threshold of when will the swiper to apply paging.\n // When rounding is 0.7, then index 1.6 will be paged to 1, and 1.8 will be paged to 2\n function calcPaging(offset: number, rounding = 0.5) {\n 'main thread'\n const { offset: limitOffset, reachingLimit } = calcLimitCompact(offset)\n if (reachingLimit) {\n return limitOffset\n }\n\n return customRound(-offset / fullSize, rounding) * -fullSize\n }\n\n function calcLoop(start: number, end: number) {\n 'main thread'\n if (dataCount === 0) {\n return { offset: 0, finalOffset: 0 }\n }\n\n if (!loop) {\n return { offset: start, finalOffset: end }\n }\n\n return normalizeLoopTransition(start, end, fullSize * dataCount)\n }\n\n const {\n handleTouchMove: swipeCallbackTouchMove,\n handleTouchStart: swipeCallbackTouchStart,\n setSwipeEndMT,\n setSwipeStartMT,\n } = useSwipeCallback({\n onSwipeStartMT,\n onSwipeStopMT,\n })\n\n const {\n handleTouchStart: axisLockTouchStart,\n handleTouchMove: axisLockTouchMove,\n handleTouchEnd: axisLockTouchEnd,\n handleVelocity: axisLockVelocity,\n } = useAxisLock({\n consumeSlideEvent,\n experimentalHorizontalSwipeOnly,\n })\n\n const {\n handleTouchStart: tapLockTouchStart,\n handleTouchMove: tapLockTouchMove,\n handleTouchEnd: tapLockTouchEnd,\n } = useTapLock()\n\n function easingTo(start: number, end: number, onFinished?: () => void) {\n 'main thread'\n function onProgress(progress: number) {\n const interpolatedProgress = easing(progress / 100)\n const animeOffset = (end - start) * interpolatedProgress + start\n\n setOffset(animeOffset)\n }\n\n animate(duration, onProgress, onFinished)\n }\n\n function hasNextMTS() {\n 'main thread'\n const offset = offsetRef.current\n const { reachingLimit } = calcLimitCompact(offset)\n\n return reachingLimit !== 1\n }\n\n function hasPrevMTS() {\n 'main thread'\n const offset = offsetRef.current\n const { reachingLimit } = calcLimitCompact(offset)\n\n return reachingLimit !== -1\n }\n\n function swipeToMTS(index: number, options?: SwipeToOptions) {\n 'main thread'\n if (dataCount === 0) {\n setSwipeEndMT()\n return\n }\n\n const finalIndex = Math.max(Math.min(index, dataCount - 1), 0)\n const currentIndex = getCurrentIndex()\n const { offset: finalOffset } = calcLimitCompact(-finalIndex * fullSize)\n setSwipeStartMT()\n\n if (finalIndex > currentIndex) {\n overrideDirection(SwipeDirection.NORMAL)\n } else if (finalIndex < currentIndex) {\n overrideDirection(SwipeDirection.REVERT)\n } else {\n overrideDirection(SwipeDirection.NONE)\n }\n\n if (options?.animate) {\n easingTo(offsetRef.current, finalOffset, () => {\n if (options?.onFinished) {\n options.onFinished()\n }\n setSwipeEndMT()\n })\n } else {\n setOffset(finalOffset)\n setSwipeEndMT()\n }\n }\n\n function swipeNextMTS(options?: SwipeToOptions) {\n 'main thread'\n\n if (!hasNextMTS()) {\n setSwipeEndMT()\n return\n }\n\n setSwipeStartMT()\n let offset = offsetRef.current\n let finalOffset = calcPaging(offset - fullSize, 0.95)\n\n if (loop) {\n const result = calcLoop(offset, finalOffset)\n offset = result.offset\n finalOffset = result.finalOffset\n } else {\n const result = calcLimitCompact(finalOffset)\n finalOffset = result.offset\n }\n\n overrideDirection(SwipeDirection.NORMAL)\n\n if (options?.animate === false) {\n setOffset(finalOffset)\n setSwipeEndMT()\n } else {\n easingTo(offset, finalOffset, () => {\n if (options?.onFinished) {\n options.onFinished()\n }\n setSwipeEndMT()\n })\n }\n }\n\n function swipePrevMTS(options?: SwipeToOptions) {\n 'main thread'\n\n if (!hasPrevMTS()) {\n setSwipeEndMT()\n return\n }\n\n setSwipeStartMT()\n let offset = offsetRef.current\n let finalOffset = calcPaging(offset + fullSize, 0.05)\n if (loop) {\n const result = calcLoop(offset, finalOffset)\n offset = result.offset\n finalOffset = result.finalOffset\n } else {\n const result = calcLimitCompact(finalOffset)\n finalOffset = result.offset\n }\n\n overrideDirection(SwipeDirection.REVERT)\n\n if (options?.animate === false) {\n setOffset(finalOffset)\n setSwipeEndMT()\n } else {\n easingTo(offset, finalOffset, () => {\n if (options?.onFinished) {\n options.onFinished()\n }\n setSwipeEndMT()\n })\n }\n }\n\n function swipePrev(options?: SwipeToOptions) {\n runOnMainThread(swipePrevMTS)(options)\n }\n\n function swipeNext(options?: SwipeToOptions) {\n runOnMainThread(swipeNextMTS)(options)\n }\n\n function swipeTo(index: number, options?: SwipeToOptions) {\n runOnMainThread(swipeToMTS)(index, options)\n }\n\n function handleOnBounce(params: OnBounceParams) {\n if (params.type === 'start' && onStartBounceItemBounce) {\n onStartBounceItemBounce(params)\n } else if (params.type === 'end' && onEndBounceItemBounce) {\n onEndBounceItemBounce(params)\n }\n }\n\n function handleBounceCallback(offset: number) {\n 'main thread'\n if (reachedBounceRef.current) {\n runOnBackground(handleOnBounce)({\n type: offset > 0 ? 'start' : 'end',\n offset: Math.abs(bounceDeltaRef.current),\n })\n reachedBounceRef.current = false\n bounceDeltaRef.current = 0\n }\n }\n\n const {\n pauseMT: pauseAutoPlayMT,\n startMT: startAutoPlayMT,\n } = useAutoplay({\n autoPlay,\n autoPlayInterval,\n prevMT: swipePrevMTS,\n nextMT: swipeNextMTS,\n duration,\n dataCount,\n })\n\n function handleVelocity() {\n 'main thread'\n const VELOCITY_THRESHOLD = 300\n\n if (axisLockVelocity()) {\n return false\n }\n\n const { velocity: velocityValue, direction } = getVelocity()\n if (Math.abs(velocityValue) > VELOCITY_THRESHOLD) {\n overrideDirection(direction)\n if (direction === SwipeDirection.NORMAL && hasNextMTS()) {\n swipeNextMTS({\n onFinished: () => {\n startAutoPlayMT()\n },\n })\n return true\n } else if (direction === SwipeDirection.REVERT && hasPrevMTS()) {\n swipePrevMTS({\n onFinished: () => {\n startAutoPlayMT()\n },\n })\n return true\n }\n }\n return false\n }\n\n function handleTouchStart(event: MainThread.TouchEvent) {\n 'main thread'\n lastScrollOffsetRef.current = offsetRef.current\n\n touchStartRef.current = event.detail.x\n\n touchStartCrossAxisRef.current = event.detail.y\n axisLockTouchStart(event)\n velocityTouchStart()\n tapLockTouchStart(event)\n cancelAnimation()\n swipeCallbackTouchStart(event)\n directionTouchStart(event)\n pauseAutoPlayMT()\n }\n\n function handleTouchMove(event: MainThread.TouchEvent) {\n 'main thread'\n\n // Guard against empty data to prevent state corruption\n if (dataCount === 0) {\n return\n }\n\n if (axisLockTouchMove(event) || tapLockTouchMove(event)) {\n return\n }\n\n const sign = RTL ? -1 : 1\n\n let offsetInner = sign * (event.detail.x - touchStartRef.current)\n + lastScrollOffsetRef.current\n offsetInner = calcBounceOffsetAndLimit(offsetInner)\n if (loop) {\n offsetInner = normalizeLoopOffset(offsetInner, fullSize * dataCount)\n }\n setOffset(offsetInner)\n velocityTouchMove(event)\n swipeCallbackTouchMove(event)\n directionTouchMove(event)\n }\n\n function handleTouchEnd(event: MainThread.TouchEvent) {\n 'main thread'\n let offset = offsetRef.current\n\n handleBounceCallback(offset)\n\n if (handleVelocity()) {\n return\n }\n axisLockTouchEnd()\n directionTouchEnd(event)\n\n let finalOffset = calcPaging(offset)\n if (loop) {\n const result = calcLoop(offset, finalOffset)\n offset = result.offset\n finalOffset = result.finalOffset\n } else {\n const result = calcLimitCompact(finalOffset)\n finalOffset = result.offset\n }\n\n tapLockTouchEnd(event)\n easingTo(offset, finalOffset, () => {\n setSwipeEndMT()\n startAutoPlayMT()\n })\n }\n\n function resetOffsetMT(resetOptions: ResetOptions) {\n 'main thread'\n cancelAnimation()\n if (dataCount === 0) {\n swipeToMTS(0)\n return\n }\n if (resetOptions.fullReset) {\n swipeToMTS(resetOptions.resetIndex!, {\n animate: false,\n })\n } else {\n const currentIndex = prevIndexRef.current\n // Guard against NaN from previous empty data state\n if (Number.isNaN(currentIndex)) {\n swipeToMTS(0, {\n animate: false,\n })\n } else {\n swipeToMTS(currentIndex, {\n animate: false,\n })\n }\n }\n }\n\n function cancelAnimationJS() {\n runOnMainThread(cancelAnimation)()\n }\n\n return {\n startAutoPlayMT,\n offsetRef,\n handleTouchStart,\n handleTouchMove,\n handleTouchEnd,\n swipeTo,\n swipeNext,\n swipePrev,\n resetOffsetMT,\n cancelAnimationJS,\n }\n}\n\nexport { useOffset }\n"],"names":["customRound","num","threshold","decimal","Math","rubberEffect","rubberDelta","bounceWidth","swipeLimit","scaleFactor","absDelta","effectiveDelta","bounce","useOffset","loop","duration","size","spaceBetween","easing","dataCount","initialIndex","autoPlay","autoPlayInterval","offsetLimit","enableBounce","startBounceItemWidth","endBounceItemWidth","onStartBounceItemBounce","onEndBounceItemBounce","experimentalHorizontalSwipeOnly","onSwipeStartMT","onSwipeStopMT","consumeSlideEvent","RTL","onOffsetUpdate","fullSize","getInitialOffset","limiter","touchStartRef","useMainThreadRef","touchStartCrossAxisRef","lastScrollOffsetRef","offsetRef","prevIndexRef","velocityTouchMove","velocityTouchStart","getVelocity","useVelocity","cancelAnimation","animate","useAnimate","reachedBounceRef","bounceDeltaRef","directionRef","directionTouchStart","directionTouchMove","directionTouchEnd","overrideDirection","useDirection","getCurrentIndex","totalWidth","currentIndex","setOffset","offset","Number","Error","calcLimitCompact","options","reachingLimit","finalOffset","calcBounceOffsetAndLimit","limitOffset","bounceDelta","bounceItemWidth","calcPaging","rounding","calcLoop","start","end","normalizeLoopTransition","swipeCallbackTouchMove","swipeCallbackTouchStart","setSwipeEndMT","setSwipeStartMT","useSwipeCallback","axisLockTouchStart","axisLockTouchMove","axisLockTouchEnd","axisLockVelocity","useAxisLock","tapLockTouchStart","tapLockTouchMove","tapLockTouchEnd","useTapLock","easingTo","onFinished","onProgress","progress","interpolatedProgress","animeOffset","hasNextMTS","hasPrevMTS","swipeToMTS","index","finalIndex","SwipeDirection","swipeNextMTS","result","swipePrevMTS","swipePrev","runOnMainThread","swipeNext","swipeTo","handleOnBounce","params","handleBounceCallback","runOnBackground","pauseAutoPlayMT","startAutoPlayMT","useAutoplay","handleVelocity","VELOCITY_THRESHOLD","velocityValue","direction","handleTouchStart","event","handleTouchMove","sign","offsetInner","normalizeLoopOffset","handleTouchEnd","resetOffsetMT","resetOptions","cancelAnimationJS"],"mappings":";;;;;;;;;;AAgEA,SAASA,YAA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AQF,CAAAA,MAAM,MAAM,CAAC,CAAC,GAAGvF,cAAc,OAAM,IAC3DG,oBAAoB,OAAO;QAC/BuF,cAAc1D,yBAAyB0D;QACvC,IAAIlH,MACFkH,cAAcC,oBAAoBD,aAAa7F,WAAWhB;QAE5D2C,UAAUkE;QACVpF,kBAAkBiF;QAClB7C,uBAAuB6C;QACvBtE,mBAAmBsE;IACrB;IAEA,SAASK,eAAeL,KAA4B;QAClD;QACA,IAAI9D,SAASrB,UAAU,OAAO;QAE9ByE,qBAAqBpD;QAErB,IAAIyD,kBACF;QAEFjC;QACA/B,kBAAkBqE;QAElB,IAAIxD,cAAcK,WAAWX;QAC7B,IAAIjD,MAAM;YACR,MAAM6F,SAAS/B,SAASb,QAAQM;YAChCN,SAAS4C,OAAO,MAAM;YACtBtC,cAAcsC,OAAO,WAAW;QAClC,OAAO;YACL,MAAMA,SAASzC,iBAAiBG;YAChCA,cAAcsC,OAAO,MAAM;QAC7B;QAEAf,gBAAgBiC;QAChB/B,SAAS/B,QAAQM,aAAa;YAC5Ba;YACAoC;QACF;IACF;IAEA,SAASa,cAAcC,YAA0B;QAC/C;QACApF;QACA,IAAI7B,AAAc,MAAdA,WAAiB,YACnBmF,WAAW;QAGb,IAAI8B,aAAa,SAAS,EACxB9B,WAAW8B,aAAa,UAAU,EAAG;YACnC,SAAS;QACX;aACK;YACL,MAAMvE,eAAelB,aAAa,OAAO;YAErCqB,OAAO,KAAK,CAACH,gBACfyC,WAAW,GAAG;gBACZ,SAAS;YACX,KAEAA,WAAWzC,cAAc;gBACvB,SAAS;YACX;QAEJ;IACF;IAEA,SAASwE;QACPvB,gBAAgB9D;IAClB;IAEA,OAAO;QACLsE;QACA5E;QACAkF;QACAE;QACAI;QACAlB;QACAD;QACAF;QACAsB;QACAE;IACF;AACF"}
|
package/dist/types/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { CSSProperties, MainThread } from '@lynx-js/types';
|
|
2
|
-
import type { BounceConfig, SwipeToOptions, SwiperPropsReal as SwiperProps, SwiperRef
|
|
2
|
+
import type { BounceConfig, OnBounceParams, SwipeToOptions, SwiperPropsReal as SwiperProps, SwiperRef } from './index.docs.js';
|
|
3
3
|
export interface SwiperContextProps extends Pick<SwiperProps<unknown>, 'itemWidth' | 'itemHeight' | 'customAnimationFirstScreen' | 'RTL'>, Required<Pick<SwiperProps<unknown>, 'initialIndex' | 'loop'>> {
|
|
4
4
|
setChildrenRef: (ref: MainThread.Element, index: number) => void;
|
|
5
5
|
spaceBetween: number;
|
|
@@ -13,7 +13,7 @@ export interface CompoundCustomModeConfig {
|
|
|
13
13
|
mode: 'custom';
|
|
14
14
|
}
|
|
15
15
|
export type CompoundModeConfig = CompoundNormalModeConfig | CompoundCustomModeConfig;
|
|
16
|
-
export type
|
|
16
|
+
export type CustomAnimation = (progress: number, props: SwiperProps<unknown>) => CSSProperties;
|
|
17
17
|
export interface CustomTouch {
|
|
18
18
|
identifier: number;
|
|
19
19
|
pageX: number;
|
|
@@ -58,5 +58,5 @@ export interface OffsetLimitResult {
|
|
|
58
58
|
endLimit: number;
|
|
59
59
|
isNotEnoughForScreen: boolean;
|
|
60
60
|
}
|
|
61
|
-
export type { BounceConfig,
|
|
61
|
+
export type { BounceConfig, OnBounceParams, SwiperRef, SwipeToOptions, SwiperProps, };
|
|
62
62
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/types/index.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,aAAa,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAA;AAE/D,OAAO,KAAK,EACV,YAAY,EACZ,cAAc,EACd,eAAe,IAAI,WAAW,EAC9B,SAAS,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/types/index.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,aAAa,EAAE,UAAU,EAAE,MA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EAAE,CAAC,EAAE,GAAG,EAAE,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,KAAK,KAAK,CAAC,YAAY,GAAG,IAAI,GACjE,CAAC,KAAK,EAAE,CAAC,GAAG,KAAK,CAAC,aAAa,CAAC,CAAC,CAAC,KAAK,KAAK,CAAC,YAAY,GAAG,IAAI,CAAA;CACpE;AAED,OAAO,QAAQ,gBAAgB,CAAC;IAC9B,UAAU,WAAW;QACnB,WAAW,EAAE,MAAM,CAAA;KACpB;CACF;AAED,MAAM,WAAW,YAAY;IAC3B,SAAS,CAAC,EAAE,OAAO,CAAA;IACnB,UAAU,CAAC,EAAE,MAAM,CAAA;CACpB;AAED,MAAM,WAAW,iCAAiC;IAChD,SAAS,EAAE,MAAM,CAAA;IACjB,kBAAkB,EAAE,MAAM,CAAA;IAC1B,IAAI,EAAE,OAAO,CAAA;IACb,SAAS,EAAE,MAAM,CAAA;IACjB,YAAY,EAAE,MAAM,CAAA;IACpB,UAAU,EAAE,WAAW,CAAC,OAAO,CAAC,CAAC,YAAY,CAAC,CAAA;IAC9C,IAAI,EAAE,kBAAkB,CAAC,MAAM,CAAC,CAAA;CACjC;AAED,oBAAY,cAAc;IACxB,MAAM,KAAK;IACX,IAAI,IAAI;IACR,MAAM,IAAI;CACX;AAED,MAAM,WAAW,iBAAiB;IAChC,UAAU,EAAE,MAAM,CAAA;IAClB,QAAQ,EAAE,MAAM,CAAA;IAChB,oBAAoB,EAAE,OAAO,CAAA;CAC9B;AAED,YAAY,EACV,YAAY,EACZ,cAAc,EACd,SAAS,EACT,cAAc,EACd,WAAW,GACZ,CAAA"}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { ReactElement } from '@lynx-js/react';
|
|
2
2
|
import type { CSSProperties } from '@lynx-js/types';
|
|
3
|
+
export type { SwiperItemProps } from '../SwiperItem/index.js';
|
|
3
4
|
export interface SwiperProps<T> {
|
|
4
5
|
/**
|
|
5
6
|
* Swiper items data set
|
|
@@ -45,6 +46,7 @@ export interface SwiperProps<T> {
|
|
|
45
46
|
* )}
|
|
46
47
|
* </Swiper>
|
|
47
48
|
* ```
|
|
49
|
+
* @docTypeFallback (prop: {index: number, item: T, realIndex: number}) => ReactElement
|
|
48
50
|
*/
|
|
49
51
|
children: (prop: RenderFunctionProps<T>) => ReactElement;
|
|
50
52
|
/**
|
|
@@ -369,16 +371,18 @@ export interface BounceConfig {
|
|
|
369
371
|
* @iOS
|
|
370
372
|
* @Harmony
|
|
371
373
|
* @zh 当startBounceItem处于回弹状态时,释放手指将调用此函数。
|
|
374
|
+
* @docTypeFallback (bounceParams: {offset: number, type: 'start' | 'end'}) => void
|
|
372
375
|
*/
|
|
373
|
-
onStartBounceItemBounce?: (bounceParams:
|
|
374
|
-
/**
|
|
376
|
+
onStartBounceItemBounce?: (bounceParams: OnBounceParams) => void;
|
|
377
|
+
/**
|
|
375
378
|
* When endBounceItem is in bounce state, releasing finger will call this.
|
|
376
379
|
* @Android
|
|
377
380
|
* @iOS
|
|
378
381
|
* @Harmony
|
|
379
382
|
* @zh 当endBounceItem处于回弹状态时,释放手指将调用此函数。
|
|
383
|
+
* @docTypeFallback (bounceParams: {offset: number, type: 'start' | 'end'}) => void
|
|
380
384
|
*/
|
|
381
|
-
onEndBounceItemBounce?: (bounceParams:
|
|
385
|
+
onEndBounceItemBounce?: (bounceParams: OnBounceParams) => void;
|
|
382
386
|
/**
|
|
383
387
|
* Width of bounceItem.
|
|
384
388
|
* When overscroll the bounces, you will have larger and larger resistance, to make overscroll not exceed bounceItemWidth
|
|
@@ -407,6 +411,7 @@ export interface SwiperRef {
|
|
|
407
411
|
* @iOS
|
|
408
412
|
* @Harmony
|
|
409
413
|
* @zh 滑动到指定索引的项目
|
|
414
|
+
* @docTypeFallback (index: number, options?: {animate?: boolean, onFinished?: () => void}) => void
|
|
410
415
|
*/
|
|
411
416
|
swipeTo: (index: number, options?: SwipeToOptions) => void;
|
|
412
417
|
/**
|
|
@@ -436,7 +441,7 @@ export interface SwiperRef {
|
|
|
436
441
|
*/
|
|
437
442
|
cancelAnimation: () => void;
|
|
438
443
|
}
|
|
439
|
-
export interface
|
|
444
|
+
export interface OnBounceParams {
|
|
440
445
|
type: 'start' | 'end';
|
|
441
446
|
offset: number;
|
|
442
447
|
}
|
|
@@ -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
|
|
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,YAAY,EAAE,eAAe,EAAE,MAAM,eAAe,CAAA;AAEpD,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;;;;;;;;;;;;;;;;;;;;;OAqBG;IACH,QAAQ,EAAE,CAAC,IAAI,EAAE,mBAAmB,CAAC,CAAC,CAAC,KAAK,YAAY,CAAA;IACxD;;;;;;;OAOG;IACH,cAAc,CAAC,EAAE,MAAM,CAAA;IACvB;;;;;;;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IAC9B;;;;;;OAMG;IACH,aAAa,CAAC,EAAE,YAAY,CAAA;IAC5B;;;;;;;OAOG;IACH,uBAAuB,CAAC,EAAE,CAAC,YAAY,EAAE,cAAc,KAAK,IAAI,CAAA;IAChE;;;;;;;OAOG;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;;;;;;;OAOG;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/dist/types/index.jsx.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types/index.jsx","sources":["../../src/types/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 type { CSSProperties, MainThread } from '@lynx-js/types'\n\nimport type {\n BounceConfig,\n SwipeToOptions,\n SwiperPropsReal as SwiperProps,\n SwiperRef,\n
|
|
1
|
+
{"version":3,"file":"types/index.jsx","sources":["../../src/types/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 type { CSSProperties, MainThread } from '@lynx-js/types'\n\nimport type {\n BounceConfig,\n OnBounceParams,\n SwipeToOptions,\n SwiperPropsReal as SwiperProps,\n SwiperRef,\n} from './index.docs'\n\nexport interface SwiperContextProps extends\n Pick<\n SwiperProps<unknown>,\n 'itemWidth' | 'itemHeight' | 'customAnimationFirstScreen' | 'RTL'\n >,\n Required<Pick<SwiperProps<unknown>, 'initialIndex' | 'loop'>>\n{\n setChildrenRef: (ref: MainThread.Element, index: number) => void\n spaceBetween: number\n modeConfig: CompoundModeConfig\n}\n\nexport interface CompoundNormalModeConfig {\n mode: 'normal'\n align: 'start' | 'center' | 'end'\n}\n\nexport interface CompoundCustomModeConfig {\n mode: 'custom'\n}\n\nexport type CompoundModeConfig =\n | CompoundNormalModeConfig\n | CompoundCustomModeConfig\n\nexport type CustomAnimation = (\n progress: number,\n props: SwiperProps<unknown>,\n) => CSSProperties\n\nexport interface CustomTouch {\n identifier: number\n pageX: number\n pageY: number\n clientX: number\n clientY: number\n x: number\n y: number\n}\n\n/**\n * Rewrite forwardRef to make it supports generic\n * see: https://stackoverflow.com/questions/58469229/react-with-typescript-generics-while-using-react-forwardref\n */\ndeclare module 'react' {\n // eslint-disable-next-line @typescript-eslint/no-empty-object-type -- intentional empty config\n function forwardRef<T, P = {}>(\n render: (props: P, ref: React.Ref<T>) => React.ReactElement | null,\n ): (props: P & React.RefAttributes<T>) => React.ReactElement | null\n}\n\ndeclare module '@lynx-js/types' {\n interface GlobalProps {\n screenWidth: number\n }\n}\n\nexport interface ResetOptions {\n fullReset?: boolean\n resetIndex?: number\n}\n\nexport interface UpdateSwiperInnerContainerOptions {\n itemWidth: number\n loopDuplicateCount: number\n loop: boolean\n dataCount: number\n spaceBetween: number\n itemHeight: SwiperProps<unknown>['itemHeight']\n mode: CompoundModeConfig['mode']\n}\n\nexport enum SwipeDirection {\n NORMAL = -1,\n NONE = 0,\n REVERT = 1,\n}\n\nexport interface OffsetLimitResult {\n startLimit: number\n endLimit: number\n isNotEnoughForScreen: boolean\n}\n\nexport type {\n BounceConfig,\n OnBounceParams,\n SwiperRef,\n SwipeToOptions,\n SwiperProps,\n}\n"],"names":["SwipeDirection"],"mappings":"AAsFO,IAAKA,uBAAcA,WAAAA,GAAAA,SAAdA,cAAc;;;;WAAdA"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lynx-js/lynx-ui-swiper",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.140.1",
|
|
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.2.2",
|
|
29
|
-
"@lynx-js/lynx-ui-common": "3.
|
|
29
|
+
"@lynx-js/lynx-ui-common": "3.139.0"
|
|
30
30
|
},
|
|
31
31
|
"devDependencies": {
|
|
32
32
|
"@lynx-js/react": "0.123.1",
|
package/src/Swiper/index.tsx
CHANGED
|
@@ -12,7 +12,7 @@ import {
|
|
|
12
12
|
import type { ForwardedRef } from '@lynx-js/react'
|
|
13
13
|
|
|
14
14
|
import { useTouchEmulation } from '@lynx-js/react-use'
|
|
15
|
-
import type { MainThread } from '@lynx-js/types'
|
|
15
|
+
import type { CSSProperties, MainThread } from '@lynx-js/types'
|
|
16
16
|
|
|
17
17
|
import { LOOP_COUNT } from '../const'
|
|
18
18
|
import { useBounceConfig } from '../hooks/useBounceConfig'
|
|
@@ -355,16 +355,19 @@ const Swiper = forwardRef(
|
|
|
355
355
|
containerWidth,
|
|
356
356
|
})
|
|
357
357
|
|
|
358
|
+
const rootStyle: CSSProperties = {
|
|
359
|
+
zIndex: 0,
|
|
360
|
+
...style,
|
|
361
|
+
width: `${containerWidth}px`,
|
|
362
|
+
height: `${itemHeight}px`,
|
|
363
|
+
direction: RTL === 'lynx-rtl' ? 'lynx-rtl' : (RTL ? 'rtl' : 'ltr'),
|
|
364
|
+
}
|
|
365
|
+
|
|
358
366
|
return (
|
|
359
367
|
<SwiperContext.Provider value={contextValue}>
|
|
360
368
|
<view
|
|
361
369
|
class='lynx-ui-swiper__root'
|
|
362
|
-
style={
|
|
363
|
-
...style,
|
|
364
|
-
width: `${containerWidth}px`,
|
|
365
|
-
height: `${itemHeight}px`,
|
|
366
|
-
direction: RTL === 'lynx-rtl' ? 'lynx-rtl' : (RTL ? 'rtl' : 'ltr'),
|
|
367
|
-
}}
|
|
370
|
+
style={rootStyle}
|
|
368
371
|
{...touchHandlers}
|
|
369
372
|
consume-slide-event={consumeSlideEvent}
|
|
370
373
|
block-native-event={blockNativeEvent}
|
package/src/hooks/useOffset.ts
CHANGED
|
@@ -22,10 +22,10 @@ import type {
|
|
|
22
22
|
BounceConfig,
|
|
23
23
|
CompoundModeConfig,
|
|
24
24
|
OffsetLimitResult,
|
|
25
|
+
OnBounceParams,
|
|
25
26
|
ResetOptions,
|
|
26
27
|
SwipeToOptions,
|
|
27
28
|
SwiperProps,
|
|
28
|
-
onBounceParams,
|
|
29
29
|
} from '../types'
|
|
30
30
|
import { useDirection } from './useDirection'
|
|
31
31
|
|
|
@@ -174,7 +174,7 @@ function useOffset(
|
|
|
174
174
|
// Offset should only be updated by this function.
|
|
175
175
|
function setOffset(offset: number) {
|
|
176
176
|
'main thread'
|
|
177
|
-
if (isNaN(offset)) {
|
|
177
|
+
if (Number.isNaN(offset)) {
|
|
178
178
|
throw new Error('calcBounceOffset: invalid offset')
|
|
179
179
|
}
|
|
180
180
|
offsetRef.current = offset
|
|
@@ -420,7 +420,7 @@ function useOffset(
|
|
|
420
420
|
runOnMainThread(swipeToMTS)(index, options)
|
|
421
421
|
}
|
|
422
422
|
|
|
423
|
-
function handleOnBounce(params:
|
|
423
|
+
function handleOnBounce(params: OnBounceParams) {
|
|
424
424
|
if (params.type === 'start' && onStartBounceItemBounce) {
|
|
425
425
|
onStartBounceItemBounce(params)
|
|
426
426
|
} else if (params.type === 'end' && onEndBounceItemBounce) {
|
|
@@ -567,7 +567,7 @@ function useOffset(
|
|
|
567
567
|
} else {
|
|
568
568
|
const currentIndex = prevIndexRef.current
|
|
569
569
|
// Guard against NaN from previous empty data state
|
|
570
|
-
if (isNaN(currentIndex)) {
|
|
570
|
+
if (Number.isNaN(currentIndex)) {
|
|
571
571
|
swipeToMTS(0, {
|
|
572
572
|
animate: false,
|
|
573
573
|
})
|
package/src/types/index.docs.ts
CHANGED
|
@@ -6,6 +6,8 @@ import type { ReactElement } from '@lynx-js/react'
|
|
|
6
6
|
|
|
7
7
|
import type { CSSProperties } from '@lynx-js/types'
|
|
8
8
|
|
|
9
|
+
export type { SwiperItemProps } from '../SwiperItem'
|
|
10
|
+
|
|
9
11
|
export interface SwiperProps<T> {
|
|
10
12
|
/**
|
|
11
13
|
* Swiper items data set
|
|
@@ -51,6 +53,7 @@ export interface SwiperProps<T> {
|
|
|
51
53
|
* )}
|
|
52
54
|
* </Swiper>
|
|
53
55
|
* ```
|
|
56
|
+
* @docTypeFallback (prop: {index: number, item: T, realIndex: number}) => ReactElement
|
|
54
57
|
*/
|
|
55
58
|
children: (prop: RenderFunctionProps<T>) => ReactElement
|
|
56
59
|
/**
|
|
@@ -384,16 +387,18 @@ export interface BounceConfig {
|
|
|
384
387
|
* @iOS
|
|
385
388
|
* @Harmony
|
|
386
389
|
* @zh 当startBounceItem处于回弹状态时,释放手指将调用此函数。
|
|
390
|
+
* @docTypeFallback (bounceParams: {offset: number, type: 'start' | 'end'}) => void
|
|
387
391
|
*/
|
|
388
|
-
onStartBounceItemBounce?: (bounceParams:
|
|
389
|
-
/**
|
|
392
|
+
onStartBounceItemBounce?: (bounceParams: OnBounceParams) => void
|
|
393
|
+
/**
|
|
390
394
|
* When endBounceItem is in bounce state, releasing finger will call this.
|
|
391
395
|
* @Android
|
|
392
396
|
* @iOS
|
|
393
397
|
* @Harmony
|
|
394
398
|
* @zh 当endBounceItem处于回弹状态时,释放手指将调用此函数。
|
|
399
|
+
* @docTypeFallback (bounceParams: {offset: number, type: 'start' | 'end'}) => void
|
|
395
400
|
*/
|
|
396
|
-
onEndBounceItemBounce?: (bounceParams:
|
|
401
|
+
onEndBounceItemBounce?: (bounceParams: OnBounceParams) => void
|
|
397
402
|
/**
|
|
398
403
|
* Width of bounceItem.
|
|
399
404
|
* When overscroll the bounces, you will have larger and larger resistance, to make overscroll not exceed bounceItemWidth
|
|
@@ -423,6 +428,7 @@ export interface SwiperRef {
|
|
|
423
428
|
* @iOS
|
|
424
429
|
* @Harmony
|
|
425
430
|
* @zh 滑动到指定索引的项目
|
|
431
|
+
* @docTypeFallback (index: number, options?: {animate?: boolean, onFinished?: () => void}) => void
|
|
426
432
|
*/
|
|
427
433
|
swipeTo: (index: number, options?: SwipeToOptions) => void
|
|
428
434
|
/**
|
|
@@ -453,7 +459,7 @@ export interface SwiperRef {
|
|
|
453
459
|
cancelAnimation: () => void
|
|
454
460
|
}
|
|
455
461
|
|
|
456
|
-
export interface
|
|
462
|
+
export interface OnBounceParams {
|
|
457
463
|
type: 'start' | 'end'
|
|
458
464
|
offset: number
|
|
459
465
|
}
|
package/src/types/index.ts
CHANGED
|
@@ -6,10 +6,10 @@ import type { CSSProperties, MainThread } from '@lynx-js/types'
|
|
|
6
6
|
|
|
7
7
|
import type {
|
|
8
8
|
BounceConfig,
|
|
9
|
+
OnBounceParams,
|
|
9
10
|
SwipeToOptions,
|
|
10
11
|
SwiperPropsReal as SwiperProps,
|
|
11
12
|
SwiperRef,
|
|
12
|
-
onBounceParams,
|
|
13
13
|
} from './index.docs'
|
|
14
14
|
|
|
15
15
|
export interface SwiperContextProps extends
|
|
@@ -37,7 +37,7 @@ export type CompoundModeConfig =
|
|
|
37
37
|
| CompoundNormalModeConfig
|
|
38
38
|
| CompoundCustomModeConfig
|
|
39
39
|
|
|
40
|
-
export type
|
|
40
|
+
export type CustomAnimation = (
|
|
41
41
|
progress: number,
|
|
42
42
|
props: SwiperProps<unknown>,
|
|
43
43
|
) => CSSProperties
|
|
@@ -57,7 +57,7 @@ export interface CustomTouch {
|
|
|
57
57
|
* see: https://stackoverflow.com/questions/58469229/react-with-typescript-generics-while-using-react-forwardref
|
|
58
58
|
*/
|
|
59
59
|
declare module 'react' {
|
|
60
|
-
//
|
|
60
|
+
// eslint-disable-next-line @typescript-eslint/no-empty-object-type -- intentional empty config
|
|
61
61
|
function forwardRef<T, P = {}>(
|
|
62
62
|
render: (props: P, ref: React.Ref<T>) => React.ReactElement | null,
|
|
63
63
|
): (props: P & React.RefAttributes<T>) => React.ReactElement | null
|
|
@@ -98,8 +98,8 @@ export interface OffsetLimitResult {
|
|
|
98
98
|
|
|
99
99
|
export type {
|
|
100
100
|
BounceConfig,
|
|
101
|
+
OnBounceParams,
|
|
101
102
|
SwiperRef,
|
|
102
|
-
onBounceParams,
|
|
103
103
|
SwipeToOptions,
|
|
104
104
|
SwiperProps,
|
|
105
105
|
}
|