@@ -200,34 +200,36 @@ type Props = ViewProps &
200
200
} > ;
201
201
202
202
const SliderComponent = (
203
- props : Props ,
204
- forwardedRef ?: Ref < typeof RCTSliderNativeComponent > ,
205
- ) => {
206
- const {
203
+ {
207
204
onValueChange,
208
205
onSlidingStart,
209
206
onSlidingComplete,
210
207
onAccessibilityAction,
211
- ...localProps
212
- } = props ;
208
+ value = constants . SLIDER_DEFAULT_INITIAL_VALUE ,
209
+ minimumValue = 0 ,
210
+ maximumValue = 1 ,
211
+ step = 0 ,
212
+ inverted = false ,
213
+ tapToSeek = false ,
214
+ ...props
215
+ } : Props ,
216
+ forwardedRef ?: Ref < typeof RCTSliderNativeComponent > ,
217
+ ) => {
213
218
const [ currentValue , setCurrentValue ] = useState (
214
- props . value ?? props . minimumValue ?? constants . SLIDER_DEFAULT_INITIAL_VALUE ,
219
+ value ?? minimumValue ?? constants . SLIDER_DEFAULT_INITIAL_VALUE ,
215
220
) ;
216
221
const [ width , setWidth ] = useState ( 0 ) ;
217
222
218
- const stepResolution = localProps . step
219
- ? localProps . step
220
- : constants . DEFAULT_STEP_RESOLUTION ;
223
+ const stepResolution = step ? step : constants . DEFAULT_STEP_RESOLUTION ;
221
224
222
- const defaultStep =
223
- ( localProps . maximumValue ! - localProps . minimumValue ! ) / stepResolution ;
224
- const stepLength = localProps . step || defaultStep ;
225
+ const defaultStep = ( maximumValue - minimumValue ) / stepResolution ;
226
+ const stepLength = step || defaultStep ;
225
227
226
228
const options = Array . from (
227
229
{
228
- length : ( localProps . step ? defaultStep : stepResolution ) + 1 ,
230
+ length : ( step ? defaultStep : stepResolution ) + 1 ,
229
231
} ,
230
- ( _ , index ) => localProps . minimumValue ! + index * stepLength ,
232
+ ( _ , index ) => minimumValue + index * stepLength ,
231
233
) ;
232
234
233
235
const defaultStyle =
@@ -266,22 +268,21 @@ const SliderComponent = (
266
268
}
267
269
: null ;
268
270
269
- const value =
270
- Number . isNaN ( props . value ) || ! props . value ? undefined : props . value ;
271
+ const passedValue = Number . isNaN ( value ) || ! value ? undefined : value ;
271
272
272
273
const lowerLimit =
273
- ! ! localProps . lowerLimit || localProps . lowerLimit === 0
274
- ? localProps . lowerLimit
274
+ ! ! props . lowerLimit || props . lowerLimit === 0
275
+ ? props . lowerLimit
275
276
: Platform . select ( {
276
- web : localProps . minimumValue ,
277
+ web : minimumValue ,
277
278
default : constants . LIMIT_MIN_VALUE ,
278
279
} ) ;
279
280
280
281
const upperLimit =
281
- ! ! localProps . upperLimit || localProps . upperLimit === 0
282
- ? localProps . upperLimit
282
+ ! ! props . upperLimit || props . upperLimit === 0
283
+ ? props . upperLimit
283
284
: Platform . select ( {
284
- web : localProps . maximumValue ,
285
+ web : maximumValue ,
285
286
default : constants . LIMIT_MAX_VALUE ,
286
287
} ) ;
287
288
@@ -304,15 +305,20 @@ const SliderComponent = (
304
305
options = { options }
305
306
sliderWidth = { width }
306
307
currentValue = { currentValue }
307
- renderStepNumber = { localProps . renderStepNumber }
308
- thumbImage = { localProps . thumbImage }
309
- StepMarker = { localProps . StepMarker }
310
- isLTR = { localProps . inverted }
308
+ renderStepNumber = { props . renderStepNumber }
309
+ thumbImage = { props . thumbImage }
310
+ StepMarker = { props . StepMarker }
311
+ isLTR = { inverted }
311
312
/>
312
313
) : null }
313
314
< RCTSliderNativeComponent
314
- { ...localProps }
315
- value = { value }
315
+ { ...props }
316
+ minimumValue = { minimumValue }
317
+ maximumValue = { maximumValue }
318
+ step = { step }
319
+ inverted = { inverted }
320
+ tapToSeek = { tapToSeek }
321
+ value = { passedValue }
316
322
lowerLimit = { lowerLimit }
317
323
upperLimit = { upperLimit }
318
324
accessibilityState = { _accessibilityState }
@@ -349,21 +355,4 @@ const SliderComponent = (
349
355
350
356
const SliderWithRef = React . forwardRef ( SliderComponent ) ;
351
357
352
- SliderWithRef . defaultProps = {
353
- value : constants . SLIDER_DEFAULT_INITIAL_VALUE ,
354
- minimumValue : 0 ,
355
- maximumValue : 1 ,
356
- step : 0 ,
357
- inverted : false ,
358
- tapToSeek : false ,
359
- lowerLimit : Platform . select ( {
360
- web : undefined ,
361
- default : constants . LIMIT_MIN_VALUE ,
362
- } ) ,
363
- upperLimit : Platform . select ( {
364
- web : undefined ,
365
- default : constants . LIMIT_MAX_VALUE ,
366
- } ) ,
367
- } ;
368
-
369
358
export default SliderWithRef ;
0 commit comments