react-native-varia 0.5.2 → 0.6.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/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 +91 -47
- 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 +198 -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/theme/Accordion.recipe.tsx +48 -0
- package/lib/theme/Drawer.recipe.tsx +1 -0
- package/lib/theme/Slider.recipe.tsx +143 -399
- 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,22 @@ 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'
|
|
97
114
|
|
|
98
115
|
const halfSize = ((axis === 'x' ? thumbWidth : thumbHeight) ?? 0) / 2
|
|
116
|
+
|
|
99
117
|
const context = useSharedValue({x: 0})
|
|
100
|
-
|
|
118
|
+
|
|
119
|
+
// ❗️CAMBIO 1: translate SIEMPRE en píxeles
|
|
120
|
+
const translate = useSharedValue(0)
|
|
121
|
+
|
|
101
122
|
const trackLength = useSharedValue(0)
|
|
102
123
|
const isInsideChild = useSharedValue(false)
|
|
103
124
|
|
|
@@ -106,168 +127,110 @@ const Slider = ({
|
|
|
106
127
|
trackLength.value = axis === 'x' ? width : height
|
|
107
128
|
}
|
|
108
129
|
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
130
|
+
// ❗️CAMBIO 2: sincronizar value → translate cuando hay layout
|
|
131
|
+
React.useEffect(() => {
|
|
132
|
+
if (trackLength.value <= 0) return
|
|
133
|
+
|
|
134
|
+
if (steps) {
|
|
135
|
+
const stepLength = trackLength.value / steps
|
|
136
|
+
translate.value = value * stepLength
|
|
137
|
+
} else {
|
|
138
|
+
translate.value = value * trackLength.value
|
|
139
|
+
}
|
|
140
|
+
}, [value, steps])
|
|
141
|
+
|
|
142
|
+
useAnimatedReaction(
|
|
143
|
+
() => normalizedValue.value,
|
|
144
|
+
(value, prev) => {
|
|
145
|
+
if (value === prev) return
|
|
119
146
|
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
Math.min(context.value.x + delta, trackLength.value),
|
|
123
|
-
)
|
|
124
|
-
|
|
125
|
-
const snappedValue = steps
|
|
126
|
-
? Math.round(rawValue / stepLength) * stepLength
|
|
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
|
-
)
|
|
147
|
+
if (onValueChange) {
|
|
148
|
+
runOnJS(onValueChange)(steps ? value : Math.round(value * 100) / 100)
|
|
139
149
|
}
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
|
|
150
|
+
},
|
|
151
|
+
[steps],
|
|
152
|
+
)
|
|
143
153
|
|
|
144
|
-
|
|
145
|
-
? Math.round(translate.value / stepLength)
|
|
146
|
-
: translate.value / trackLength.value
|
|
154
|
+
const isInteracting = useSharedValue(false)
|
|
147
155
|
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
.
|
|
151
|
-
|
|
152
|
-
})
|
|
156
|
+
const computeSnappedValue = (position: number) => {
|
|
157
|
+
'worklet'
|
|
158
|
+
const clamped = Math.max(0, Math.min(position, trackLength.value))
|
|
159
|
+
if (!steps) return clamped
|
|
153
160
|
|
|
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)
|
|
161
|
+
const stepLength = trackLength.value / steps
|
|
162
|
+
return Math.round(clamped / stepLength) * stepLength
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
const toNormalizedValue = (px: number) => {
|
|
166
|
+
'worklet'
|
|
167
|
+
return steps
|
|
168
|
+
? Math.round(px / (trackLength.value / steps))
|
|
169
|
+
: px / trackLength.value
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
const beginInteraction = (value: number) => {
|
|
173
|
+
'worklet'
|
|
174
|
+
if (isInteracting.value) return
|
|
175
|
+
isInteracting.value = true
|
|
176
|
+
onSlidingStart && runOnJS(onSlidingStart)(value)
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
const updateInteraction = (value: number) => {
|
|
180
|
+
'worklet'
|
|
181
|
+
onValueChange && runOnJS(onValueChange)(value)
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
const endInteraction = (value: number) => {
|
|
185
|
+
'worklet'
|
|
186
|
+
if (!isInteracting.value) return
|
|
187
|
+
isInteracting.value = false
|
|
188
|
+
onSlidingComplete && runOnJS(onSlidingComplete)(value)
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
const panGesture = Gesture.Pan()
|
|
192
|
+
.enabled(allowGestures)
|
|
193
|
+
.minDistance(0)
|
|
188
194
|
|
|
189
|
-
const trackPan = Gesture.Pan()
|
|
190
195
|
.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
|
-
}
|
|
196
|
+
const pos = axis === 'y' ? trackLength.value - e.y : e.x
|
|
197
|
+
const snapped = computeSnappedValue(pos)
|
|
198
|
+
|
|
199
|
+
context.value.x = snapped
|
|
200
|
+
translate.value = snapped
|
|
201
|
+
|
|
202
|
+
beginInteraction(toNormalizedValue(snapped))
|
|
203
|
+
updateInteraction(toNormalizedValue(snapped))
|
|
219
204
|
})
|
|
220
|
-
.onUpdate(e => {
|
|
221
|
-
if (trackLength.value <= 0) return
|
|
222
205
|
|
|
223
|
-
|
|
206
|
+
.onUpdate(e => {
|
|
224
207
|
const delta = axis === 'y' ? -e.translationY : e.translationX
|
|
208
|
+
const snapped = computeSnappedValue(context.value.x + delta)
|
|
225
209
|
|
|
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
|
-
}
|
|
210
|
+
translate.value = snapped
|
|
211
|
+
updateInteraction(toNormalizedValue(snapped))
|
|
244
212
|
})
|
|
245
|
-
.onEnd(() => {
|
|
246
|
-
const stepLength = steps ? trackLength.value / steps : 1
|
|
247
213
|
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
214
|
+
.onEnd(() => {
|
|
215
|
+
endInteraction(toNormalizedValue(translate.value))
|
|
216
|
+
})
|
|
251
217
|
|
|
252
|
-
|
|
218
|
+
.onFinalize(() => {
|
|
219
|
+
// 🔒 garantiza cleanup incluso en cancelaciones
|
|
220
|
+
endInteraction(toNormalizedValue(translate.value))
|
|
253
221
|
})
|
|
254
222
|
|
|
255
|
-
const animatedTrack = useAnimatedStyle(() => {
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
})
|
|
223
|
+
const animatedTrack = useAnimatedStyle(() => ({
|
|
224
|
+
[axis === 'y' ? 'height' : 'width']:
|
|
225
|
+
translate.value + (mode === 'wrap' ? halfSize : 0),
|
|
226
|
+
}))
|
|
260
227
|
|
|
261
228
|
const animatedThumb = useAnimatedStyle(() => {
|
|
262
229
|
if (axis === 'x') {
|
|
263
|
-
return {
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
const translateY = trackLength.value - translate.value - halfSize
|
|
268
|
-
return {
|
|
269
|
-
transform: [{translateY}],
|
|
270
|
-
}
|
|
230
|
+
return {transform: [{translateX: translate.value - halfSize}]}
|
|
231
|
+
}
|
|
232
|
+
return {
|
|
233
|
+
transform: [{translateY: trackLength.value - translate.value - halfSize}],
|
|
271
234
|
}
|
|
272
235
|
})
|
|
273
236
|
|
|
@@ -275,60 +238,66 @@ const Slider = ({
|
|
|
275
238
|
<View
|
|
276
239
|
testID="varia-slider-container"
|
|
277
240
|
style={[
|
|
278
|
-
styles.container(halfSize, flex, alignSelf),
|
|
279
241
|
SliderStyles.container(colorPalette),
|
|
242
|
+
containerStyles,
|
|
243
|
+
styles.container(
|
|
244
|
+
halfSize,
|
|
245
|
+
flex,
|
|
246
|
+
alignSelf,
|
|
247
|
+
mode === 'wrap' ? maximumTrackColor : 'transparent',
|
|
248
|
+
),
|
|
280
249
|
]}>
|
|
281
|
-
|
|
282
|
-
<GestureDetector gesture={Gesture.Simultaneous(trackPan, tapGesture)}>
|
|
250
|
+
<GestureDetector gesture={panGesture}>
|
|
283
251
|
<View
|
|
284
252
|
testID="varia-slider-maximun-track"
|
|
285
253
|
style={[
|
|
286
|
-
styles.maximumTrack(),
|
|
254
|
+
styles.maximumTrack(mode),
|
|
255
|
+
maximumTrackStyles,
|
|
287
256
|
SliderStyles.maximumTrack(colorPalette),
|
|
288
257
|
]}
|
|
289
258
|
onLayout={handleTrackLayout}>
|
|
290
259
|
<AnimatedView
|
|
291
260
|
testID="varia-slider-minimum-track"
|
|
292
261
|
style={[
|
|
293
|
-
styles.minimumTrack(halfSize),
|
|
294
262
|
SliderStyles.minimumTrack(colorPalette),
|
|
263
|
+
minimumTrackStyles,
|
|
264
|
+
styles.minimumTrack(halfSize, mode),
|
|
295
265
|
animatedTrack,
|
|
296
266
|
]}
|
|
297
267
|
/>
|
|
298
268
|
|
|
299
269
|
{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
|
-
)}
|
|
270
|
+
<View style={styles.stepsOverlay} pointerEvents="none">
|
|
271
|
+
<View style={styles.steps}>
|
|
272
|
+
{Array.from({length: steps + 1}, (_, i) => (
|
|
273
|
+
<View
|
|
274
|
+
key={i}
|
|
275
|
+
style={[
|
|
276
|
+
styles.step(i, steps),
|
|
277
|
+
SliderStyles.step(colorPalette),
|
|
278
|
+
]}
|
|
279
|
+
/>
|
|
280
|
+
))}
|
|
313
281
|
</View>
|
|
314
282
|
</View>
|
|
315
283
|
)}
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
</
|
|
327
|
-
</
|
|
328
|
-
</
|
|
284
|
+
|
|
285
|
+
<View style={styles.thumbContainerFull}>
|
|
286
|
+
<AnimatedView style={[animatedThumb, styles.thumbContainer]}>
|
|
287
|
+
<View
|
|
288
|
+
style={[
|
|
289
|
+
SliderStyles.thumb(colorPalette),
|
|
290
|
+
thumbStyles,
|
|
291
|
+
styles.thumb(halfSize),
|
|
292
|
+
]}>
|
|
293
|
+
{ThumbChildren || null}
|
|
294
|
+
</View>
|
|
295
|
+
</AnimatedView>
|
|
296
|
+
</View>
|
|
297
|
+
{/* <GestureDetector gesture={slideGesture}>
|
|
298
|
+
</GestureDetector> */}
|
|
329
299
|
</View>
|
|
330
300
|
</GestureDetector>
|
|
331
|
-
{axis === 'y' && <View style={{height: halfSize}} />}
|
|
332
301
|
</View>
|
|
333
302
|
)
|
|
334
303
|
}
|
|
@@ -338,23 +307,28 @@ const styles = StyleSheet.create(theme => ({
|
|
|
338
307
|
halfSize: number,
|
|
339
308
|
flex: ViewStyle['flex'],
|
|
340
309
|
alignSelf: ViewStyle['alignSelf'],
|
|
310
|
+
backgroundColor: ViewStyle['backgroundColor'],
|
|
341
311
|
) => ({
|
|
342
312
|
flex,
|
|
343
313
|
alignSelf,
|
|
344
314
|
overflow: 'hidden',
|
|
315
|
+
backgroundColor,
|
|
316
|
+
alignItems: 'center',
|
|
345
317
|
// flexBasis: 'auto',
|
|
346
318
|
variants: {
|
|
347
319
|
axis: {
|
|
348
320
|
x: {
|
|
349
321
|
// maxWidth: 'auto',
|
|
350
322
|
paddingTop: 0,
|
|
351
|
-
paddingRight: halfSize,
|
|
323
|
+
// paddingRight: halfSize,
|
|
324
|
+
paddingHorizontal: halfSize,
|
|
352
325
|
flexDirection: 'row',
|
|
353
326
|
},
|
|
354
327
|
y: {
|
|
355
328
|
// maxHeight: 'auto',
|
|
356
329
|
// height: '100%',
|
|
357
|
-
paddingTop: halfSize,
|
|
330
|
+
// paddingTop: halfSize,
|
|
331
|
+
paddingVertical: halfSize,
|
|
358
332
|
paddingRight: 0,
|
|
359
333
|
flexDirection: 'column',
|
|
360
334
|
},
|
|
@@ -365,7 +339,7 @@ const styles = StyleSheet.create(theme => ({
|
|
|
365
339
|
flex: flex === 0 ? undefined : flex,
|
|
366
340
|
},
|
|
367
341
|
}),
|
|
368
|
-
maximumTrack: () => ({
|
|
342
|
+
maximumTrack: (mode: 'normal' | 'wrap') => ({
|
|
369
343
|
flex: 1,
|
|
370
344
|
position: 'relative',
|
|
371
345
|
overflow: 'visible',
|
|
@@ -373,10 +347,14 @@ const styles = StyleSheet.create(theme => ({
|
|
|
373
347
|
variants: {
|
|
374
348
|
axis: {
|
|
375
349
|
x: {
|
|
350
|
+
...(mode === 'wrap' ? {height: '100%'} : {}),
|
|
376
351
|
justifyContent: 'center',
|
|
377
352
|
},
|
|
378
353
|
y: {
|
|
379
|
-
|
|
354
|
+
...(mode === 'wrap' ? {width: '100%'} : {}),
|
|
355
|
+
flexDirection: 'row',
|
|
356
|
+
justifyContent: 'center',
|
|
357
|
+
alignItems: 'flex-end',
|
|
380
358
|
},
|
|
381
359
|
},
|
|
382
360
|
},
|
|
@@ -384,26 +362,31 @@ const styles = StyleSheet.create(theme => ({
|
|
|
384
362
|
_classNames: 'slider-maximun-track-base',
|
|
385
363
|
},
|
|
386
364
|
}),
|
|
387
|
-
minimumTrack: (halfSize: number) => ({
|
|
365
|
+
minimumTrack: (halfSize: number, mode) => ({
|
|
388
366
|
flexBasis: 'auto',
|
|
389
367
|
variants: {
|
|
390
368
|
axis: {
|
|
391
369
|
x: {
|
|
392
|
-
flex: 1,
|
|
393
|
-
marginLeft: halfSize * -1,
|
|
370
|
+
// flex: 1,
|
|
371
|
+
// marginLeft: halfSize * -1,
|
|
394
372
|
width: '100%',
|
|
395
373
|
bottom: 'auto',
|
|
396
374
|
paddingBottom: 0,
|
|
397
|
-
paddingLeft: halfSize,
|
|
375
|
+
// paddingLeft: halfSize,
|
|
398
376
|
justifyContent: 'center',
|
|
399
377
|
alignItems: 'flex-end',
|
|
378
|
+
...(mode === 'wrap'
|
|
379
|
+
? {transform: [{translateX: halfSize * -1}]}
|
|
380
|
+
: {}),
|
|
400
381
|
},
|
|
401
382
|
y: {
|
|
383
|
+
// flex: 1,
|
|
402
384
|
height: '100%',
|
|
403
|
-
paddingBottom: halfSize,
|
|
404
|
-
marginBottom: halfSize * -1,
|
|
385
|
+
// paddingBottom: halfSize,
|
|
386
|
+
// marginBottom: halfSize * -1,
|
|
405
387
|
paddingLeft: 0,
|
|
406
388
|
alignItems: 'flex-start',
|
|
389
|
+
...(mode === 'wrap' ? {transform: [{translateY: halfSize}]} : {}),
|
|
407
390
|
},
|
|
408
391
|
},
|
|
409
392
|
},
|
|
@@ -412,6 +395,7 @@ const styles = StyleSheet.create(theme => ({
|
|
|
412
395
|
},
|
|
413
396
|
}),
|
|
414
397
|
thumbContainerFull: {
|
|
398
|
+
// overflow: 'hidden',
|
|
415
399
|
position: 'absolute',
|
|
416
400
|
left: 0,
|
|
417
401
|
right: 0,
|
|
@@ -422,18 +406,33 @@ const styles = StyleSheet.create(theme => ({
|
|
|
422
406
|
_classNames: 'thumb-container-full-base',
|
|
423
407
|
},
|
|
424
408
|
},
|
|
425
|
-
|
|
409
|
+
thumbContainer: {
|
|
410
|
+
flex: 1,
|
|
426
411
|
variants: {
|
|
427
412
|
axis: {
|
|
428
413
|
x: {
|
|
429
|
-
height: '100%',
|
|
430
414
|
justifyContent: 'center',
|
|
415
|
+
},
|
|
416
|
+
y: {
|
|
431
417
|
alignItems: 'center',
|
|
432
418
|
},
|
|
419
|
+
},
|
|
420
|
+
},
|
|
421
|
+
},
|
|
422
|
+
thumb: (halfSize: number) => ({
|
|
423
|
+
variants: {
|
|
424
|
+
axis: {
|
|
425
|
+
x: {
|
|
426
|
+
// height: '100%',
|
|
427
|
+
justifyContent: 'center',
|
|
428
|
+
alignItems: 'center',
|
|
429
|
+
// transform: [{translateX: halfSize * -1}],
|
|
430
|
+
},
|
|
433
431
|
y: {
|
|
434
|
-
width: '100%',
|
|
432
|
+
// width: '100%',
|
|
435
433
|
justifyContent: 'center',
|
|
436
434
|
alignItems: 'center',
|
|
435
|
+
// transform: [{translateY: halfSize * -1}],
|
|
437
436
|
},
|
|
438
437
|
},
|
|
439
438
|
},
|
|
@@ -494,5 +493,4 @@ const styles = StyleSheet.create(theme => ({
|
|
|
494
493
|
},
|
|
495
494
|
}),
|
|
496
495
|
}))
|
|
497
|
-
|
|
498
496
|
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>
|