Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
6a0b098
Wrap the Slider component in View implementing steps
BartoszKlonowski Sep 8, 2023
db294d8
Introduce new props regarding steps
BartoszKlonowski Sep 8, 2023
233634c
Centralize the thumb regardless of layout and adjust
BartoszKlonowski Sep 15, 2023
0860ba4
Fix the issue of missing thumbImage for step other than 0
BartoszKlonowski Sep 15, 2023
2cd0bea
Add examples of utilizing steps indicator in various scenarios
BartoszKlonowski Sep 15, 2023
7ef3505
Avoid breaking layout of steps when thumbImage is rendered
BartoszKlonowski Sep 22, 2023
c9cd43f
Use CK icon as a thumbImage for steps indicator examples
BartoszKlonowski Sep 22, 2023
b2936f9
Revert "Avoid breaking layout of steps when thumbImage is rendered"
BartoszKlonowski Sep 29, 2023
14b9ab2
Fix missing step numbers on iOS
BartoszKlonowski Sep 29, 2023
3894952
Fix layout breaking left/right alignement when sliding thumbImage
BartoszKlonowski Oct 6, 2023
33b82f8
Extract the customization implementation into new components files
BartoszKlonowski Oct 6, 2023
17c3d1f
Fix justification and alignement of thumbImage with custom component
BartoszKlonowski Oct 13, 2023
268b2ea
Adjust examples to present more cases of customized Slider
BartoszKlonowski Oct 13, 2023
613eb1b
Introduce styles and constants as a separate modules
BartoszKlonowski Oct 20, 2023
a394e41
Update examples regarding proper usage of stepMarker props
BartoszKlonowski Oct 27, 2023
5282d22
Move default step mark to styles implementation
BartoszKlonowski Oct 27, 2023
f66dffb
Fix the padding and layout issue for steps indicator
BartoszKlonowski Nov 17, 2023
5281293
Update the example application with new examples
BartoszKlonowski Nov 24, 2023
5bc56f2
Update the snapshots regarding the new tree
BartoszKlonowski Dec 1, 2023
9c40711
Do not provide Slider with default StepMarker
BartoszKlonowski Jan 19, 2024
5d9e456
Provide customized steps indicator with LTR support
BartoszKlonowski Jan 19, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion example/ios/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -375,7 +375,7 @@ PODS:
- React-jsinspector (0.72.6)
- React-logger (0.72.6):
- glog
- react-native-pager-view (6.2.0):
- react-native-pager-view (6.2.2):
- React-Core
- react-native-slider (4.5.0):
- RCT-Folly (= 2021.07.22.00)
Expand Down
9,804 changes: 3,846 additions & 5,958 deletions example/package-lock.json

Large diffs are not rendered by default.

