Skip to content

Commit 027f600

Browse files
Provide new custom component with the example in example app
1 parent 752d977 commit 027f600

File tree

1 file changed

+83
-0
lines changed

1 file changed

+83
-0
lines changed

example/src/Examples.tsx

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -292,6 +292,22 @@ const MyStepMarker: FC<MarkerProps> = ({stepMarked, currentValue}) => {
292292
);
293293
};
294294

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+
295311
const SliderExampleWithCustomMarker = (props: SliderProps) => {
296312
const [value, setValue] = useState(props.value ?? CONSTANTS.MIN_VALUE);
297313

@@ -317,6 +333,30 @@ const SliderExampleWithCustomMarker = (props: SliderProps) => {
317333
);
318334
};
319335

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+
320360
export default SliderExample;
321361

322362
const styles = StyleSheet.create({
@@ -326,6 +366,43 @@ const styles = StyleSheet.create({
326366
fontWeight: '500',
327367
margin: 0,
328368
},
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+
},
329406
divider: {
330407
width: 2,
331408
height: 20,
@@ -608,6 +685,12 @@ export const examples: Props[] = [
608685
return <SliderExampleWithCustomMarker />;
609686
},
610687
},
688+
{
689+
title: 'Custom component with steps filled when passed',
690+
render() {
691+
return <SliderExampleWithCustomComponentAndFilledSteps />;
692+
},
693+
},
611694
{
612695
title: 'Inverted slider direction',
613696
render() {

0 commit comments

Comments
 (0)