react-native-varia 0.5.2 → 0.6.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/lib/components/Accordion.tsx +55 -27
- package/lib/components/Badge.tsx +12 -6
- package/lib/components/Button.tsx +18 -6
- package/lib/components/Checkbox.tsx +22 -4
- package/lib/components/CircleProgress.tsx +7 -3
- package/lib/components/Divider.tsx +7 -3
- package/lib/components/Drawer.tsx +73 -25
- package/lib/components/Field.tsx +12 -6
- package/lib/components/FloatingAction.tsx +15 -4
- package/lib/components/GradientBackground.tsx +1 -1
- package/lib/components/GradientText.tsx +15 -5
- package/lib/components/IconWrapper.tsx +2 -2
- package/lib/components/Input.tsx +11 -6
- package/lib/components/Link.tsx +7 -7
- package/lib/components/Modal.tsx +42 -13
- package/lib/components/NumberInput.tsx +44 -23
- package/lib/components/RadioGroup.tsx +35 -6
- package/lib/components/ReText.tsx +1 -1
- package/lib/components/Select.tsx +61 -8
- package/lib/components/Slider.tsx +202 -200
- package/lib/components/Slideshow.tsx +12 -3
- package/lib/components/Switch.tsx +15 -3
- package/lib/components/Text.tsx +2 -2
- package/lib/components/Toast.tsx +14 -3
- package/lib/components/context/Field.tsx +2 -0
- package/lib/varia/types.ts +6 -0
- package/lib/varia/utils.ts +7 -0
- package/package.json +1 -1
|
@@ -1,15 +1,16 @@
|
|
|
1
1
|
import React from 'react'
|
|
2
|
-
import {type LayoutChangeEvent, View, ViewStyle} from 'react-native'
|
|
2
|
+
import {type LayoutChangeEvent, StyleProp, View, ViewStyle} from 'react-native'
|
|
3
3
|
import {StyleSheet, UnistylesVariants} from 'react-native-unistyles'
|
|
4
4
|
import {Gesture, GestureDetector} from 'react-native-gesture-handler'
|
|
5
5
|
import Animated, {
|
|
6
|
+
useAnimatedReaction,
|
|
6
7
|
useAnimatedStyle,
|
|
7
8
|
useSharedValue,
|
|
8
9
|
} from 'react-native-reanimated'
|
|
9
10
|
import {runOnJS} from 'react-native-worklets'
|
|
10
11
|
import {SliderStyles, SliderDefaultVariants} from '../../theme/Slider.recipe'
|
|
11
12
|
import {PalettesWithNestedKeys} from '../../style/varia/types'
|
|
12
|
-
import {getCompoundVariantValue} from '../../style/varia/utils'
|
|
13
|
+
import {getCompoundVariantValue, getVariantValue} from '../../style/varia/utils'
|
|
13
14
|
|
|
14
15
|
function throttle<T extends (...args: any[]) => any>(
|
|
15
16
|
func: T,
|
|
@@ -31,11 +32,6 @@ type SliderVariants = UnistylesVariants<typeof SliderStyles>
|
|
|
31
32
|
|
|
32
33
|
const AnimatedView = Animated.createAnimatedComponent(View)
|
|
33
34
|
|
|
34
|
-
type ThumbStyleExtended = ReturnType<typeof SliderStyles.thumb> & {
|
|
35
|
-
width: number
|
|
36
|
-
height: number
|
|
37
|
-
}
|
|
38
|
-
|
|
39
35
|
type SliderProps = SliderVariants & {
|
|
40
36
|
colorPalette?: PalettesWithNestedKeys
|
|
41
37
|
thickness?: number
|
|
@@ -48,10 +44,17 @@ type SliderProps = SliderVariants & {
|
|
|
48
44
|
thumbChildren?: React.ReactNode
|
|
49
45
|
steps?: number
|
|
50
46
|
value?: number
|
|
47
|
+
onSlidingStart?: (value: number) => void
|
|
51
48
|
onValueChange?: (value: number) => void
|
|
52
49
|
onSlidingComplete?: (value: number) => void
|
|
53
50
|
flex?: ViewStyle['flex']
|
|
54
51
|
alignSelf?: ViewStyle['alignSelf']
|
|
52
|
+
allowGestures?: boolean
|
|
53
|
+
mode?: 'normal' | 'wrap'
|
|
54
|
+
containerStyles?: StyleProp<ViewStyle>
|
|
55
|
+
maximumTrackStyles?: StyleProp<ViewStyle>
|
|
56
|
+
minimumTrackStyles?: StyleProp<ViewStyle>
|
|
57
|
+
thumbStyles?: StyleProp<ViewStyle>
|
|
55
58
|
}
|
|
56
59
|
|
|
57
60
|
const Slider = ({
|
|
@@ -62,10 +65,17 @@ const Slider = ({
|
|
|
62
65
|
axis = 'x',
|
|
63
66
|
value = 0,
|
|
64
67
|
steps,
|
|
68
|
+
onSlidingStart,
|
|
65
69
|
onValueChange,
|
|
66
70
|
onSlidingComplete,
|
|
67
71
|
flex = 0,
|
|
68
72
|
alignSelf = 'auto',
|
|
73
|
+
allowGestures = true,
|
|
74
|
+
mode = 'normal',
|
|
75
|
+
containerStyles,
|
|
76
|
+
maximumTrackStyles,
|
|
77
|
+
minimumTrackStyles,
|
|
78
|
+
thumbStyles,
|
|
69
79
|
}: SliderProps) => {
|
|
70
80
|
SliderStyles.useVariants({
|
|
71
81
|
size,
|
|
@@ -76,13 +86,13 @@ const Slider = ({
|
|
|
76
86
|
axis,
|
|
77
87
|
})
|
|
78
88
|
|
|
89
|
+
const normalizedValue = useSharedValue(0)
|
|
90
|
+
|
|
79
91
|
const throttledOnValueChange = React.useMemo(() => {
|
|
80
92
|
if (!onValueChange) return undefined
|
|
81
93
|
return throttle(onValueChange, 50)
|
|
82
94
|
}, [onValueChange])
|
|
83
95
|
|
|
84
|
-
// const thumbStyle = SliderStyles.thumb(colorPalette) as ThumbStyleExtended
|
|
85
|
-
// const thumbWidth = getVariantValue(SliderStyles.thumb(colorPalette), 'size', size, 'width', true)
|
|
86
96
|
const thumbWidth = getCompoundVariantValue(
|
|
87
97
|
SliderStyles.thumb(colorPalette),
|
|
88
98
|
{axis, size},
|
|
@@ -93,11 +103,24 @@ const Slider = ({
|
|
|
93
103
|
{axis, size},
|
|
94
104
|
'height',
|
|
95
105
|
)
|
|
96
|
-
|
|
106
|
+
|
|
107
|
+
const maximumTrackColor =
|
|
108
|
+
getVariantValue(
|
|
109
|
+
SliderStyles.maximumTrack(colorPalette),
|
|
110
|
+
'variant',
|
|
111
|
+
variant,
|
|
112
|
+
'backgroundColor',
|
|
113
|
+
) || 'transparent'
|
|
114
|
+
|
|
115
|
+
console.log(SliderStyles.maximumTrack(colorPalette))
|
|
97
116
|
|
|
98
117
|
const halfSize = ((axis === 'x' ? thumbWidth : thumbHeight) ?? 0) / 2
|
|
118
|
+
|
|
99
119
|
const context = useSharedValue({x: 0})
|
|
100
|
-
|
|
120
|
+
|
|
121
|
+
// ❗️CAMBIO 1: translate SIEMPRE en píxeles
|
|
122
|
+
const translate = useSharedValue(0)
|
|
123
|
+
|
|
101
124
|
const trackLength = useSharedValue(0)
|
|
102
125
|
const isInsideChild = useSharedValue(false)
|
|
103
126
|
|
|
@@ -106,229 +129,179 @@ const Slider = ({
|
|
|
106
129
|
trackLength.value = axis === 'x' ? width : height
|
|
107
130
|
}
|
|
108
131
|
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
132
|
+
// ❗️CAMBIO 2: sincronizar value → translate cuando hay layout
|
|
133
|
+
React.useEffect(() => {
|
|
134
|
+
if (trackLength.value <= 0) return
|
|
135
|
+
|
|
136
|
+
if (steps) {
|
|
137
|
+
const stepLength = trackLength.value / steps
|
|
138
|
+
translate.value = value * stepLength
|
|
139
|
+
} else {
|
|
140
|
+
translate.value = value * trackLength.value
|
|
141
|
+
}
|
|
142
|
+
}, [value, steps])
|
|
119
143
|
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
)
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
? Math.round(
|
|
127
|
-
: rawValue
|
|
128
|
-
|
|
129
|
-
translate.value = snappedValue
|
|
130
|
-
|
|
131
|
-
if (steps) {
|
|
132
|
-
const stepIndex = Math.round(snappedValue / stepLength)
|
|
133
|
-
throttledOnValueChange && runOnJS(throttledOnValueChange)(stepIndex)
|
|
134
|
-
} else {
|
|
135
|
-
throttledOnValueChange &&
|
|
136
|
-
runOnJS(throttledOnValueChange)(
|
|
137
|
-
Math.round((snappedValue / trackLength.value) * 100) / 100,
|
|
138
|
-
)
|
|
144
|
+
useAnimatedReaction(
|
|
145
|
+
() => normalizedValue.value,
|
|
146
|
+
(value, prev) => {
|
|
147
|
+
if (value === prev) return
|
|
148
|
+
|
|
149
|
+
if (onValueChange) {
|
|
150
|
+
runOnJS(onValueChange)(steps ? value : Math.round(value * 100) / 100)
|
|
139
151
|
}
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
|
|
152
|
+
},
|
|
153
|
+
[steps],
|
|
154
|
+
)
|
|
143
155
|
|
|
144
|
-
|
|
145
|
-
? Math.round(translate.value / stepLength)
|
|
146
|
-
: translate.value / trackLength.value
|
|
156
|
+
const isInteracting = useSharedValue(false)
|
|
147
157
|
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
.
|
|
151
|
-
|
|
152
|
-
})
|
|
158
|
+
const computeSnappedValue = (position: number) => {
|
|
159
|
+
'worklet'
|
|
160
|
+
const clamped = Math.max(0, Math.min(position, trackLength.value))
|
|
161
|
+
if (!steps) return clamped
|
|
153
162
|
|
|
154
|
-
|
|
155
|
-
.
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
.simultaneousWithExternalGesture(slideGesture)
|
|
163
|
+
const stepLength = trackLength.value / steps
|
|
164
|
+
return Math.round(clamped / stepLength) * stepLength
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
const toNormalizedValue = (px: number) => {
|
|
168
|
+
'worklet'
|
|
169
|
+
return steps
|
|
170
|
+
? Math.round(px / (trackLength.value / steps))
|
|
171
|
+
: px / trackLength.value
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
const beginInteraction = (value: number) => {
|
|
175
|
+
'worklet'
|
|
176
|
+
if (isInteracting.value) return
|
|
177
|
+
isInteracting.value = true
|
|
178
|
+
onSlidingStart && runOnJS(onSlidingStart)(value)
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
const updateInteraction = (value: number) => {
|
|
182
|
+
'worklet'
|
|
183
|
+
onValueChange && runOnJS(onValueChange)(value)
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
const endInteraction = (value: number) => {
|
|
187
|
+
'worklet'
|
|
188
|
+
if (!isInteracting.value) return
|
|
189
|
+
isInteracting.value = false
|
|
190
|
+
onSlidingComplete && runOnJS(onSlidingComplete)(value)
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
const panGesture = Gesture.Pan()
|
|
194
|
+
.enabled(allowGestures)
|
|
195
|
+
.minDistance(0)
|
|
188
196
|
|
|
189
|
-
const trackPan = Gesture.Pan()
|
|
190
197
|
.onBegin(e => {
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
0,
|
|
200
|
-
Math.min(trackLength.value - tapPosition, trackLength.value),
|
|
201
|
-
)
|
|
202
|
-
: Math.max(0, Math.min(tapPosition, trackLength.value))
|
|
203
|
-
|
|
204
|
-
const snappedValue = steps
|
|
205
|
-
? Math.round(rawValue / stepLength) * stepLength
|
|
206
|
-
: rawValue
|
|
207
|
-
|
|
208
|
-
context.value.x = snappedValue
|
|
209
|
-
translate.value = snappedValue
|
|
210
|
-
|
|
211
|
-
if (steps) {
|
|
212
|
-
const stepIndex = Math.round(snappedValue / stepLength)
|
|
213
|
-
onValueChange && runOnJS(onValueChange)(stepIndex)
|
|
214
|
-
} else {
|
|
215
|
-
const normalizedValue =
|
|
216
|
-
Math.round((snappedValue / trackLength.value) * 100) / 100
|
|
217
|
-
onValueChange && runOnJS(onValueChange)(normalizedValue)
|
|
218
|
-
}
|
|
198
|
+
const pos = axis === 'y' ? trackLength.value - e.y : e.x
|
|
199
|
+
const snapped = computeSnappedValue(pos)
|
|
200
|
+
|
|
201
|
+
context.value.x = snapped
|
|
202
|
+
translate.value = snapped
|
|
203
|
+
|
|
204
|
+
beginInteraction(toNormalizedValue(snapped))
|
|
205
|
+
updateInteraction(toNormalizedValue(snapped))
|
|
219
206
|
})
|
|
220
|
-
.onUpdate(e => {
|
|
221
|
-
if (trackLength.value <= 0) return
|
|
222
207
|
|
|
223
|
-
|
|
208
|
+
.onUpdate(e => {
|
|
224
209
|
const delta = axis === 'y' ? -e.translationY : e.translationX
|
|
210
|
+
const snapped = computeSnappedValue(context.value.x + delta)
|
|
225
211
|
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
Math.min(context.value.x + delta, trackLength.value),
|
|
229
|
-
)
|
|
230
|
-
|
|
231
|
-
if (steps) {
|
|
232
|
-
const snappedValue = Math.round(rawValue / stepLength) * stepLength
|
|
233
|
-
translate.value = snappedValue
|
|
234
|
-
|
|
235
|
-
const stepIndex = Math.round(snappedValue / stepLength)
|
|
236
|
-
throttledOnValueChange && runOnJS(throttledOnValueChange)(stepIndex)
|
|
237
|
-
} else {
|
|
238
|
-
translate.value = rawValue
|
|
239
|
-
throttledOnValueChange &&
|
|
240
|
-
runOnJS(throttledOnValueChange)(
|
|
241
|
-
Math.round((rawValue / trackLength.value) * 100) / 100,
|
|
242
|
-
)
|
|
243
|
-
}
|
|
212
|
+
translate.value = snapped
|
|
213
|
+
updateInteraction(toNormalizedValue(snapped))
|
|
244
214
|
})
|
|
245
|
-
.onEnd(() => {
|
|
246
|
-
const stepLength = steps ? trackLength.value / steps : 1
|
|
247
215
|
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
216
|
+
.onEnd(() => {
|
|
217
|
+
endInteraction(toNormalizedValue(translate.value))
|
|
218
|
+
})
|
|
251
219
|
|
|
252
|
-
|
|
220
|
+
.onFinalize(() => {
|
|
221
|
+
// 🔒 garantiza cleanup incluso en cancelaciones
|
|
222
|
+
endInteraction(toNormalizedValue(translate.value))
|
|
253
223
|
})
|
|
254
224
|
|
|
255
|
-
const animatedTrack = useAnimatedStyle(() => {
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
})
|
|
225
|
+
const animatedTrack = useAnimatedStyle(() => ({
|
|
226
|
+
[axis === 'y' ? 'height' : 'width']:
|
|
227
|
+
translate.value + (mode === 'wrap' ? halfSize : 0),
|
|
228
|
+
}))
|
|
260
229
|
|
|
261
230
|
const animatedThumb = useAnimatedStyle(() => {
|
|
262
231
|
if (axis === 'x') {
|
|
263
|
-
return {
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
const translateY = trackLength.value - translate.value - halfSize
|
|
268
|
-
return {
|
|
269
|
-
transform: [{translateY}],
|
|
270
|
-
}
|
|
232
|
+
return {transform: [{translateX: translate.value - halfSize}]}
|
|
233
|
+
}
|
|
234
|
+
return {
|
|
235
|
+
transform: [{translateY: trackLength.value - translate.value - halfSize}],
|
|
271
236
|
}
|
|
272
237
|
})
|
|
273
238
|
|
|
239
|
+
console.log('maximum color', maximumTrackColor)
|
|
240
|
+
|
|
274
241
|
return (
|
|
275
242
|
<View
|
|
276
243
|
testID="varia-slider-container"
|
|
277
244
|
style={[
|
|
278
|
-
styles.container(halfSize, flex, alignSelf),
|
|
279
245
|
SliderStyles.container(colorPalette),
|
|
246
|
+
containerStyles,
|
|
247
|
+
styles.container(
|
|
248
|
+
halfSize,
|
|
249
|
+
flex,
|
|
250
|
+
alignSelf,
|
|
251
|
+
mode === 'wrap' ? maximumTrackColor : 'transparent',
|
|
252
|
+
),
|
|
280
253
|
]}>
|
|
281
|
-
|
|
282
|
-
<GestureDetector gesture={Gesture.Simultaneous(trackPan, tapGesture)}>
|
|
254
|
+
<GestureDetector gesture={panGesture}>
|
|
283
255
|
<View
|
|
284
256
|
testID="varia-slider-maximun-track"
|
|
285
257
|
style={[
|
|
286
|
-
styles.maximumTrack(),
|
|
258
|
+
styles.maximumTrack(mode),
|
|
259
|
+
maximumTrackStyles,
|
|
287
260
|
SliderStyles.maximumTrack(colorPalette),
|
|
288
261
|
]}
|
|
289
262
|
onLayout={handleTrackLayout}>
|
|
290
263
|
<AnimatedView
|
|
291
264
|
testID="varia-slider-minimum-track"
|
|
292
265
|
style={[
|
|
293
|
-
styles.minimumTrack(halfSize),
|
|
294
266
|
SliderStyles.minimumTrack(colorPalette),
|
|
267
|
+
minimumTrackStyles,
|
|
268
|
+
styles.minimumTrack(halfSize, mode),
|
|
295
269
|
animatedTrack,
|
|
296
270
|
]}
|
|
297
271
|
/>
|
|
298
272
|
|
|
299
273
|
{steps && (
|
|
300
|
-
<View style={
|
|
301
|
-
<View style={styles.steps}
|
|
302
|
-
{Array.from({length: steps + 1}, (_,
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
),
|
|
312
|
-
)}
|
|
274
|
+
<View style={styles.stepsOverlay} pointerEvents="none">
|
|
275
|
+
<View style={styles.steps}>
|
|
276
|
+
{Array.from({length: steps + 1}, (_, i) => (
|
|
277
|
+
<View
|
|
278
|
+
key={i}
|
|
279
|
+
style={[
|
|
280
|
+
styles.step(i, steps),
|
|
281
|
+
SliderStyles.step(colorPalette),
|
|
282
|
+
]}
|
|
283
|
+
/>
|
|
284
|
+
))}
|
|
313
285
|
</View>
|
|
314
286
|
</View>
|
|
315
287
|
)}
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
</
|
|
327
|
-
</
|
|
328
|
-
</
|
|
288
|
+
|
|
289
|
+
<View style={styles.thumbContainerFull}>
|
|
290
|
+
<AnimatedView style={[animatedThumb, styles.thumbContainer]}>
|
|
291
|
+
<View
|
|
292
|
+
style={[
|
|
293
|
+
SliderStyles.thumb(colorPalette),
|
|
294
|
+
thumbStyles,
|
|
295
|
+
styles.thumb(halfSize),
|
|
296
|
+
]}>
|
|
297
|
+
{ThumbChildren || null}
|
|
298
|
+
</View>
|
|
299
|
+
</AnimatedView>
|
|
300
|
+
</View>
|
|
301
|
+
{/* <GestureDetector gesture={slideGesture}>
|
|
302
|
+
</GestureDetector> */}
|
|
329
303
|
</View>
|
|
330
304
|
</GestureDetector>
|
|
331
|
-
{axis === 'y' && <View style={{height: halfSize}} />}
|
|
332
305
|
</View>
|
|
333
306
|
)
|
|
334
307
|
}
|
|
@@ -338,23 +311,28 @@ const styles = StyleSheet.create(theme => ({
|
|
|
338
311
|
halfSize: number,
|
|
339
312
|
flex: ViewStyle['flex'],
|
|
340
313
|
alignSelf: ViewStyle['alignSelf'],
|
|
314
|
+
backgroundColor: ViewStyle['backgroundColor'],
|
|
341
315
|
) => ({
|
|
342
316
|
flex,
|
|
343
317
|
alignSelf,
|
|
344
318
|
overflow: 'hidden',
|
|
319
|
+
backgroundColor,
|
|
320
|
+
alignItems: 'center',
|
|
345
321
|
// flexBasis: 'auto',
|
|
346
322
|
variants: {
|
|
347
323
|
axis: {
|
|
348
324
|
x: {
|
|
349
325
|
// maxWidth: 'auto',
|
|
350
326
|
paddingTop: 0,
|
|
351
|
-
paddingRight: halfSize,
|
|
327
|
+
// paddingRight: halfSize,
|
|
328
|
+
paddingHorizontal: halfSize,
|
|
352
329
|
flexDirection: 'row',
|
|
353
330
|
},
|
|
354
331
|
y: {
|
|
355
332
|
// maxHeight: 'auto',
|
|
356
333
|
// height: '100%',
|
|
357
|
-
paddingTop: halfSize,
|
|
334
|
+
// paddingTop: halfSize,
|
|
335
|
+
paddingVertical: halfSize,
|
|
358
336
|
paddingRight: 0,
|
|
359
337
|
flexDirection: 'column',
|
|
360
338
|
},
|
|
@@ -365,7 +343,7 @@ const styles = StyleSheet.create(theme => ({
|
|
|
365
343
|
flex: flex === 0 ? undefined : flex,
|
|
366
344
|
},
|
|
367
345
|
}),
|
|
368
|
-
maximumTrack: () => ({
|
|
346
|
+
maximumTrack: (mode: 'normal' | 'wrap') => ({
|
|
369
347
|
flex: 1,
|
|
370
348
|
position: 'relative',
|
|
371
349
|
overflow: 'visible',
|
|
@@ -373,10 +351,14 @@ const styles = StyleSheet.create(theme => ({
|
|
|
373
351
|
variants: {
|
|
374
352
|
axis: {
|
|
375
353
|
x: {
|
|
354
|
+
...(mode === 'wrap' ? {height: '100%'} : {}),
|
|
376
355
|
justifyContent: 'center',
|
|
377
356
|
},
|
|
378
357
|
y: {
|
|
379
|
-
|
|
358
|
+
...(mode === 'wrap' ? {width: '100%'} : {}),
|
|
359
|
+
flexDirection: 'row',
|
|
360
|
+
justifyContent: 'center',
|
|
361
|
+
alignItems: 'flex-end',
|
|
380
362
|
},
|
|
381
363
|
},
|
|
382
364
|
},
|
|
@@ -384,26 +366,31 @@ const styles = StyleSheet.create(theme => ({
|
|
|
384
366
|
_classNames: 'slider-maximun-track-base',
|
|
385
367
|
},
|
|
386
368
|
}),
|
|
387
|
-
minimumTrack: (halfSize: number) => ({
|
|
369
|
+
minimumTrack: (halfSize: number, mode) => ({
|
|
388
370
|
flexBasis: 'auto',
|
|
389
371
|
variants: {
|
|
390
372
|
axis: {
|
|
391
373
|
x: {
|
|
392
|
-
flex: 1,
|
|
393
|
-
marginLeft: halfSize * -1,
|
|
374
|
+
// flex: 1,
|
|
375
|
+
// marginLeft: halfSize * -1,
|
|
394
376
|
width: '100%',
|
|
395
377
|
bottom: 'auto',
|
|
396
378
|
paddingBottom: 0,
|
|
397
|
-
paddingLeft: halfSize,
|
|
379
|
+
// paddingLeft: halfSize,
|
|
398
380
|
justifyContent: 'center',
|
|
399
381
|
alignItems: 'flex-end',
|
|
382
|
+
...(mode === 'wrap'
|
|
383
|
+
? {transform: [{translateX: halfSize * -1}]}
|
|
384
|
+
: {}),
|
|
400
385
|
},
|
|
401
386
|
y: {
|
|
387
|
+
// flex: 1,
|
|
402
388
|
height: '100%',
|
|
403
|
-
paddingBottom: halfSize,
|
|
404
|
-
marginBottom: halfSize * -1,
|
|
389
|
+
// paddingBottom: halfSize,
|
|
390
|
+
// marginBottom: halfSize * -1,
|
|
405
391
|
paddingLeft: 0,
|
|
406
392
|
alignItems: 'flex-start',
|
|
393
|
+
...(mode === 'wrap' ? {transform: [{translateY: halfSize}]} : {}),
|
|
407
394
|
},
|
|
408
395
|
},
|
|
409
396
|
},
|
|
@@ -412,6 +399,7 @@ const styles = StyleSheet.create(theme => ({
|
|
|
412
399
|
},
|
|
413
400
|
}),
|
|
414
401
|
thumbContainerFull: {
|
|
402
|
+
// overflow: 'hidden',
|
|
415
403
|
position: 'absolute',
|
|
416
404
|
left: 0,
|
|
417
405
|
right: 0,
|
|
@@ -422,18 +410,33 @@ const styles = StyleSheet.create(theme => ({
|
|
|
422
410
|
_classNames: 'thumb-container-full-base',
|
|
423
411
|
},
|
|
424
412
|
},
|
|
425
|
-
|
|
413
|
+
thumbContainer: {
|
|
414
|
+
flex: 1,
|
|
426
415
|
variants: {
|
|
427
416
|
axis: {
|
|
428
417
|
x: {
|
|
429
|
-
height: '100%',
|
|
430
418
|
justifyContent: 'center',
|
|
419
|
+
},
|
|
420
|
+
y: {
|
|
431
421
|
alignItems: 'center',
|
|
432
422
|
},
|
|
423
|
+
},
|
|
424
|
+
},
|
|
425
|
+
},
|
|
426
|
+
thumb: (halfSize: number) => ({
|
|
427
|
+
variants: {
|
|
428
|
+
axis: {
|
|
429
|
+
x: {
|
|
430
|
+
// height: '100%',
|
|
431
|
+
justifyContent: 'center',
|
|
432
|
+
alignItems: 'center',
|
|
433
|
+
// transform: [{translateX: halfSize * -1}],
|
|
434
|
+
},
|
|
433
435
|
y: {
|
|
434
|
-
width: '100%',
|
|
436
|
+
// width: '100%',
|
|
435
437
|
justifyContent: 'center',
|
|
436
438
|
alignItems: 'center',
|
|
439
|
+
// transform: [{translateY: halfSize * -1}],
|
|
437
440
|
},
|
|
438
441
|
},
|
|
439
442
|
},
|
|
@@ -494,5 +497,4 @@ const styles = StyleSheet.create(theme => ({
|
|
|
494
497
|
},
|
|
495
498
|
}),
|
|
496
499
|
}))
|
|
497
|
-
|
|
498
500
|
export default Slider
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import {Children, type ReactNode, useImperativeHandle, useState} from 'react'
|
|
2
|
-
import {View} from 'react-native'
|
|
2
|
+
import {StyleProp, View, ViewStyle} from 'react-native'
|
|
3
3
|
import Animated, {
|
|
4
4
|
useAnimatedReaction,
|
|
5
5
|
useAnimatedStyle,
|
|
@@ -32,6 +32,8 @@ type SlideshowProps = SlideshowVariants & {
|
|
|
32
32
|
onSlideChange?: (index: number) => void
|
|
33
33
|
children: ReactNode
|
|
34
34
|
ref?: React.RefObject<SlideshowRef | null>
|
|
35
|
+
containerStyles?: StyleProp<ViewStyle>
|
|
36
|
+
slideContainerStyles?: StyleProp<ViewStyle>
|
|
35
37
|
}
|
|
36
38
|
|
|
37
39
|
const Slideshow = ({
|
|
@@ -44,6 +46,8 @@ const Slideshow = ({
|
|
|
44
46
|
animation = SlideshowTokens.defaultProps.animation,
|
|
45
47
|
children,
|
|
46
48
|
ref,
|
|
49
|
+
containerStyles,
|
|
50
|
+
slideContainerStyles,
|
|
47
51
|
}: SlideshowProps) => {
|
|
48
52
|
const isHorizontal = axis === 'x'
|
|
49
53
|
|
|
@@ -171,7 +175,11 @@ const Slideshow = ({
|
|
|
171
175
|
<GestureDetector gesture={slideGesture}>
|
|
172
176
|
<View
|
|
173
177
|
testID="varia-slideshow"
|
|
174
|
-
style={[
|
|
178
|
+
style={[
|
|
179
|
+
SlideshowStyles.container(colorPalette),
|
|
180
|
+
containerStyles,
|
|
181
|
+
styles.container(),
|
|
182
|
+
]}
|
|
175
183
|
onLayout={e => {
|
|
176
184
|
setContainerWidth(e.nativeEvent.layout.width)
|
|
177
185
|
setContainerHeight(e.nativeEvent.layout.height)
|
|
@@ -186,8 +194,9 @@ const Slideshow = ({
|
|
|
186
194
|
testID={`varia-slides-slide-${index}`}
|
|
187
195
|
key={index}
|
|
188
196
|
style={[
|
|
189
|
-
styles.slide(`${slideSize}%`, isHorizontal),
|
|
190
197
|
SlideshowStyles.slideContainer(colorPalette),
|
|
198
|
+
slideContainerStyles,
|
|
199
|
+
styles.slide(`${slideSize}%`, isHorizontal),
|
|
191
200
|
]}>
|
|
192
201
|
{Slide}
|
|
193
202
|
</View>
|