react-native-varia 0.3.0 → 0.4.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 +61 -21
- package/lib/components/Badge.tsx +9 -0
- package/lib/components/Button.tsx +19 -8
- package/lib/components/Checkbox.tsx +21 -12
- package/lib/components/CircleProgress.tsx +8 -0
- package/lib/components/Divider.tsx +6 -0
- package/lib/components/Drawer.tsx +16 -4
- package/lib/components/Field.tsx +4 -0
- package/lib/components/FloatingAction.tsx +215 -0
- package/lib/components/GradientBackground.tsx +3 -0
- package/lib/components/GradientText.tsx +27 -14
- package/lib/components/IconWrapper.tsx +4 -3
- package/lib/components/Input.tsx +47 -21
- package/lib/components/Link.tsx +4 -0
- package/lib/components/Modal.tsx +18 -5
- package/lib/components/NumberInput.tsx +27 -5
- package/lib/components/RadioGroup.tsx +16 -5
- package/lib/components/ReText.tsx +4 -1
- package/lib/components/Select.tsx +20 -0
- package/lib/components/Slider.tsx +59 -23
- package/lib/components/Slideshow.tsx +19 -3
- package/lib/components/Spinner.tsx +9 -3
- package/lib/components/Switch.tsx +57 -26
- package/lib/components/Text.tsx +3 -0
- package/lib/components/Toast.tsx +110 -36
- package/lib/patterns/index.tsx +299 -90
- package/lib/theme/Accordion.tsx +184 -0
- package/lib/theme/Button.recipe.tsx +24 -7
- package/lib/theme/Drawer.recipe.tsx +2 -4
- package/lib/theme/Field.recipe.tsx +45 -15
- package/lib/theme/FloatingAction.tsx +112 -0
- package/lib/theme/GradientText.recipe.tsx +103 -34
- package/lib/theme/Input.recipe.tsx +14 -6
- package/lib/theme/Select.recipe.tsx +3 -0
- package/lib/theme/Slider.recipe.tsx +86 -150
- package/lib/theme/Spinner.recipe.tsx +4 -0
- package/lib/theme/Switch.recipe.tsx +19 -0
- package/lib/theme/Text.recipe.tsx +63 -12
- package/lib/theme/Toast.recipe.tsx +40 -7
- package/lib/varia/types.ts +3 -0
- package/lib/varia/utils.ts +110 -18
- package/package.json +1 -1
- package/lib/components/OldSlider.tsx +0 -327
- package/lib/components/SlidingDrawer.tsx +0 -301
- package/lib/patterns/newPatterns.tsx +0 -285
|
@@ -9,6 +9,7 @@ import Animated, {
|
|
|
9
9
|
import {runOnJS} from 'react-native-worklets'
|
|
10
10
|
import {SliderStyles, SliderDefaultVariants} from '../theme/Slider.recipe'
|
|
11
11
|
import {PalettesWithNestedKeys} from '../style/varia/types'
|
|
12
|
+
import {getCompoundVariantValue} from '../style/varia/utils'
|
|
12
13
|
|
|
13
14
|
function throttle<T extends (...args: any[]) => any>(
|
|
14
15
|
func: T,
|
|
@@ -28,6 +29,8 @@ function throttle<T extends (...args: any[]) => any>(
|
|
|
28
29
|
|
|
29
30
|
type SliderVariants = UnistylesVariants<typeof SliderStyles>
|
|
30
31
|
|
|
32
|
+
const AnimatedView = Animated.createAnimatedComponent(View)
|
|
33
|
+
|
|
31
34
|
type ThumbStyleExtended = ReturnType<typeof SliderStyles.thumb> & {
|
|
32
35
|
width: number
|
|
33
36
|
height: number
|
|
@@ -38,7 +41,6 @@ type SliderProps = SliderVariants & {
|
|
|
38
41
|
thickness?: number
|
|
39
42
|
minimumTrackThickness?: number
|
|
40
43
|
minimumTrackColor?: string
|
|
41
|
-
displayStepsOnMinimumTrack?: boolean
|
|
42
44
|
thumbSize?: {
|
|
43
45
|
width: number
|
|
44
46
|
height: number
|
|
@@ -56,7 +58,6 @@ const Slider = ({
|
|
|
56
58
|
colorPalette = 'accent',
|
|
57
59
|
variant = SliderDefaultVariants.variant,
|
|
58
60
|
size = SliderDefaultVariants.size,
|
|
59
|
-
displayStepsOnMinimumTrack = false,
|
|
60
61
|
thumbChildren: ThumbChildren,
|
|
61
62
|
axis = 'x',
|
|
62
63
|
value = 0,
|
|
@@ -80,10 +81,21 @@ const Slider = ({
|
|
|
80
81
|
return throttle(onValueChange, 50)
|
|
81
82
|
}, [onValueChange])
|
|
82
83
|
|
|
83
|
-
const thumbStyle = SliderStyles.thumb(colorPalette) as ThumbStyleExtended
|
|
84
|
+
// const thumbStyle = SliderStyles.thumb(colorPalette) as ThumbStyleExtended
|
|
85
|
+
// const thumbWidth = getVariantValue(SliderStyles.thumb(colorPalette), 'size', size, 'width', true)
|
|
86
|
+
const thumbWidth = getCompoundVariantValue(
|
|
87
|
+
SliderStyles.thumb(colorPalette),
|
|
88
|
+
{axis, size},
|
|
89
|
+
'width',
|
|
90
|
+
)
|
|
91
|
+
const thumbHeight = getCompoundVariantValue(
|
|
92
|
+
SliderStyles.thumb(colorPalette),
|
|
93
|
+
{axis, size},
|
|
94
|
+
'height',
|
|
95
|
+
)
|
|
96
|
+
// const thumbHeight = getVariantValue(SliderStyles.thumb(colorPalette), 'size', size, 'height', true)
|
|
84
97
|
|
|
85
|
-
const halfSize =
|
|
86
|
-
axis === 'x' ? (thumbStyle.width ?? 0) / 2 : (thumbStyle.height ?? 0) / 2
|
|
98
|
+
const halfSize = ((axis === 'x' ? thumbWidth : thumbHeight) ?? 0) / 2
|
|
87
99
|
const context = useSharedValue({x: 0})
|
|
88
100
|
const translate = useSharedValue(value)
|
|
89
101
|
const trackLength = useSharedValue(0)
|
|
@@ -240,9 +252,11 @@ const Slider = ({
|
|
|
240
252
|
onSlidingComplete && runOnJS(onSlidingComplete)(snappedValue)
|
|
241
253
|
})
|
|
242
254
|
|
|
243
|
-
const animatedTrack = useAnimatedStyle(() =>
|
|
244
|
-
|
|
245
|
-
|
|
255
|
+
const animatedTrack = useAnimatedStyle(() => {
|
|
256
|
+
return {
|
|
257
|
+
[axis === 'y' ? 'height' : 'width']: translate.value + halfSize,
|
|
258
|
+
}
|
|
259
|
+
})
|
|
246
260
|
|
|
247
261
|
const animatedThumb = useAnimatedStyle(() => {
|
|
248
262
|
if (axis === 'x') {
|
|
@@ -257,8 +271,6 @@ const Slider = ({
|
|
|
257
271
|
}
|
|
258
272
|
})
|
|
259
273
|
|
|
260
|
-
const opacityTrack = steps !== undefined && displayStepsOnMinimumTrack
|
|
261
|
-
|
|
262
274
|
return (
|
|
263
275
|
<View
|
|
264
276
|
style={[
|
|
@@ -273,10 +285,10 @@ const Slider = ({
|
|
|
273
285
|
SliderStyles.maximumTrack(colorPalette),
|
|
274
286
|
]}
|
|
275
287
|
onLayout={handleTrackLayout}>
|
|
276
|
-
<
|
|
288
|
+
<AnimatedView
|
|
277
289
|
style={[
|
|
278
290
|
styles.minimumTrack(halfSize),
|
|
279
|
-
SliderStyles.minimumTrack(colorPalette
|
|
291
|
+
SliderStyles.minimumTrack(colorPalette),
|
|
280
292
|
animatedTrack,
|
|
281
293
|
]}
|
|
282
294
|
/>
|
|
@@ -300,7 +312,7 @@ const Slider = ({
|
|
|
300
312
|
)}
|
|
301
313
|
<GestureDetector gesture={slideGesture}>
|
|
302
314
|
<View style={styles.thumbContainerFull}>
|
|
303
|
-
<
|
|
315
|
+
<AnimatedView style={[animatedThumb, {flex: 1}]}>
|
|
304
316
|
<View
|
|
305
317
|
style={[
|
|
306
318
|
SliderStyles.thumb(colorPalette),
|
|
@@ -308,7 +320,7 @@ const Slider = ({
|
|
|
308
320
|
]}>
|
|
309
321
|
{ThumbChildren || null}
|
|
310
322
|
</View>
|
|
311
|
-
</
|
|
323
|
+
</AnimatedView>
|
|
312
324
|
</View>
|
|
313
325
|
</GestureDetector>
|
|
314
326
|
</View>
|
|
@@ -326,16 +338,18 @@ const styles = StyleSheet.create(theme => ({
|
|
|
326
338
|
) => ({
|
|
327
339
|
flex,
|
|
328
340
|
alignSelf,
|
|
341
|
+
overflow: 'hidden',
|
|
342
|
+
// flexBasis: 'auto',
|
|
329
343
|
variants: {
|
|
330
344
|
axis: {
|
|
331
345
|
x: {
|
|
332
|
-
maxWidth: 'auto',
|
|
346
|
+
// maxWidth: 'auto',
|
|
333
347
|
paddingTop: 0,
|
|
334
348
|
paddingRight: halfSize,
|
|
335
349
|
flexDirection: 'row',
|
|
336
350
|
},
|
|
337
351
|
y: {
|
|
338
|
-
maxHeight: 'auto',
|
|
352
|
+
// maxHeight: 'auto',
|
|
339
353
|
height: '100%',
|
|
340
354
|
paddingTop: halfSize,
|
|
341
355
|
paddingRight: 0,
|
|
@@ -343,11 +357,16 @@ const styles = StyleSheet.create(theme => ({
|
|
|
343
357
|
},
|
|
344
358
|
},
|
|
345
359
|
},
|
|
360
|
+
_web: {
|
|
361
|
+
_classNames: 'slider-container-base',
|
|
362
|
+
flex: flex === 0 ? undefined : flex,
|
|
363
|
+
},
|
|
346
364
|
}),
|
|
347
365
|
maximumTrack: () => ({
|
|
348
366
|
flex: 1,
|
|
349
367
|
position: 'relative',
|
|
350
368
|
overflow: 'visible',
|
|
369
|
+
flexBasis: 'auto',
|
|
351
370
|
variants: {
|
|
352
371
|
axis: {
|
|
353
372
|
x: {
|
|
@@ -358,8 +377,12 @@ const styles = StyleSheet.create(theme => ({
|
|
|
358
377
|
},
|
|
359
378
|
},
|
|
360
379
|
},
|
|
380
|
+
_web: {
|
|
381
|
+
_classNames: 'slider-maximun-track-base',
|
|
382
|
+
},
|
|
361
383
|
}),
|
|
362
384
|
minimumTrack: (halfSize: number) => ({
|
|
385
|
+
flexBasis: 'auto',
|
|
363
386
|
variants: {
|
|
364
387
|
axis: {
|
|
365
388
|
x: {
|
|
@@ -369,9 +392,6 @@ const styles = StyleSheet.create(theme => ({
|
|
|
369
392
|
bottom: 'auto',
|
|
370
393
|
paddingBottom: 0,
|
|
371
394
|
paddingLeft: halfSize,
|
|
372
|
-
borderBottomLeftRadius: 20,
|
|
373
|
-
borderBottomRightRadius: 0,
|
|
374
|
-
borderTopLeftRadius: 20,
|
|
375
395
|
justifyContent: 'center',
|
|
376
396
|
alignItems: 'flex-end',
|
|
377
397
|
},
|
|
@@ -380,13 +400,13 @@ const styles = StyleSheet.create(theme => ({
|
|
|
380
400
|
paddingBottom: halfSize,
|
|
381
401
|
marginBottom: halfSize * -1,
|
|
382
402
|
paddingLeft: 0,
|
|
383
|
-
borderBottomLeftRadius: 20,
|
|
384
|
-
borderBottomRightRadius: 20,
|
|
385
|
-
borderTopLeftRadius: 0,
|
|
386
403
|
alignItems: 'flex-start',
|
|
387
404
|
},
|
|
388
405
|
},
|
|
389
406
|
},
|
|
407
|
+
_web: {
|
|
408
|
+
_classNames: 'slider-minimum-track-base',
|
|
409
|
+
},
|
|
390
410
|
}),
|
|
391
411
|
thumbContainerFull: {
|
|
392
412
|
position: 'absolute',
|
|
@@ -395,21 +415,28 @@ const styles = StyleSheet.create(theme => ({
|
|
|
395
415
|
top: 0,
|
|
396
416
|
bottom: 0,
|
|
397
417
|
zIndex: 2,
|
|
418
|
+
_web: {
|
|
419
|
+
_classNames: 'thumb-container-full-base',
|
|
420
|
+
},
|
|
398
421
|
},
|
|
399
422
|
thumb: halfSize => ({
|
|
400
|
-
borderRadius: 25,
|
|
401
423
|
variants: {
|
|
402
424
|
axis: {
|
|
403
425
|
x: {
|
|
404
426
|
height: '100%',
|
|
405
427
|
justifyContent: 'center',
|
|
428
|
+
alignItems: 'center',
|
|
406
429
|
},
|
|
407
430
|
y: {
|
|
408
431
|
width: '100%',
|
|
432
|
+
justifyContent: 'center',
|
|
409
433
|
alignItems: 'center',
|
|
410
434
|
},
|
|
411
435
|
},
|
|
412
436
|
},
|
|
437
|
+
_web: {
|
|
438
|
+
_classNames: 'slider-thumb-base',
|
|
439
|
+
},
|
|
413
440
|
}),
|
|
414
441
|
|
|
415
442
|
stepsOverlay: {
|
|
@@ -419,6 +446,9 @@ const styles = StyleSheet.create(theme => ({
|
|
|
419
446
|
top: 0,
|
|
420
447
|
bottom: 0,
|
|
421
448
|
zIndex: 1,
|
|
449
|
+
_web: {
|
|
450
|
+
_classNames: 'slider-steps-overlay-base',
|
|
451
|
+
},
|
|
422
452
|
},
|
|
423
453
|
steps: {
|
|
424
454
|
width: '100%',
|
|
@@ -437,6 +467,9 @@ const styles = StyleSheet.create(theme => ({
|
|
|
437
467
|
},
|
|
438
468
|
},
|
|
439
469
|
},
|
|
470
|
+
_web: {
|
|
471
|
+
_classNames: 'slider-steps-base',
|
|
472
|
+
},
|
|
440
473
|
},
|
|
441
474
|
step: (index, length) => ({
|
|
442
475
|
backgroundColor:
|
|
@@ -453,6 +486,9 @@ const styles = StyleSheet.create(theme => ({
|
|
|
453
486
|
},
|
|
454
487
|
},
|
|
455
488
|
},
|
|
489
|
+
_web: {
|
|
490
|
+
_classNames: 'slider-step-base',
|
|
491
|
+
},
|
|
456
492
|
}),
|
|
457
493
|
}))
|
|
458
494
|
|
|
@@ -18,6 +18,7 @@ export type SlideshowRef = {
|
|
|
18
18
|
handlePrev: () => void | null
|
|
19
19
|
}
|
|
20
20
|
|
|
21
|
+
const AnimatedView = Animated.createAnimatedComponent(View)
|
|
21
22
|
type SlideshowVariants = UnistylesVariants<typeof SlideshowStyles>
|
|
22
23
|
|
|
23
24
|
type Axis = 'x' | 'y'
|
|
@@ -174,7 +175,7 @@ const Slideshow = ({
|
|
|
174
175
|
setContainerWidth(e.nativeEvent.layout.width)
|
|
175
176
|
setContainerHeight(e.nativeEvent.layout.height)
|
|
176
177
|
}}>
|
|
177
|
-
<
|
|
178
|
+
<AnimatedView
|
|
178
179
|
style={[
|
|
179
180
|
styles.slidesContainer(`${NUM_PAGES * 100}%`, isHorizontal),
|
|
180
181
|
animatedStyle,
|
|
@@ -189,7 +190,7 @@ const Slideshow = ({
|
|
|
189
190
|
{Slide}
|
|
190
191
|
</View>
|
|
191
192
|
))}
|
|
192
|
-
</
|
|
193
|
+
</AnimatedView>
|
|
193
194
|
</View>
|
|
194
195
|
</GestureDetector>
|
|
195
196
|
</View>
|
|
@@ -201,15 +202,24 @@ export default Slideshow
|
|
|
201
202
|
const styles = StyleSheet.create({
|
|
202
203
|
flex: flex => ({
|
|
203
204
|
flex,
|
|
205
|
+
flexBasis: 'auto',
|
|
204
206
|
flexDirection: 'row',
|
|
207
|
+
alignSelf: 'stretch',
|
|
208
|
+
_web: {
|
|
209
|
+
_classNames: 'slideshow-container-flex-base',
|
|
210
|
+
},
|
|
205
211
|
}),
|
|
206
212
|
|
|
207
213
|
container: () => ({
|
|
214
|
+
flexBasis: 'auto',
|
|
208
215
|
width: '100%',
|
|
209
|
-
|
|
216
|
+
maxHeight: '100%',
|
|
210
217
|
overflow: 'hidden',
|
|
211
218
|
justifyContent: 'flex-start',
|
|
212
219
|
alignItems: 'flex-start',
|
|
220
|
+
_web: {
|
|
221
|
+
_classNames: 'slideshow-container-base',
|
|
222
|
+
},
|
|
213
223
|
}),
|
|
214
224
|
|
|
215
225
|
slidesContainer: (size, isHorizontal) => ({
|
|
@@ -217,6 +227,9 @@ const styles = StyleSheet.create({
|
|
|
217
227
|
width: isHorizontal ? size : '100%',
|
|
218
228
|
minHeight: isHorizontal ? '100%' : size,
|
|
219
229
|
flex: 1,
|
|
230
|
+
_web: {
|
|
231
|
+
_classNames: 'slideshow-container-slides-container-base',
|
|
232
|
+
},
|
|
220
233
|
}),
|
|
221
234
|
|
|
222
235
|
slide: (size, isHorizontal) => ({
|
|
@@ -225,5 +238,8 @@ const styles = StyleSheet.create({
|
|
|
225
238
|
height: isHorizontal ? '100%' : size,
|
|
226
239
|
justifyContent: 'center',
|
|
227
240
|
alignItems: 'center',
|
|
241
|
+
_web: {
|
|
242
|
+
_classNames: 'slideshow-container-slide-base',
|
|
243
|
+
},
|
|
228
244
|
}),
|
|
229
245
|
})
|
|
@@ -34,17 +34,23 @@ const BaseSpinner = ({
|
|
|
34
34
|
...props
|
|
35
35
|
}: SpinnerProps) => {
|
|
36
36
|
const resolvedColor = resolveColor(color, colors, colorPalette)
|
|
37
|
-
|
|
37
|
+
|
|
38
38
|
SpinnerStyles.useVariants({
|
|
39
39
|
size,
|
|
40
40
|
})
|
|
41
41
|
|
|
42
42
|
// console.log('color', color)
|
|
43
43
|
|
|
44
|
-
const resolvedSize = getVariantValue(
|
|
45
|
-
|
|
44
|
+
const resolvedSize = getVariantValue(
|
|
45
|
+
SpinnerStyles.base,
|
|
46
|
+
'size',
|
|
47
|
+
size,
|
|
48
|
+
'width',
|
|
49
|
+
)
|
|
50
|
+
|
|
46
51
|
return (
|
|
47
52
|
<ActivityIndicator
|
|
53
|
+
testID="spinner"
|
|
48
54
|
color={resolvedColor}
|
|
49
55
|
size={resolvedSize}
|
|
50
56
|
{...props}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {TouchableWithoutFeedback, View} from 'react-native'
|
|
1
|
+
import {Platform, TouchableWithoutFeedback, View} from 'react-native'
|
|
2
2
|
import Animated, {
|
|
3
3
|
useAnimatedStyle,
|
|
4
4
|
useSharedValue,
|
|
@@ -9,13 +9,15 @@ import {StyleSheet, UnistylesVariants} from 'react-native-unistyles'
|
|
|
9
9
|
import {useAnimatedVariantColor} from 'react-native-unistyles/reanimated'
|
|
10
10
|
import {ReactNode, useLayoutEffect, useRef} from 'react'
|
|
11
11
|
import {SwitchTokens, SwitchStyles} from '../theme/Switch.recipe'
|
|
12
|
-
import {PalettesWithNestedKeys} from '../style/varia/types'
|
|
12
|
+
import {AlignSelf, Flex, PalettesWithNestedKeys} from '../style/varia/types'
|
|
13
|
+
import {getVariantValue} from '../style/varia/utils'
|
|
13
14
|
|
|
14
15
|
const animations = {
|
|
15
16
|
withSpring,
|
|
16
17
|
withTiming,
|
|
17
18
|
}
|
|
18
19
|
|
|
20
|
+
const AnimatedView = Animated.createAnimatedComponent(View)
|
|
19
21
|
type AnimationType = 'withSpring' | 'withTiming'
|
|
20
22
|
|
|
21
23
|
type SwitchVariants = UnistylesVariants<typeof SwitchStyles>
|
|
@@ -25,9 +27,10 @@ type SwitchProps = SwitchVariants & {
|
|
|
25
27
|
value?: boolean
|
|
26
28
|
animation?: keyof typeof SwitchTokens.variants.animation
|
|
27
29
|
onValueChange?: (value: boolean) => void
|
|
28
|
-
flex?:
|
|
29
|
-
enabledIcon
|
|
30
|
-
disabledIcon
|
|
30
|
+
flex?: Flex
|
|
31
|
+
enabledIcon?: ReactNode
|
|
32
|
+
disabledIcon?: ReactNode
|
|
33
|
+
alignSelf?: AlignSelf
|
|
31
34
|
}
|
|
32
35
|
|
|
33
36
|
const Switch = ({
|
|
@@ -39,7 +42,8 @@ const Switch = ({
|
|
|
39
42
|
onValueChange = () => {},
|
|
40
43
|
variant = SwitchTokens.defaultProps.variant,
|
|
41
44
|
size = SwitchTokens.defaultProps.size,
|
|
42
|
-
flex =
|
|
45
|
+
flex = 0,
|
|
46
|
+
alignSelf = 'flex-start',
|
|
43
47
|
}: SwitchProps) => {
|
|
44
48
|
const animatedRef = useRef<View>(null)
|
|
45
49
|
|
|
@@ -62,15 +66,20 @@ const Switch = ({
|
|
|
62
66
|
mass: 1,
|
|
63
67
|
},
|
|
64
68
|
}
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
69
|
+
const color =
|
|
70
|
+
Platform.OS === 'web'
|
|
71
|
+
? {value: 'blue'}
|
|
72
|
+
: useAnimatedVariantColor(
|
|
73
|
+
SwitchStyles.container(colorPalette),
|
|
74
|
+
'backgroundColor',
|
|
75
|
+
)
|
|
76
|
+
const thumbColor =
|
|
77
|
+
Platform.OS === 'web'
|
|
78
|
+
? {value: 'white'}
|
|
79
|
+
: useAnimatedVariantColor(
|
|
80
|
+
SwitchStyles.thumb(colorPalette),
|
|
81
|
+
'backgroundColor',
|
|
82
|
+
)
|
|
74
83
|
const thumbEnabledPosition = useSharedValue(0)
|
|
75
84
|
const animatedValue = useSharedValue(0)
|
|
76
85
|
const containerWidth = useSharedValue(0)
|
|
@@ -78,10 +87,24 @@ const Switch = ({
|
|
|
78
87
|
useLayoutEffect(() => {
|
|
79
88
|
animatedRef.current?.measure((x, y, width) => {
|
|
80
89
|
containerWidth.value = width
|
|
81
|
-
const thumbWidth = SwitchStyles.thumb(colorPalette).width
|
|
82
|
-
const
|
|
83
|
-
|
|
84
|
-
|
|
90
|
+
// const thumbWidth = SwitchStyles.thumb(colorPalette).width
|
|
91
|
+
const thumbWidth = getVariantValue(
|
|
92
|
+
SwitchStyles.thumb(colorPalette),
|
|
93
|
+
'size',
|
|
94
|
+
size,
|
|
95
|
+
'width',
|
|
96
|
+
)
|
|
97
|
+
// const padding = SwitchStyles.container(colorPalette).padding || 0
|
|
98
|
+
const padding =
|
|
99
|
+
getVariantValue(
|
|
100
|
+
SwitchStyles.container(colorPalette),
|
|
101
|
+
'size',
|
|
102
|
+
size,
|
|
103
|
+
'padding',
|
|
104
|
+
) || 0
|
|
105
|
+
// const trackBorderWidth =
|
|
106
|
+
// SwitchStyles.container(colorPalette).borderWidth || 0
|
|
107
|
+
const trackBorderWidth = 1
|
|
85
108
|
thumbEnabledPosition.value =
|
|
86
109
|
width - thumbWidth - trackBorderWidth * 2 - padding * 2
|
|
87
110
|
})
|
|
@@ -133,14 +156,14 @@ const Switch = ({
|
|
|
133
156
|
},
|
|
134
157
|
)
|
|
135
158
|
}}>
|
|
136
|
-
<
|
|
159
|
+
<AnimatedView
|
|
137
160
|
ref={animatedRef}
|
|
138
161
|
style={[
|
|
139
|
-
styles.container(flex),
|
|
162
|
+
styles.container(flex, alignSelf),
|
|
140
163
|
animatedStyle,
|
|
141
164
|
SwitchStyles.container(colorPalette),
|
|
142
165
|
]}>
|
|
143
|
-
<
|
|
166
|
+
<AnimatedView
|
|
144
167
|
style={[
|
|
145
168
|
styles.thumb,
|
|
146
169
|
SwitchStyles.thumb(colorPalette),
|
|
@@ -148,8 +171,8 @@ const Switch = ({
|
|
|
148
171
|
circleTranslationStyle,
|
|
149
172
|
]}>
|
|
150
173
|
{Icon && Icon}
|
|
151
|
-
</
|
|
152
|
-
</
|
|
174
|
+
</AnimatedView>
|
|
175
|
+
</AnimatedView>
|
|
153
176
|
</TouchableWithoutFeedback>
|
|
154
177
|
)
|
|
155
178
|
}
|
|
@@ -157,17 +180,25 @@ const Switch = ({
|
|
|
157
180
|
export default Switch
|
|
158
181
|
|
|
159
182
|
const styles = StyleSheet.create({
|
|
160
|
-
container: (flex:
|
|
183
|
+
container: (flex: Flex, alignSelf: AlignSelf) => ({
|
|
161
184
|
flexGrow: flex,
|
|
185
|
+
flexBasis: 'auto',
|
|
186
|
+
alignSelf,
|
|
162
187
|
flexShrink: 0,
|
|
163
|
-
alignSelf: 'flex-start',
|
|
188
|
+
// alignSelf: 'flex-start',
|
|
164
189
|
flexDirection: 'row',
|
|
165
190
|
alignItems: 'center',
|
|
166
191
|
margin: 0,
|
|
192
|
+
_web: {
|
|
193
|
+
_classNames: 'switch-container-base',
|
|
194
|
+
},
|
|
167
195
|
}),
|
|
168
196
|
thumb: {
|
|
169
197
|
borderRadius: 9999,
|
|
170
198
|
justifyContent: 'center',
|
|
171
199
|
alignItems: 'center',
|
|
200
|
+
_web: {
|
|
201
|
+
_classNames: 'switch-thumb-base',
|
|
202
|
+
},
|
|
172
203
|
},
|
|
173
204
|
})
|