304 changes: 301 additions & 3 deletions example/src/Examples.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ export interface Props {
const SliderExample = (props: SliderProps) => {
const [value, setValue] = useState(props.value ?? 0);
return (
<View>
<View style={{alignItems: 'center'}}>
<Text style={styles.text}>{value && +value.toFixed(3)}</Text>
<Slider
step={0.5}
style={styles.slider}
style={[styles.slider, props.style]}
{...props}
value={value}
onValueChange={setValue}
Expand Down Expand Up @@ -62,13 +62,212 @@ const SlidingCompleteExample = (props: SliderProps) => {
);
};

const SlidingStepsExample = (props: SliderProps) => {
return (
<View>
<SliderExample
{...props}
minimumValue={0}
maximumValue={4}
step={1}
tapToSeek
StepMarker={({stepMarked}) => {
return stepMarked ? (
<View style={styles.outerTrue}>
<View style={styles.innerTrue} />
</View>
) : (
<View style={styles.outer}>
<View style={styles.inner} />
</View>
);
}}
minimumTrackTintColor={'#112233'}
maximumTrackTintColor={'#00FF00'}
/>
</View>
);
};

const SlidingStepsNumbersExample = (props: SliderProps) => {
return (
<View>
<SliderExample
{...props}
minimumValue={0}
maximumValue={5}
step={1}
tapToSeek
renderStepNumber
StepMarker={({stepMarked}) => {
return stepMarked ? (
<View style={styles.outerTrue}>
<View style={styles.innerTrue} />
</View>
) : (
<View style={styles.outer}>
<View style={styles.inner} />
</View>
);
}}
minimumTrackTintColor={'#123456'}
maximumTrackTintColor={'#00FF00'}
/>
</View>
);
};

const SlidingStepsSmallNumbersExample = (props: SliderProps) => {
return (
<View>
<SliderExample
{...props}
minimumValue={0}
maximumValue={5}
step={1}
tapToSeek
renderStepNumber
StepMarker={({stepMarked}) => {
return stepMarked ? (
<View style={styles.outerTrueSmall}>
<View style={styles.innerTrueSmall} />
</View>
) : (
<View style={styles.outerSmall}>
<View style={styles.innerSmall} />
</View>
);
}}
minimumTrackTintColor={'#123456'}
maximumTrackTintColor={'#00FF00'}
/>
</View>
);
};

const SlidingCustomStepsThumbImageNumbersExample = (props: SliderProps) => {
return (
<View>
<SliderExample
{...props}
minimumValue={0}
maximumValue={4}
step={1}
tapToSeek
renderStepNumber
thumbImage={require('./resources/ck-icon.png')}
StepMarker={({stepMarked}) => {
return stepMarked ? (
<View style={styles.outerTrue}>
<View style={styles.innerTrue} />
</View>
) : (
<View style={styles.outer}>
<View style={styles.inner} />
</View>
);
}}
minimumTrackTintColor={'#123456'}
maximumTrackTintColor={'#654321'}
/>
</View>
);
};

const SlidingCustomStepsAnotherThumbImageNumbersExample = (
props: SliderProps,
) => {
return (
<View>
<SliderExample
{...props}
minimumValue={0}
maximumValue={15}
step={1}
tapToSeek
renderStepNumber
thumbImage={require('./resources/twitter-small.png')}
StepMarker={({stepMarked}) => {
return stepMarked ? (
<View style={styles.outerTrueSmall}>
<View style={styles.innerTrueSmall} />
</View>
) : (
<View style={styles.outerSmall}>
<View style={styles.innerSmall} />
</View>
);
}}
minimumTrackTintColor={'#123456'}
maximumTrackTintColor={'#654321'}
/>
</View>
);
};

const InvertedSliderWithStepMarker = (props: SliderProps) => {
return (
<View>
<SliderExample
{...props}
minimumValue={0}
maximumValue={15}
step={1}
tapToSeek
renderStepNumber
thumbImage={require('./resources/twitter-small.png')}
StepMarker={({stepMarked}) => {
return stepMarked ? (
<View style={styles.outerTrueSmall}>
<View style={styles.innerTrueSmall} />
</View>
) : (
<View style={styles.outerSmall}>
<View style={styles.innerSmall} />
</View>
);
}}
inverted
minimumTrackTintColor={'#123456'}
maximumTrackTintColor={'#654321'}
/>
</View>
);
};

const SlidingCustomStepsThumbImageWithNumbersAndDifferentWidth = (
props: SliderProps,
) => {
return (
<View>
<SliderExample
{...props}
minimumValue={0}
maximumValue={3}
step={1}
style={{width: 200}}
tapToSeek
renderStepNumber
StepMarker={({stepMarked}) => {
return stepMarked ? (
<View style={[styles.innerTrue, {top: 3}]} />
) : (
<View style={[styles.inner, {top: 3}]} />
);
}}
minimumTrackTintColor={'#ABCDEF'}
maximumTrackTintColor={'#001122'}
/>
</View>
);
};

export default SliderExample;

const styles = StyleSheet.create({
slider: {
width: 300,
opacity: 1,
height: 50,
marginTop: 10,
},
text: {
Expand All @@ -77,6 +276,63 @@ const styles = StyleSheet.create({
fontWeight: '500',
margin: 0,
},
outer: {
width: 20,
height: 20,
borderRadius: 10,
backgroundColor: '#11FF11',
justifyContent: 'center',
alignItems: 'center',
},
outerTrue: {
width: 20,
height: 20,
borderRadius: 10,
backgroundColor: '#0F0FFF',
justifyContent: 'center',
alignItems: 'center',
},
inner: {
width: 10,
height: 10,
borderRadius: 5,
backgroundColor: '#111111',
},
innerTrue: {
width: 10,
height: 10,
borderRadius: 5,
backgroundColor: '#0F0FFF',
},
outerSmall: {
width: 4,
height: 4,
top: 6,
borderRadius: 2,
backgroundColor: '#003366',
justifyContent: 'center',
alignItems: 'center',
},
outerTrueSmall: {
width: 8,
height: 8,
borderRadius: 2,
backgroundColor: '#ABCDEF',
justifyContent: 'center',
alignItems: 'center',
},
innerSmall: {
width: 7,
height: 7,
borderRadius: 1,
backgroundColor: '#223366',
},
innerTrueSmall: {
width: 7,
height: 7,
borderRadius: 1,
backgroundColor: '#334488',
},
});

export const examples: Props[] = [
Expand Down Expand Up @@ -204,6 +460,48 @@ export const examples: Props[] = [
);
},
},
{
title: 'Slider with customized indicator and no numbers',
render() {
return <SlidingStepsExample />;
},
},
{
title: 'Slider with customized indicator and default numbers',
render() {
return <SlidingStepsNumbersExample />;
},
},
{
title: 'Slider with smaller customized indicator and default numbers',
render() {
return <SlidingStepsSmallNumbersExample />;
},
},
{
title: 'Slider with custom steps, thumbImage and steps numbers',
render() {
return <SlidingCustomStepsThumbImageNumbersExample />;
},
},
{
title: 'Slider with custom steps, different thumbImage and steps numbers',
render() {
return <SlidingCustomStepsAnotherThumbImageNumbersExample />;
},
},
{
title: 'Slider with custom steps, different width and thumbImage',
render() {
return <SlidingCustomStepsThumbImageWithNumbersAndDifferentWidth />;
},
},
{
title: 'Inverted slider direction with steps number and thumbImage',
render() {
return <InvertedSliderWithStepMarker />;
},
},
{
title: 'Inverted slider direction',
render() {
Expand Down
Binary file added example/src/resources/ck-icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added example/src/resources/twitter-small.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -100,14 +100,11 @@ public long measure(
YogaMeasureMode widthMode,
float height,
YogaMeasureMode heightMode) {
if (!mMeasured) {
SeekBar reactSlider = new ReactSlider(getThemedContext(), null);
final int spec = View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED);
reactSlider.measure(spec, spec);
mWidth = reactSlider.getMeasuredWidth();
mHeight = reactSlider.getMeasuredHeight();
mMeasured = true;
}

return YogaMeasureOutput.make(mWidth, mHeight);
}
Expand Down
Loading