1
1
import _ from 'lodash' ;
2
- import React , { useImperativeHandle , useCallback , useMemo , useEffect } from 'react' ;
2
+ import React , { ReactElement , useImperativeHandle , useCallback , useMemo , useEffect } from 'react' ;
3
3
import { StyleSheet , AccessibilityRole , StyleProp , ViewStyle , GestureResponderEvent , LayoutChangeEvent , ViewProps , AccessibilityProps } from 'react-native' ;
4
4
import { useSharedValue , useAnimatedStyle , runOnJS , useAnimatedReaction , withTiming } from 'react-native-reanimated' ;
5
5
import { forwardRef , ForwardRefInjectedProps , Constants } from '../../commons/new' ;
@@ -9,7 +9,6 @@ import {StyleUtils} from 'utils';
9
9
import { useThemeProps } from '../../hooks' ;
10
10
import View from '../../components/view' ;
11
11
import { ComponentStatics } from '../../typings/common' ;
12
- import { SliderProps as BaseSliderProps } from '../../components/slider/types' ;
13
12
import {
14
13
validateValues ,
15
14
getOffsetForValue ,
@@ -19,8 +18,67 @@ import {
19
18
import Thumb from './Thumb' ;
20
19
import Track from './Track' ;
21
20
22
- // TODO: after removing old Slider move these extra props to the SliderProps in types.ts
23
- export interface SliderProps extends BaseSliderProps , AccessibilityProps {
21
+ export interface SliderProps extends AccessibilityProps {
22
+ /**
23
+ * Initial value
24
+ */
25
+ value ?: number ;
26
+ /**
27
+ * Track minimum value
28
+ */
29
+ minimumValue ?: number ;
30
+ /**
31
+ * Track maximum value
32
+ */
33
+ maximumValue ?: number ;
34
+ /**
35
+ * Initial minimum value (when useRange is true)
36
+ */
37
+ initialMinimumValue ?: number ;
38
+ /**
39
+ * Initial maximum value (when useRange is true)
40
+ */
41
+ initialMaximumValue ?: number ;
42
+ /**
43
+ * Step value of the slider. The value should be between 0 and (maximumValue - minimumValue)
44
+ */
45
+ step ?: number ;
46
+ /**
47
+ * Callback for onValueChange
48
+ */
49
+ onValueChange ?: ( value : number ) => void ;
50
+ /**
51
+ * Callback that notifies about slider seeking is started
52
+ */
53
+ onSeekStart ?: ( ) => void ;
54
+ /**
55
+ * Callback that notifies about slider seeking is finished
56
+ */
57
+ onSeekEnd ?: ( ) => void ;
58
+ /**
59
+ * Callback that notifies when the reset function was invoked
60
+ */
61
+ onReset ?: ( ) => void ;
62
+ /**
63
+ * The container style
64
+ */
65
+ containerStyle ?: StyleProp < ViewStyle > ;
66
+ /**
67
+ * The color used for the track from minimum value to current value
68
+ */
69
+ minimumTrackTintColor ?: string ;
70
+ /**
71
+ * The track color
72
+ */
73
+ maximumTrackTintColor ?: string ;
74
+ /**
75
+ * The track style
76
+ */
77
+ trackStyle ?: StyleProp < ViewStyle > ;
78
+ /**
79
+ * Custom render instead of rendering the track
80
+ */
81
+ renderTrack ?: ( ) => ReactElement | ReactElement [ ] ;
24
82
/**
25
83
* The thumb style
26
84
*/
@@ -34,7 +92,7 @@ export interface SliderProps extends BaseSliderProps, AccessibilityProps {
34
92
*/
35
93
disableActiveStyling ?: boolean ;
36
94
/**
37
- * Defines how far a touch event can start away from the thumb.
95
+ * Defines how far a touch event can start away from the thumb
38
96
*/
39
97
thumbHitSlop ?: ViewProps [ 'hitSlop' ] ;
40
98
/**
@@ -45,6 +103,42 @@ export interface SliderProps extends BaseSliderProps, AccessibilityProps {
45
103
* Thumb color
46
104
*/
47
105
thumbTintColor ?: string ;
106
+ /**
107
+ * Disabled thumb tint color
108
+ */
109
+ disabledThumbTintColor ?: string ;
110
+ /**
111
+ * If true the Slider will be disabled and will appear in disabled color
112
+ */
113
+ disabled ?: boolean ;
114
+ /**
115
+ * If true the Slider will display a second thumb for the min value
116
+ */
117
+ useRange ?: boolean ;
118
+ /**
119
+ * If true the min and max thumbs will not overlap
120
+ */
121
+ useGap ?: boolean ;
122
+ /**
123
+ * Callback for onRangeChange. Returns values object with the min and max values
124
+ */
125
+ onRangeChange ?: ( values : { min : number , max : number } ) => void ;
126
+ /**
127
+ * If true the Slider will stay in LTR mode even if the app is on RTL mode
128
+ */
129
+ disableRTL ?: boolean ;
130
+ /**
131
+ * If true the component will have accessibility features enabled
132
+ */
133
+ accessible ?: boolean ;
134
+ /**
135
+ * The slider's test identifier
136
+ */
137
+ testID ?: string ;
138
+ /**
139
+ * Whether to use the new Slider implementation using Reanimated
140
+ */
141
+ migrate ?: boolean ;
48
142
}
49
143
50
144
type Props = SliderProps & ForwardRefInjectedProps < SliderRef > ;
@@ -87,6 +181,7 @@ const Slider = React.memo((props: Props) => {
87
181
thumbStyle,
88
182
activeThumbStyle,
89
183
thumbTintColor = Colors . $backgroundPrimaryHeavy ,
184
+ disabledThumbTintColor = Colors . $backgroundDisabled ,
90
185
thumbHitSlop,
91
186
disableActiveStyling,
92
187
disabled,
@@ -129,7 +224,7 @@ const Slider = React.memo((props: Props) => {
129
224
const rangeThumbOffset = useSharedValue ( 0 ) ;
130
225
131
226
const thumbBackground : StyleProp < ViewStyle > = useMemo ( ( ) => [
132
- { backgroundColor : disabled ? Colors . $backgroundDisabled : thumbTintColor }
227
+ { backgroundColor : disabled ? disabledThumbTintColor : thumbTintColor }
133
228
] , [ disabled , thumbTintColor ] ) ;
134
229
const defaultThumbStyle : StyleProp < ViewStyle > = useMemo ( ( ) => [
135
230
styles . thumb , thumbBackground
0 commit comments