@lynx-js/lynx-ui-swiper 3.139.0 → 3.141.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 +13 -0
- package/README.md +1 -5
- package/dist/SwiperItem/index.d.ts +2 -1
- package/dist/SwiperItem/index.d.ts.map +1 -1
- package/dist/SwiperItem/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 +16 -9
- package/dist/types/index.docs.d.ts.map +1 -1
- package/dist/types/index.jsx.map +1 -1
- package/package.json +1 -1
- package/src/SwiperItem/index.tsx +2 -1
- package/src/hooks/useOffset.ts +4 -4
- package/src/types/index.docs.ts +17 -9
- package/src/types/index.ts +4 -4
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,18 @@
|
|
|
1
1
|
# @lynx-js/lynx-ui-swiper
|
|
2
2
|
|
|
3
|
+
## 3.141.0
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- Clarify Swiper viewport sizing and styling guidance, and use consistent dimensions in skill examples and custom animations. ([#380](https://github.com/lynx-family/lynx-ui/pull/380))
|
|
8
|
+
|
|
9
|
+
## 3.140.1
|
|
10
|
+
|
|
11
|
+
### Patch Changes
|
|
12
|
+
|
|
13
|
+
- Add PascalCase names for public hook types and normalize supporting type names, ([#355](https://github.com/lynx-family/lynx-ui/pull/355))
|
|
14
|
+
retaining deprecated aliases for existing public names.
|
|
15
|
+
|
|
3
16
|
## 3.139.0
|
|
4
17
|
|
|
5
18
|
### Patch Changes
|
package/README.md
CHANGED
|
@@ -32,12 +32,13 @@ export interface SwiperItemProps {
|
|
|
32
32
|
*/
|
|
33
33
|
realIndex?: number;
|
|
34
34
|
/**
|
|
35
|
-
* `overlap` attribute
|
|
35
|
+
* `overlap` attribute applied to the view rendered by SwiperItem.
|
|
36
36
|
* This property is used only when opacity has issues.
|
|
37
37
|
* Refer to {@link https://lynxjs.org/api/css/properties/opacity#opacity}
|
|
38
38
|
* @Android
|
|
39
39
|
* @iOS
|
|
40
40
|
* @Harmony
|
|
41
|
+
* @zh 应用到SwiperItem自身渲染的view上的overlap属性,用于处理透明度渲染问题。
|
|
41
42
|
*/
|
|
42
43
|
overlap?: boolean;
|
|
43
44
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/SwiperItem/index.tsx"],"names":[],"mappings":"AAYA,OAAO,KAAK,EAAE,YAAY,EAAa,MAAM,gBAAgB,CAAA;AAE7D,OAAO,KAAK,EAAE,aAAa,EAAc,MAAM,gBAAgB,CAAA;AAK/D,MAAM,WAAW,eAAe;IAC9B;;;;;OAKG;IACH,KAAK,CAAC,EAAE,MAAM,CAAA;IACd;;;;;OAKG;IACH,QAAQ,EAAE,YAAY,GAAG,YAAY,EAAE,CAAA;IACvC;;;;;OAKG;IACH,KAAK,CAAC,EAAE,aAAa,CAAA;IACrB;;;;;;;OAOG;IACH,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/SwiperItem/index.tsx"],"names":[],"mappings":"AAYA,OAAO,KAAK,EAAE,YAAY,EAAa,MAAM,gBAAgB,CAAA;AAE7D,OAAO,KAAK,EAAE,aAAa,EAAc,MAAM,gBAAgB,CAAA;AAK/D,MAAM,WAAW,eAAe;IAC9B;;;;;OAKG;IACH,KAAK,CAAC,EAAE,MAAM,CAAA;IACd;;;;;OAKG;IACH,QAAQ,EAAE,YAAY,GAAG,YAAY,EAAE,CAAA;IACvC;;;;;OAKG;IACH,KAAK,CAAC,EAAE,aAAa,CAAA;IACrB;;;;;;;OAOG;IACH,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB;;;;;;;;OAQG;IACH,OAAO,CAAC,EAAE,OAAO,CAAA;CAClB;AAmGD,QAAA,MAAM,UAAU,GACd,yCAAyC,eAAe,gCAqDzD,CAAA;AAED,QAAA,MAAM,cAAc,EAAuB,OAAO,UAAU,CAAA;AAE5D,OAAO,EAAE,cAAc,IAAI,UAAU,EAAE,CAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SwiperItem/index.jsx","sources":["../../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
|
|
1
|
+
{"version":3,"file":"SwiperItem/index.jsx","sources":["../../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 applied to the view rendered by SwiperItem.\n * This property is used only when opacity has issues.\n * Refer to {@link https://lynxjs.org/api/css/properties/opacity#opacity}\n * @Android\n * @iOS\n * @Harmony\n * @zh 应用到SwiperItem自身渲染的view上的overlap属性,用于处理透明度渲染问题。\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='lynx-ui-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":";;AA8EA,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,uBACN,OAAO3B,gBACP,YAAY,KAAKyB,QACjB,SAASd,SACV;MACC,CAACD,SAAS;IACZ,EAAEiB;AAEN;AAEA,MAAMC,iBAAiBC,KAAKrB"}
|
|
@@ -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,Y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AAE,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,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A/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,MAAMH,gBACRyC,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"}
|
|
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,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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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,MAAM,gBAAgB,CAAA;AAE/D,OAAO,KAAK,EACV,YAAY,EACZ,cAAc,EACd,cAAc,EACd,eAAe,IAAI,WAAW,EAC9B,SAAS,EACV,MAAM,cAAc,CAAA;AAErB,MAAM,WAAW,kBAAmB,SAClC,IAAI,CACF,WAAW,CAAC,OAAO,CAAC,EACpB,WAAW,GAAG,YAAY,GAAG,4BAA4B,GAAG,KAAK,CAClE,EACD,QAAQ,CAAC,IAAI,CAAC,WAAW,CAAC,OAAO,CAAC,EAAE,cAAc,GAAG,MAAM,CAAC,CAAC;IAE7D,cAAc,EAAE,CAAC,GAAG,EAAE,UAAU,CAAC,OAAO,EAAE,KAAK,EAAE,MAAM,KAAK,IAAI,CAAA;IAChE,YAAY,EAAE,MAAM,CAAA;IACpB,UAAU,EAAE,kBAAkB,CAAA;CAC/B;AAED,MAAM,WAAW,wBAAwB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;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
|
|
@@ -36,6 +37,7 @@ export interface SwiperProps<T> {
|
|
|
36
37
|
* <Swiper
|
|
37
38
|
* data={items}
|
|
38
39
|
* itemWidth={350}
|
|
40
|
+
* containerWidth={375}
|
|
39
41
|
* >
|
|
40
42
|
* {({ index, item }) => (
|
|
41
43
|
* <SwiperItem>
|
|
@@ -49,12 +51,15 @@ export interface SwiperProps<T> {
|
|
|
49
51
|
*/
|
|
50
52
|
children: (prop: RenderFunctionProps<T>) => ReactElement;
|
|
51
53
|
/**
|
|
52
|
-
* Width of
|
|
53
|
-
*
|
|
54
|
+
* Width of the Swiper viewport in px. Always pass this prop explicitly.
|
|
55
|
+
* Use the width available inside the parent.
|
|
56
|
+
* For example, inside a screen-width parent with 16px padding on each side,
|
|
57
|
+
* set containerWidth to screenWidth - 32.
|
|
58
|
+
* @defaultValue lynx.__globalProps.screenWidth ?? SystemInfo.pixelWidth / SystemInfo.pixelRatio
|
|
54
59
|
* @Android
|
|
55
60
|
* @iOS
|
|
56
61
|
* @Harmony
|
|
57
|
-
* @zh
|
|
62
|
+
* @zh 轮播图视口的宽度,单位为px。使用时必须显式传入父容器内的可用宽度。例如,父容器与屏幕等宽且左右各有16px内边距时,将containerWidth设置为screenWidth - 32。
|
|
58
63
|
*/
|
|
59
64
|
containerWidth?: number;
|
|
60
65
|
/**
|
|
@@ -217,11 +222,13 @@ export interface SwiperProps<T> {
|
|
|
217
222
|
/**
|
|
218
223
|
* Style for the root element of the Swiper component.
|
|
219
224
|
* This controls the visible viewport/frame that contains the swiper.
|
|
220
|
-
* Use this for
|
|
225
|
+
* Use this for background, borders, border radius, and overflow.
|
|
226
|
+
* Configure dimensions through containerWidth and itemHeight, and direction through RTL.
|
|
227
|
+
* Apply outer padding and CSS classes to a surrounding view.
|
|
221
228
|
* @Android
|
|
222
229
|
* @iOS
|
|
223
230
|
* @Harmony
|
|
224
|
-
* @zh Swiper
|
|
231
|
+
* @zh Swiper组件根元素的样式,用于背景、边框、圆角和溢出等。尺寸通过containerWidth和itemHeight配置,方向通过RTL配置。外层内边距和CSS类放在包裹view上。
|
|
225
232
|
*/
|
|
226
233
|
style?: CSSProperties;
|
|
227
234
|
/**
|
|
@@ -372,8 +379,8 @@ export interface BounceConfig {
|
|
|
372
379
|
* @zh 当startBounceItem处于回弹状态时,释放手指将调用此函数。
|
|
373
380
|
* @docTypeFallback (bounceParams: {offset: number, type: 'start' | 'end'}) => void
|
|
374
381
|
*/
|
|
375
|
-
onStartBounceItemBounce?: (bounceParams:
|
|
376
|
-
/**
|
|
382
|
+
onStartBounceItemBounce?: (bounceParams: OnBounceParams) => void;
|
|
383
|
+
/**
|
|
377
384
|
* When endBounceItem is in bounce state, releasing finger will call this.
|
|
378
385
|
* @Android
|
|
379
386
|
* @iOS
|
|
@@ -381,7 +388,7 @@ export interface BounceConfig {
|
|
|
381
388
|
* @zh 当endBounceItem处于回弹状态时,释放手指将调用此函数。
|
|
382
389
|
* @docTypeFallback (bounceParams: {offset: number, type: 'start' | 'end'}) => void
|
|
383
390
|
*/
|
|
384
|
-
onEndBounceItemBounce?: (bounceParams:
|
|
391
|
+
onEndBounceItemBounce?: (bounceParams: OnBounceParams) => void;
|
|
385
392
|
/**
|
|
386
393
|
* Width of bounceItem.
|
|
387
394
|
* When overscroll the bounces, you will have larger and larger resistance, to make overscroll not exceed bounceItemWidth
|
|
@@ -440,7 +447,7 @@ export interface SwiperRef {
|
|
|
440
447
|
*/
|
|
441
448
|
cancelAnimation: () => void;
|
|
442
449
|
}
|
|
443
|
-
export interface
|
|
450
|
+
export interface OnBounceParams {
|
|
444
451
|
type: 'start' | 'end';
|
|
445
452
|
offset: number;
|
|
446
453
|
}
|
|
@@ -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,EAA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AAA;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
package/src/SwiperItem/index.tsx
CHANGED
|
@@ -49,12 +49,13 @@ export interface SwiperItemProps {
|
|
|
49
49
|
*/
|
|
50
50
|
realIndex?: number
|
|
51
51
|
/**
|
|
52
|
-
* `overlap` attribute
|
|
52
|
+
* `overlap` attribute applied to the view rendered by SwiperItem.
|
|
53
53
|
* This property is used only when opacity has issues.
|
|
54
54
|
* Refer to {@link https://lynxjs.org/api/css/properties/opacity#opacity}
|
|
55
55
|
* @Android
|
|
56
56
|
* @iOS
|
|
57
57
|
* @Harmony
|
|
58
|
+
* @zh 应用到SwiperItem自身渲染的view上的overlap属性,用于处理透明度渲染问题。
|
|
58
59
|
*/
|
|
59
60
|
overlap?: boolean
|
|
60
61
|
}
|
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
|
|
@@ -42,6 +44,7 @@ export interface SwiperProps<T> {
|
|
|
42
44
|
* <Swiper
|
|
43
45
|
* data={items}
|
|
44
46
|
* itemWidth={350}
|
|
47
|
+
* containerWidth={375}
|
|
45
48
|
* >
|
|
46
49
|
* {({ index, item }) => (
|
|
47
50
|
* <SwiperItem>
|
|
@@ -55,12 +58,15 @@ export interface SwiperProps<T> {
|
|
|
55
58
|
*/
|
|
56
59
|
children: (prop: RenderFunctionProps<T>) => ReactElement
|
|
57
60
|
/**
|
|
58
|
-
* Width of
|
|
59
|
-
*
|
|
61
|
+
* Width of the Swiper viewport in px. Always pass this prop explicitly.
|
|
62
|
+
* Use the width available inside the parent.
|
|
63
|
+
* For example, inside a screen-width parent with 16px padding on each side,
|
|
64
|
+
* set containerWidth to screenWidth - 32.
|
|
65
|
+
* @defaultValue lynx.__globalProps.screenWidth ?? SystemInfo.pixelWidth / SystemInfo.pixelRatio
|
|
60
66
|
* @Android
|
|
61
67
|
* @iOS
|
|
62
68
|
* @Harmony
|
|
63
|
-
* @zh
|
|
69
|
+
* @zh 轮播图视口的宽度,单位为px。使用时必须显式传入父容器内的可用宽度。例如,父容器与屏幕等宽且左右各有16px内边距时,将containerWidth设置为screenWidth - 32。
|
|
64
70
|
*/
|
|
65
71
|
containerWidth?: number
|
|
66
72
|
/**
|
|
@@ -226,11 +232,13 @@ export interface SwiperProps<T> {
|
|
|
226
232
|
/**
|
|
227
233
|
* Style for the root element of the Swiper component.
|
|
228
234
|
* This controls the visible viewport/frame that contains the swiper.
|
|
229
|
-
* Use this for
|
|
235
|
+
* Use this for background, borders, border radius, and overflow.
|
|
236
|
+
* Configure dimensions through containerWidth and itemHeight, and direction through RTL.
|
|
237
|
+
* Apply outer padding and CSS classes to a surrounding view.
|
|
230
238
|
* @Android
|
|
231
239
|
* @iOS
|
|
232
240
|
* @Harmony
|
|
233
|
-
* @zh Swiper
|
|
241
|
+
* @zh Swiper组件根元素的样式,用于背景、边框、圆角和溢出等。尺寸通过containerWidth和itemHeight配置,方向通过RTL配置。外层内边距和CSS类放在包裹view上。
|
|
234
242
|
*/
|
|
235
243
|
style?: CSSProperties
|
|
236
244
|
|
|
@@ -387,8 +395,8 @@ export interface BounceConfig {
|
|
|
387
395
|
* @zh 当startBounceItem处于回弹状态时,释放手指将调用此函数。
|
|
388
396
|
* @docTypeFallback (bounceParams: {offset: number, type: 'start' | 'end'}) => void
|
|
389
397
|
*/
|
|
390
|
-
onStartBounceItemBounce?: (bounceParams:
|
|
391
|
-
/**
|
|
398
|
+
onStartBounceItemBounce?: (bounceParams: OnBounceParams) => void
|
|
399
|
+
/**
|
|
392
400
|
* When endBounceItem is in bounce state, releasing finger will call this.
|
|
393
401
|
* @Android
|
|
394
402
|
* @iOS
|
|
@@ -396,7 +404,7 @@ export interface BounceConfig {
|
|
|
396
404
|
* @zh 当endBounceItem处于回弹状态时,释放手指将调用此函数。
|
|
397
405
|
* @docTypeFallback (bounceParams: {offset: number, type: 'start' | 'end'}) => void
|
|
398
406
|
*/
|
|
399
|
-
onEndBounceItemBounce?: (bounceParams:
|
|
407
|
+
onEndBounceItemBounce?: (bounceParams: OnBounceParams) => void
|
|
400
408
|
/**
|
|
401
409
|
* Width of bounceItem.
|
|
402
410
|
* When overscroll the bounces, you will have larger and larger resistance, to make overscroll not exceed bounceItemWidth
|
|
@@ -457,7 +465,7 @@ export interface SwiperRef {
|
|
|
457
465
|
cancelAnimation: () => void
|
|
458
466
|
}
|
|
459
467
|
|
|
460
|
-
export interface
|
|
468
|
+
export interface OnBounceParams {
|
|
461
469
|
type: 'start' | 'end'
|
|
462
470
|
offset: number
|
|
463
471
|
}
|
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
|
}
|