@lynx-js/lynx-ui-swiper 0.0.0 → 3.131.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +25 -0
- package/LICENSE +201 -0
- package/README.md +51 -0
- package/dist/Swiper/index.d.ts +11 -0
- package/dist/Swiper/index.d.ts.map +1 -0
- package/dist/Swiper/index.jsx +261 -0
- package/dist/Swiper/index.jsx.map +1 -0
- package/dist/Swiper/styles.css +47 -0
- package/dist/Swiper/styles.css.map +1 -0
- package/dist/SwiperItem/index.d.ts +46 -0
- package/dist/SwiperItem/index.d.ts.map +1 -0
- package/dist/SwiperItem/index.jsx +86 -0
- package/dist/SwiperItem/index.jsx.map +1 -0
- package/dist/const/index.d.ts +5 -0
- package/dist/const/index.d.ts.map +1 -0
- package/dist/const/index.jsx +7 -0
- package/dist/const/index.jsx.map +1 -0
- package/dist/hooks/useAnimate.d.ts +5 -0
- package/dist/hooks/useAnimate.d.ts.map +1 -0
- package/dist/hooks/useAnimate.jsx +47 -0
- package/dist/hooks/useAnimate.jsx.map +1 -0
- package/dist/hooks/useAutoPlay.d.ts +16 -0
- package/dist/hooks/useAutoPlay.d.ts.map +1 -0
- package/dist/hooks/useAutoPlay.jsx +58 -0
- package/dist/hooks/useAutoPlay.jsx.map +1 -0
- package/dist/hooks/useAxisLock.d.ts +12 -0
- package/dist/hooks/useAxisLock.d.ts.map +1 -0
- package/dist/hooks/useAxisLock.jsx +58 -0
- package/dist/hooks/useAxisLock.jsx.map +1 -0
- package/dist/hooks/useBounceConfig.d.ts +12 -0
- package/dist/hooks/useBounceConfig.d.ts.map +1 -0
- package/dist/hooks/useBounceConfig.jsx +15 -0
- package/dist/hooks/useBounceConfig.jsx.map +1 -0
- package/dist/hooks/useBounceView.d.ts +17 -0
- package/dist/hooks/useBounceView.d.ts.map +1 -0
- package/dist/hooks/useBounceView.jsx +16 -0
- package/dist/hooks/useBounceView.jsx.map +1 -0
- package/dist/hooks/useChange.d.ts +22 -0
- package/dist/hooks/useChange.d.ts.map +1 -0
- package/dist/hooks/useChange.jsx +53 -0
- package/dist/hooks/useChange.jsx.map +1 -0
- package/dist/hooks/useDirection.d.ts +13 -0
- package/dist/hooks/useDirection.d.ts.map +1 -0
- package/dist/hooks/useDirection.jsx +37 -0
- package/dist/hooks/useDirection.jsx.map +1 -0
- package/dist/hooks/useFirstScreenStyle.d.ts +34 -0
- package/dist/hooks/useFirstScreenStyle.d.ts.map +1 -0
- package/dist/hooks/useFirstScreenStyle.jsx +63 -0
- package/dist/hooks/useFirstScreenStyle.jsx.map +1 -0
- package/dist/hooks/useModeConfig.d.ts +14 -0
- package/dist/hooks/useModeConfig.d.ts.map +1 -0
- package/dist/hooks/useModeConfig.jsx +33 -0
- package/dist/hooks/useModeConfig.jsx.map +1 -0
- package/dist/hooks/useOffset.d.ts +37 -0
- package/dist/hooks/useOffset.d.ts.map +1 -0
- package/dist/hooks/useOffset.jsx +362 -0
- package/dist/hooks/useOffset.jsx.map +1 -0
- package/dist/hooks/useOffsetLimit.d.ts +16 -0
- package/dist/hooks/useOffsetLimit.d.ts.map +1 -0
- package/dist/hooks/useOffsetLimit.jsx +51 -0
- package/dist/hooks/useOffsetLimit.jsx.map +1 -0
- package/dist/hooks/useReset.d.ts +16 -0
- package/dist/hooks/useReset.d.ts.map +1 -0
- package/dist/hooks/useReset.jsx +68 -0
- package/dist/hooks/useReset.jsx.map +1 -0
- package/dist/hooks/useSwipeCallback.d.ts +14 -0
- package/dist/hooks/useSwipeCallback.d.ts.map +1 -0
- package/dist/hooks/useSwipeCallback.jsx +40 -0
- package/dist/hooks/useSwipeCallback.jsx.map +1 -0
- package/dist/hooks/useVelocity.d.ts +14 -0
- package/dist/hooks/useVelocity.d.ts.map +1 -0
- package/dist/hooks/useVelocity.jsx +62 -0
- package/dist/hooks/useVelocity.jsx.map +1 -0
- package/dist/hooks/useVelocity_experiment.d.ts +12 -0
- package/dist/hooks/useVelocity_experiment.d.ts.map +1 -0
- package/dist/hooks/useVelocity_experiment.jsx +38 -0
- package/dist/hooks/useVelocity_experiment.jsx.map +1 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.jsx +3 -0
- package/dist/store/index.d.ts +3 -0
- package/dist/store/index.d.ts.map +1 -0
- package/dist/store/index.jsx +18 -0
- package/dist/store/index.jsx.map +1 -0
- package/dist/types/index.d.ts +62 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/index.docs.d.ts +448 -0
- package/dist/types/index.docs.d.ts.map +1 -0
- package/dist/types/index.jsx +9 -0
- package/dist/types/index.jsx.map +1 -0
- package/dist/utils/animate.d.ts +4 -0
- package/dist/utils/animate.d.ts.map +1 -0
- package/dist/utils/animate.jsx +29 -0
- package/dist/utils/animate.jsx.map +1 -0
- package/dist/utils/compareProps.d.ts +2 -0
- package/dist/utils/compareProps.d.ts.map +1 -0
- package/dist/utils/compareProps.jsx +14 -0
- package/dist/utils/compareProps.jsx.map +1 -0
- package/dist/utils/customRound.d.ts +10 -0
- package/dist/utils/customRound.d.ts.map +1 -0
- package/dist/utils/customRound.jsx +9 -0
- package/dist/utils/customRound.jsx.map +1 -0
- package/dist/utils/index.d.ts +20 -0
- package/dist/utils/index.d.ts.map +1 -0
- package/dist/utils/index.jsx +55 -0
- package/dist/utils/index.jsx.map +1 -0
- package/package.json +47 -4
- package/src/Swiper/index.tsx +414 -0
- package/src/Swiper/styles.css +44 -0
- package/src/SwiperItem/index.tsx +205 -0
- package/src/const/index.ts +11 -0
- package/src/hooks/useAnimate.ts +80 -0
- package/src/hooks/useAutoPlay.ts +95 -0
- package/src/hooks/useAxisLock.ts +92 -0
- package/src/hooks/useBounceConfig.ts +29 -0
- package/src/hooks/useBounceView.tsx +50 -0
- package/src/hooks/useChange.ts +131 -0
- package/src/hooks/useDirection.ts +59 -0
- package/src/hooks/useFirstScreenStyle.ts +200 -0
- package/src/hooks/useModeConfig.ts +56 -0
- package/src/hooks/useOffset.ts +609 -0
- package/src/hooks/useOffsetLimit.ts +98 -0
- package/src/hooks/useReset.ts +144 -0
- package/src/hooks/useSwipeCallback.ts +66 -0
- package/src/hooks/useVelocity.ts +85 -0
- package/src/hooks/useVelocity_experiment.ts +50 -0
- package/src/index.ts +8 -0
- package/src/store/index.ts +23 -0
- package/src/types/index.docs.ts +465 -0
- package/src/types/index.ts +105 -0
- package/src/utils/animate.ts +49 -0
- package/src/utils/compareProps.ts +54 -0
- package/src/utils/customRound.ts +23 -0
- package/src/utils/index.ts +117 -0
- package/tsconfig.docs.json +7 -0
- package/tsconfig.json +9 -0
- /package/{index.js → dist/types/index.docs.jsx} +0 -0
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
// Copyright 2026 The Lynx Authors. All rights reserved.
|
|
2
|
+
// Licensed under the Apache License Version 2.0 that can be found in the
|
|
3
|
+
// LICENSE file in the root directory of this source tree.
|
|
4
|
+
|
|
5
|
+
import { runOnMainThread, useEffect, useRef } from '@lynx-js/react'
|
|
6
|
+
|
|
7
|
+
import { useMemoizedFn } from '@lynx-js/lynx-ui-common'
|
|
8
|
+
import type { NodesRef } from '@lynx-js/types'
|
|
9
|
+
|
|
10
|
+
import type {
|
|
11
|
+
CompoundModeConfig,
|
|
12
|
+
ResetOptions,
|
|
13
|
+
SwiperProps,
|
|
14
|
+
UpdateSwiperInnerContainerOptions,
|
|
15
|
+
} from '../types'
|
|
16
|
+
|
|
17
|
+
interface UseResetOpts extends
|
|
18
|
+
Required<
|
|
19
|
+
Pick<
|
|
20
|
+
SwiperProps<unknown>,
|
|
21
|
+
| 'swiperKey'
|
|
22
|
+
| 'loop'
|
|
23
|
+
| 'itemWidth'
|
|
24
|
+
| 'itemHeight'
|
|
25
|
+
| 'containerWidth'
|
|
26
|
+
| 'initialIndex'
|
|
27
|
+
| 'loopDuplicateCount'
|
|
28
|
+
>
|
|
29
|
+
>
|
|
30
|
+
{
|
|
31
|
+
resetOnReuse: SwiperProps<unknown>['resetOnReuse']
|
|
32
|
+
dataCount: number
|
|
33
|
+
modeConfig: CompoundModeConfig
|
|
34
|
+
spaceBetween: number
|
|
35
|
+
resetOffsetMT: (fullReset: ResetOptions) => void
|
|
36
|
+
updateSwiperInnerContainerSizeMT: (
|
|
37
|
+
updateOptions: UpdateSwiperInnerContainerOptions,
|
|
38
|
+
) => void
|
|
39
|
+
startAutoPlayMT: () => void
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export function useReset({
|
|
43
|
+
swiperKey,
|
|
44
|
+
itemHeight,
|
|
45
|
+
itemWidth,
|
|
46
|
+
containerWidth,
|
|
47
|
+
loop,
|
|
48
|
+
dataCount,
|
|
49
|
+
modeConfig,
|
|
50
|
+
resetOffsetMT,
|
|
51
|
+
resetOnReuse,
|
|
52
|
+
initialIndex,
|
|
53
|
+
updateSwiperInnerContainerSizeMT,
|
|
54
|
+
loopDuplicateCount,
|
|
55
|
+
startAutoPlayMT,
|
|
56
|
+
spaceBetween,
|
|
57
|
+
}: UseResetOpts) {
|
|
58
|
+
const prevSwiperKey = useRef<unknown>(swiperKey)
|
|
59
|
+
const isFirstRun = useRef<boolean>(true)
|
|
60
|
+
const containerRef = useRef<NodesRef | null>(null)
|
|
61
|
+
|
|
62
|
+
function doResetMT(
|
|
63
|
+
resetOptions: ResetOptions & UpdateSwiperInnerContainerOptions,
|
|
64
|
+
) {
|
|
65
|
+
'main thread'
|
|
66
|
+
// Get props from function args, instead of automatically captured, to avoid staled states
|
|
67
|
+
const {
|
|
68
|
+
fullReset,
|
|
69
|
+
resetIndex,
|
|
70
|
+
dataCount: _dataCount,
|
|
71
|
+
itemWidth: _itemWidth,
|
|
72
|
+
loop: _loop,
|
|
73
|
+
loopDuplicateCount: _loopDuplicateCount,
|
|
74
|
+
spaceBetween: _gap,
|
|
75
|
+
itemHeight: _itemHeight,
|
|
76
|
+
} = resetOptions
|
|
77
|
+
resetOffsetMT({
|
|
78
|
+
fullReset,
|
|
79
|
+
resetIndex,
|
|
80
|
+
})
|
|
81
|
+
updateSwiperInnerContainerSizeMT({
|
|
82
|
+
dataCount: _dataCount,
|
|
83
|
+
itemWidth: _itemWidth,
|
|
84
|
+
loop: _loop,
|
|
85
|
+
loopDuplicateCount: _loopDuplicateCount,
|
|
86
|
+
spaceBetween: _gap,
|
|
87
|
+
itemHeight: _itemHeight,
|
|
88
|
+
mode: modeConfig.mode,
|
|
89
|
+
})
|
|
90
|
+
startAutoPlayMT()
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
const doReset = useMemoizedFn((fullReset: boolean) => {
|
|
94
|
+
runOnMainThread(doResetMT)({
|
|
95
|
+
fullReset,
|
|
96
|
+
resetIndex: fullReset ? initialIndex : undefined,
|
|
97
|
+
dataCount,
|
|
98
|
+
itemWidth,
|
|
99
|
+
loop,
|
|
100
|
+
loopDuplicateCount,
|
|
101
|
+
spaceBetween,
|
|
102
|
+
itemHeight,
|
|
103
|
+
mode: modeConfig.mode,
|
|
104
|
+
})
|
|
105
|
+
})
|
|
106
|
+
|
|
107
|
+
/**
|
|
108
|
+
* When used in list, while Swiper Component is new, container element will be reused, causing old styles are applied.
|
|
109
|
+
* When reused, ref setter will fire setRef with null, then with actual nodes
|
|
110
|
+
* We use this as the sign of reuse, and doing a clean up.
|
|
111
|
+
*/
|
|
112
|
+
const setContainerRef = useMemoizedFn(
|
|
113
|
+
(ref: NodesRef) => {
|
|
114
|
+
if (containerRef.current === null && ref !== null && resetOnReuse) {
|
|
115
|
+
doReset(true)
|
|
116
|
+
}
|
|
117
|
+
containerRef.current = ref
|
|
118
|
+
},
|
|
119
|
+
)
|
|
120
|
+
|
|
121
|
+
useEffect(() => {
|
|
122
|
+
if (isFirstRun.current) {
|
|
123
|
+
isFirstRun.current = false
|
|
124
|
+
return
|
|
125
|
+
}
|
|
126
|
+
if (prevSwiperKey.current === swiperKey) {
|
|
127
|
+
doReset(false)
|
|
128
|
+
} else {
|
|
129
|
+
prevSwiperKey.current = swiperKey
|
|
130
|
+
doReset(true)
|
|
131
|
+
}
|
|
132
|
+
}, [
|
|
133
|
+
modeConfig,
|
|
134
|
+
itemWidth,
|
|
135
|
+
containerWidth,
|
|
136
|
+
loop,
|
|
137
|
+
dataCount,
|
|
138
|
+
itemHeight,
|
|
139
|
+
swiperKey,
|
|
140
|
+
loopDuplicateCount,
|
|
141
|
+
])
|
|
142
|
+
|
|
143
|
+
return { setContainerRef }
|
|
144
|
+
}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
// Copyright 2026 The Lynx Authors. All rights reserved.
|
|
2
|
+
// Licensed under the Apache License Version 2.0 that can be found in the
|
|
3
|
+
// LICENSE file in the root directory of this source tree.
|
|
4
|
+
|
|
5
|
+
import { useMainThreadRef } from '@lynx-js/react'
|
|
6
|
+
|
|
7
|
+
import { useTapLock } from '@lynx-js/react-use'
|
|
8
|
+
import type { MainThread } from '@lynx-js/types'
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Determine whether a touch is swipe or click.
|
|
12
|
+
*/
|
|
13
|
+
export function useSwipeCallback({
|
|
14
|
+
onSwipeStartMT,
|
|
15
|
+
onSwipeStopMT,
|
|
16
|
+
}: {
|
|
17
|
+
onSwipeStartMT: () => void
|
|
18
|
+
onSwipeStopMT: () => void
|
|
19
|
+
}) {
|
|
20
|
+
const swipeStartedMTRef = useMainThreadRef<boolean>(false)
|
|
21
|
+
|
|
22
|
+
const {
|
|
23
|
+
handleTouchStart: tapLockTouchStart,
|
|
24
|
+
handleTouchMove: tapLockTouchMove,
|
|
25
|
+
} = useTapLock()
|
|
26
|
+
|
|
27
|
+
function setSwipeStartMT() {
|
|
28
|
+
'main thread'
|
|
29
|
+
if (swipeStartedMTRef.current) {
|
|
30
|
+
return
|
|
31
|
+
}
|
|
32
|
+
swipeStartedMTRef.current = true
|
|
33
|
+
onSwipeStartMT()
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
function setSwipeEndMT() {
|
|
37
|
+
'main thread'
|
|
38
|
+
if (swipeStartedMTRef.current) {
|
|
39
|
+
onSwipeStopMT()
|
|
40
|
+
swipeStartedMTRef.current = false
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
function handleTouchStart(event: MainThread.TouchEvent) {
|
|
45
|
+
'main thread'
|
|
46
|
+
|
|
47
|
+
tapLockTouchStart(event)
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
function handleTouchMove(event: MainThread.TouchEvent) {
|
|
51
|
+
'main thread'
|
|
52
|
+
|
|
53
|
+
if (!swipeStartedMTRef.current && !tapLockTouchMove(event)) {
|
|
54
|
+
swipeStartedMTRef.current = true
|
|
55
|
+
onSwipeStartMT()
|
|
56
|
+
return
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
return {
|
|
61
|
+
handleTouchStart,
|
|
62
|
+
handleTouchMove,
|
|
63
|
+
setSwipeEndMT,
|
|
64
|
+
setSwipeStartMT,
|
|
65
|
+
}
|
|
66
|
+
}
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
// Copyright 2026 The Lynx Authors. All rights reserved.
|
|
2
|
+
// Licensed under the Apache License Version 2.0 that can be found in the
|
|
3
|
+
// LICENSE file in the root directory of this source tree.
|
|
4
|
+
|
|
5
|
+
import { useMainThreadRef } from '@lynx-js/react'
|
|
6
|
+
|
|
7
|
+
import type { MainThread } from '@lynx-js/types'
|
|
8
|
+
|
|
9
|
+
import { SwipeDirection } from '../types'
|
|
10
|
+
import type { SwiperProps } from '../types'
|
|
11
|
+
|
|
12
|
+
export function useVelocity({ RTL }: { RTL: SwiperProps<unknown>['RTL'] }) {
|
|
13
|
+
const positionQueueRef = useMainThreadRef<number[]>([])
|
|
14
|
+
const timeQueueRef = useMainThreadRef<number[]>([])
|
|
15
|
+
|
|
16
|
+
const reset = () => {
|
|
17
|
+
'main thread'
|
|
18
|
+
timeQueueRef.current = []
|
|
19
|
+
positionQueueRef.current = []
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
const pruneQueue = (ms: number, minLength = 0) => {
|
|
23
|
+
'main thread'
|
|
24
|
+
const timeQueue = timeQueueRef.current
|
|
25
|
+
const positionQueue = positionQueueRef.current
|
|
26
|
+
|
|
27
|
+
const nowTs = Date.now()
|
|
28
|
+
// pull old values off of the queue
|
|
29
|
+
while (timeQueue.length > minLength && timeQueue[0] < nowTs - ms) {
|
|
30
|
+
timeQueue.shift()
|
|
31
|
+
positionQueue.shift()
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
const getVelocity = () => {
|
|
36
|
+
'main thread'
|
|
37
|
+
pruneQueue(500)
|
|
38
|
+
const timeQueue = timeQueueRef.current
|
|
39
|
+
const positionQueue = positionQueueRef.current
|
|
40
|
+
const { length } = timeQueue
|
|
41
|
+
if (length < 2) {
|
|
42
|
+
return {
|
|
43
|
+
velocity: 0,
|
|
44
|
+
direction: SwipeDirection.REVERT,
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
const distance = RTL
|
|
48
|
+
? positionQueue[0] - positionQueue[length - 1]
|
|
49
|
+
: positionQueue[length - 1] - positionQueue[0]
|
|
50
|
+
const time = (timeQueue[length - 1] - timeQueue[0]) / 1000
|
|
51
|
+
return {
|
|
52
|
+
velocity: distance / time,
|
|
53
|
+
direction: distance > 0 ? SwipeDirection.REVERT : SwipeDirection.NORMAL,
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
const updatePosition = (position: number) => {
|
|
58
|
+
'main thread'
|
|
59
|
+
const timeQueue = timeQueueRef.current
|
|
60
|
+
const positionQueue = positionQueueRef.current
|
|
61
|
+
|
|
62
|
+
positionQueue.push(position)
|
|
63
|
+
timeQueue.push(Date.now())
|
|
64
|
+
// Keep one older sample around so sparse touchmove delivery can still
|
|
65
|
+
// produce a release velocity from the latest two points.
|
|
66
|
+
pruneQueue(50, 2)
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
function velocityTouchStart() {
|
|
70
|
+
'main thread'
|
|
71
|
+
reset()
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
function velocityTouchMove(event: MainThread.TouchEvent) {
|
|
75
|
+
'main thread'
|
|
76
|
+
|
|
77
|
+
updatePosition(event.detail.x)
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
return {
|
|
81
|
+
getVelocity,
|
|
82
|
+
velocityTouchStart,
|
|
83
|
+
velocityTouchMove,
|
|
84
|
+
}
|
|
85
|
+
}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
// Copyright 2026 The Lynx Authors. All rights reserved.
|
|
2
|
+
// Licensed under the Apache License Version 2.0 that can be found in the
|
|
3
|
+
// LICENSE file in the root directory of this source tree.
|
|
4
|
+
|
|
5
|
+
import { useMainThreadRef } from '@lynx-js/react'
|
|
6
|
+
|
|
7
|
+
import type { MainThread } from '@lynx-js/types'
|
|
8
|
+
|
|
9
|
+
export function useVelocity({ deceleratingRate = 0.99 }) {
|
|
10
|
+
const touchStartRef = useMainThreadRef<number>(0)
|
|
11
|
+
const velocityRef = useMainThreadRef<number>(0)
|
|
12
|
+
|
|
13
|
+
function velocityTouchStart(event: MainThread.TouchEvent) {
|
|
14
|
+
'main thread'
|
|
15
|
+
|
|
16
|
+
touchStartRef.current = event.detail.x
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
function velocityTouchMove(event: MainThread.TouchEvent) {
|
|
20
|
+
'main thread'
|
|
21
|
+
const timeDuration = Date.now() - event.timestamp
|
|
22
|
+
|
|
23
|
+
const delta = event.detail.x - touchStartRef.current
|
|
24
|
+
const velocity = delta / timeDuration
|
|
25
|
+
velocityRef.current = velocity
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
function getVelocityDistance() {
|
|
29
|
+
'main thread'
|
|
30
|
+
const velocity = velocityRef.current
|
|
31
|
+
const distance = Math.pow(velocity, 2) / (2 * deceleratingRate)
|
|
32
|
+
return distance
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
function getVelocity() {
|
|
36
|
+
'main thread'
|
|
37
|
+
const distance = getVelocityDistance()
|
|
38
|
+
|
|
39
|
+
return {
|
|
40
|
+
velocity: velocityRef.current,
|
|
41
|
+
distance,
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
return {
|
|
46
|
+
getVelocity,
|
|
47
|
+
velocityTouchStart,
|
|
48
|
+
velocityTouchMove,
|
|
49
|
+
}
|
|
50
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
// Copyright 2026 The Lynx Authors. All rights reserved.
|
|
2
|
+
// Licensed under the Apache License Version 2.0 that can be found in the
|
|
3
|
+
// LICENSE file in the root directory of this source tree.
|
|
4
|
+
|
|
5
|
+
export { Swiper } from './Swiper'
|
|
6
|
+
export { SwiperItem } from './SwiperItem'
|
|
7
|
+
export type { SwiperItemProps } from './SwiperItem'
|
|
8
|
+
export type { SwiperProps, SwiperRef } from './types'
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
// Copyright 2026 The Lynx Authors. All rights reserved.
|
|
2
|
+
// Licensed under the Apache License Version 2.0 that can be found in the
|
|
3
|
+
// LICENSE file in the root directory of this source tree.
|
|
4
|
+
|
|
5
|
+
import { createContext } from '@lynx-js/react'
|
|
6
|
+
|
|
7
|
+
import { noop } from '@lynx-js/lynx-ui-common'
|
|
8
|
+
|
|
9
|
+
import type { SwiperContextProps } from '../types'
|
|
10
|
+
|
|
11
|
+
export const SwiperContext = createContext<SwiperContextProps>({
|
|
12
|
+
itemWidth: 350,
|
|
13
|
+
itemHeight: 'auto',
|
|
14
|
+
setChildrenRef: noop,
|
|
15
|
+
modeConfig: {
|
|
16
|
+
mode: 'normal',
|
|
17
|
+
align: 'start',
|
|
18
|
+
},
|
|
19
|
+
initialIndex: 0,
|
|
20
|
+
loop: false,
|
|
21
|
+
spaceBetween: 0,
|
|
22
|
+
RTL: false,
|
|
23
|
+
})
|