@@ -292,6 +292,22 @@ const MyStepMarker: FC<MarkerProps> = ({stepMarked, currentValue}) => {
292
292
) ;
293
293
} ;
294
294
295
+ const CustomComponent : FC < MarkerProps > = ( { stepMarked, currentValue, index, max} ) => {
296
+ if ( stepMarked ) {
297
+ return (
298
+ < View style = { styles . customComponentFrame } >
299
+ < View style = { [ styles . customComponentLeftFrame , styles . filled ] } >
300
+ < Text style = { styles . trackText } > { index } </ Text >
301
+ </ View >
302
+ < View style = { [ styles . customComponentRightFrame , styles . empty ] } >
303
+ < Text style = { styles . trackText } > { max } </ Text >
304
+ </ View >
305
+ < Text style = { [ styles . trackText , { position : "absolute" , left : 18 } ] } > /</ Text >
306
+ </ View > ) ;
307
+ }
308
+ return currentValue > index ? ( < View style = { [ styles . trackDot , styles . filled ] } > </ View > ) : ( < View style = { [ styles . trackDot , styles . empty ] } > </ View > ) ;
309
+ } ;
310
+
295
311
const SliderExampleWithCustomMarker = ( props : SliderProps ) => {
296
312
const [ value , setValue ] = useState ( props . value ?? CONSTANTS . MIN_VALUE ) ;
297
313
@@ -317,6 +333,30 @@ const SliderExampleWithCustomMarker = (props: SliderProps) => {
317
333
) ;
318
334
} ;
319
335
336
+ const SliderExampleWithCustomComponentAndFilledSteps = ( props : SliderProps ) => {
337
+ const [ value , setValue ] = useState ( props . value || 50 ) ;
338
+
339
+ return (
340
+ < View style = { { alignItems : 'center' } } >
341
+ < Text style = { styles . text } > { value && + value . toFixed ( 3 ) } </ Text >
342
+ < Slider
343
+ step = { CONSTANTS . STEP }
344
+ style = { [ styles . slider , props . style ] }
345
+ minimumValue = { CONSTANTS . MIN_VALUE }
346
+ maximumValue = { CONSTANTS . MAX_VALUE }
347
+ thumbImage = { require ( './resources/empty.png' ) }
348
+ tapToSeek
349
+ { ...props }
350
+ value = { value }
351
+ onValueChange = { setValue }
352
+ StepMarker = { CustomComponent }
353
+ minimumTrackTintColor = { '#00629A' }
354
+ maximumTrackTintColor = { '#979EA4' }
355
+ />
356
+ </ View >
357
+ )
358
+ }
359
+
320
360
export default SliderExample ;
321
361
322
362
const styles = StyleSheet . create ( {
@@ -326,6 +366,43 @@ const styles = StyleSheet.create({
326
366
fontWeight : '500' ,
327
367
margin : 0 ,
328
368
} ,
369
+ trackText : {
370
+ color : "#FFFFFF" ,
371
+ fontSize : 10 ,
372
+ justifyContent : "center" ,
373
+ alignSelf : "center" ,
374
+ top : 12
375
+ } ,
376
+ trackDot : {
377
+ width : 10 ,
378
+ height : 10 ,
379
+ borderRadius : 10 ,
380
+ top : 4 ,
381
+ } ,
382
+ empty : {
383
+ backgroundColor : '#B3BFC9' ,
384
+ } ,
385
+ filled : {
386
+ backgroundColor : '#00629A' ,
387
+ } ,
388
+ customComponentFrame : {
389
+ flex : 1 ,
390
+ flexDirection : 'row' ,
391
+ top : - 10 ,
392
+ opacity : 0.95
393
+ } ,
394
+ customComponentLeftFrame : {
395
+ height : 40 ,
396
+ width : 20 ,
397
+ borderTopLeftRadius : 40 ,
398
+ borderBottomLeftRadius : 40 ,
399
+ } ,
400
+ customComponentRightFrame : {
401
+ height : 40 ,
402
+ width : 20 ,
403
+ borderTopRightRadius : 40 ,
404
+ borderBottomRightRadius : 40 ,
405
+ } ,
329
406
divider : {
330
407
width : 2 ,
331
408
height : 20 ,
@@ -608,6 +685,12 @@ export const examples: Props[] = [
608
685
return < SliderExampleWithCustomMarker /> ;
609
686
} ,
610
687
} ,
688
+ {
689
+ title : 'Custom component with steps filled when passed' ,
690
+ render ( ) {
691
+ return < SliderExampleWithCustomComponentAndFilledSteps /> ;
692
+ } ,
693
+ } ,
611
694
{
612
695
title : 'Inverted slider direction' ,
613
696
render ( ) {
0 commit comments