@@ -200,34 +200,36 @@ type Props = ViewProps &
200200 } > ;
201201
202202const SliderComponent = (
203- props : Props ,
204- forwardedRef ?: Ref < typeof RCTSliderNativeComponent > ,
205- ) => {
206- const {
203+ {
207204 onValueChange,
208205 onSlidingStart,
209206 onSlidingComplete,
210207 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+ ) => {
213218 const [ currentValue , setCurrentValue ] = useState (
214- props . value ?? props . minimumValue ?? constants . SLIDER_DEFAULT_INITIAL_VALUE ,
219+ value ?? minimumValue ?? constants . SLIDER_DEFAULT_INITIAL_VALUE ,
215220 ) ;
216221 const [ width , setWidth ] = useState ( 0 ) ;
217222
218- const stepResolution = localProps . step
219- ? localProps . step
220- : constants . DEFAULT_STEP_RESOLUTION ;
223+ const stepResolution = step ? step : constants . DEFAULT_STEP_RESOLUTION ;
221224
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 ;
225227
226228 const options = Array . from (
227229 {
228- length : ( localProps . step ? defaultStep : stepResolution ) + 1 ,
230+ length : ( step ? defaultStep : stepResolution ) + 1 ,
229231 } ,
230- ( _ , index ) => localProps . minimumValue ! + index * stepLength ,
232+ ( _ , index ) => minimumValue + index * stepLength ,
231233 ) ;
232234
233235 const defaultStyle =
@@ -266,22 +268,21 @@ const SliderComponent = (
266268 }
267269 : null ;
268270
269- const value =
270- Number . isNaN ( props . value ) || ! props . value ? undefined : props . value ;
271+ const passedValue = Number . isNaN ( value ) || ! value ? undefined : value ;
271272
272273 const lowerLimit =
273- ! ! localProps . lowerLimit || localProps . lowerLimit === 0
274- ? localProps . lowerLimit
274+ ! ! props . lowerLimit || props . lowerLimit === 0
275+ ? props . lowerLimit
275276 : Platform . select ( {
276- web : localProps . minimumValue ,
277+ web : minimumValue ,
277278 default : constants . LIMIT_MIN_VALUE ,
278279 } ) ;
279280
280281 const upperLimit =
281- ! ! localProps . upperLimit || localProps . upperLimit === 0
282- ? localProps . upperLimit
282+ ! ! props . upperLimit || props . upperLimit === 0
283+ ? props . upperLimit
283284 : Platform . select ( {
284- web : localProps . maximumValue ,
285+ web : maximumValue ,
285286 default : constants . LIMIT_MAX_VALUE ,
286287 } ) ;
287288
@@ -304,15 +305,20 @@ const SliderComponent = (
304305 options = { options }
305306 sliderWidth = { width }
306307 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 }
311312 />
312313 ) : null }
313314 < 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 }
316322 lowerLimit = { lowerLimit }
317323 upperLimit = { upperLimit }
318324 accessibilityState = { _accessibilityState }
@@ -349,21 +355,4 @@ const SliderComponent = (
349355
350356const SliderWithRef = React . forwardRef ( SliderComponent ) ;
351357
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-
369358export default SliderWithRef ;
0 commit comments