Skip to content

Commit 3d8b36f

Browse files
Merge branch 'main' into 'navigation'
# Conflicts: # src/index.tsx
2 parents e3e5edc + fd1be1e commit 3d8b36f

21 files changed

+965
-1
lines changed

README.md

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1051,6 +1051,70 @@ export const MyScreen = () => {
10511051

10521052
![left side sheet](https://ik.imagekit.io/Computools/rn-material-components/left-side-sheet.gif?updatedAt=1706170982231)
10531053
![right side sheet](https://ik.imagekit.io/Computools/rn-material-components/right-side-sheet.gif?updatedAt=1706171192408)
1054+
</details>
1055+
</details>
1056+
<details><summary>Sliders</summary>
1057+
<br />
1058+
<details><summary>Slider</summary>
1059+
<br />
1060+
1061+
**Properties**
1062+
1063+
| name | description | type | default |
1064+
| ------ | ------ | ------ | ---- |
1065+
| max | required | number | - |
1066+
| min | required | number | - |
1067+
| value | - | number | 0 |
1068+
| step | The slider operates in discrete mode when a step value is provided. | number | - |
1069+
| onChangeValue | - | (value: number) => void | - |
1070+
| disabled | - | boolean | false |
1071+
| centered | The slider operates in centered mode when a centered props is true | number | boolean | false |
1072+
| damping | Controls thumb animation when a track point is pressed. | number | 20 |
1073+
| valueHeight | - | number | 44 |
1074+
| thumbWidthActive | - | number | 2 |
1075+
| thumbWidthInactive | - | number | 4 |
1076+
| thumbStyle | - | ViewStyle | - |
1077+
| valueStyle | - | ViewStyle | - |
1078+
| indicatorStyle | - | ViewStyle | - |
1079+
| trackPointStyle | - | ViewStyle | - |
1080+
| trackPointsStyle | - | ViewStyle | - |
1081+
| filledTrackStyle | - | ViewStyle | - |
1082+
| remainingTrackStyle | - | ViewStyle | - |
1083+
1084+
![continuous slider](https://ik.imagekit.io/Computools/rn-material-components/continuous-slider.gif?updatedAt=1734970059184)
1085+
![centered slider](https://ik.imagekit.io/Computools/rn-material-components/centered-slider.gif?updatedAt=1734970059052)
1086+
![discrete slider](https://ik.imagekit.io/Computools/rn-material-components/discrete-slider.gif?updatedAt=1734970059069)
1087+
1088+
</details>
1089+
<details><summary>Range Slider</summary>
1090+
<br />
1091+
1092+
**Properties**
1093+
1094+
| name | description | type | default |
1095+
| ------ | ------ | ------ | ---- |
1096+
| max | required | number | - |
1097+
| min | required | number | - |
1098+
| range | The first element represents the minimum value, and the second represents the maximum value. The range must have exactly two elements, with the minimum value less than or equal to the maximum value. | number | - |
1099+
| step | The slider operates in discrete mode when a step value is provided. | number | - |
1100+
| onChangeValue | - | (value: number) => void | - |
1101+
| disabled | - | boolean | false |
1102+
| centered | The slider operates in centered mode when a centered props is true | number | boolean | false |
1103+
| damping | Controls thumb animation when a track point is pressed. | number | 20 |
1104+
| valueHeight | - | number | 44 |
1105+
| thumbWidthActive | - | number | 2 |
1106+
| thumbWidthInactive | - | number | 4 |
1107+
| thumbStyle | - | ViewStyle | - |
1108+
| valueStyle | - | ViewStyle | - |
1109+
| indicatorStyle | - | ViewStyle | - |
1110+
| trackPointStyle | - | ViewStyle | - |
1111+
| trackPointsStyle | - | ViewStyle | - |
1112+
| filledTrackStyle | - | ViewStyle | - |
1113+
| remainingTrackStyle | - | ViewStyle | - |
1114+
1115+
![range slider](https://ik.imagekit.io/Computools/rn-material-components/range-slider.gif?updatedAt=1734970059452)
1116+
![discrete range slider](https://ik.imagekit.io/Computools/rn-material-components/continuous-slider.gif?updatedAt=1734970059184)
1117+
10541118
</details>
10551119
</details>
10561120
<details><summary>Snackbar</summary>

src/index.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,13 @@ export {Badge, type BadgeProps} from './badge/Badge.component';
55
export {Divider, type DividerProps} from './divider/Divider.component';
66

77
export {NavBar} from './navigation/navigation-bar/NavBar.component';
8+
export {Slider, type SliderProps} from './sliders/slider /Slider.component';
9+
export {RangeSlider, type RangeSliderProps} from './sliders/range-slider/RangeSlider.component';
810

911
export {InputChip, type InputChipProps} from './chips/input-chip/InputChip.component';
1012
export {FilterChip, type FilterChipProps} from './chips/filter-chip/FilterChip.component';
11-
export {SuggestionChip, type SuggestionChipProps} from './chips/suggestion-chip/SuggestionChip.component';
1213
export {AssistChip, type AssistChipProps, IconType} from './chips/assist-chip/AssistChip.component';
14+
export {SuggestionChip, type SuggestionChipProps} from './chips/suggestion-chip/SuggestionChip.component';
1315

1416
export {PrimaryTabs, type PrimaryTabsProps} from './navigation/tabs/primary-tabs/PrimaryTabs.component';
1517
export {SecondaryTabs, type SecondaryTabsProps} from './navigation/tabs/secondary-tabs/SecondaryTabs.component';
Lines changed: 138 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,138 @@
1+
import React from 'react';
2+
import {View} from 'react-native';
3+
import {GestureDetector} from 'react-native-gesture-handler';
4+
import {type LayoutChangeEvent, type ViewProps, type StyleProp, type ViewStyle, type TextStyle} from 'react-native';
5+
6+
import {styles} from './range-slider.styles';
7+
import {useRangeSlider} from './useRangeSlider.hook';
8+
import {useSliderColors} from '../use-slider-colors.hook';
9+
import {SliderTrack} from '../ui/slider-track/SliderTrack.component';
10+
import {useRangeSliderTrackPoints} from './useRangeSliderTrackPoints.hook';
11+
import {SliderIndicator} from '../ui/slider-indicator/SliderIndicator.component';
12+
import {SliderTrackPoint} from '../ui/slider-track-point/SliderTrackPoint.component';
13+
14+
export interface RangeSliderProps extends ViewProps {
15+
max: number;
16+
min: number;
17+
18+
range?: number[];
19+
step?: number;
20+
damping?: number;
21+
centered?: boolean;
22+
disabled?: boolean;
23+
24+
valueHeight?: number;
25+
thumbWidthActive?: number;
26+
thumbWidthInactive?: number;
27+
28+
thumbStyle?: StyleProp<ViewStyle>;
29+
valueStyle?: StyleProp<TextStyle>;
30+
indicatorStyle?: StyleProp<ViewStyle>;
31+
trackPointStyle?: StyleProp<ViewStyle>;
32+
trackPointsStyle?: StyleProp<ViewStyle>;
33+
filledTrackStyle?: StyleProp<ViewStyle>;
34+
remainingTrackStyle?: StyleProp<ViewStyle>;
35+
36+
onChangeRange?: (range: number[]) => void;
37+
}
38+
39+
export const RangeSlider: React.FC<RangeSliderProps> = ({
40+
max,
41+
min,
42+
43+
step,
44+
range = [0, 0],
45+
damping = 20,
46+
centered = false,
47+
disabled = false,
48+
49+
thumbStyle,
50+
valueStyle,
51+
indicatorStyle,
52+
trackPointStyle,
53+
trackPointsStyle,
54+
filledTrackStyle,
55+
remainingTrackStyle,
56+
57+
valueHeight,
58+
thumbWidthActive,
59+
thumbWidthInactive,
60+
61+
onChangeRange,
62+
onLayout,
63+
style,
64+
...props
65+
}) => {
66+
const {filledTrackColor, remainingTrackColor} = useSliderColors(disabled, centered);
67+
68+
const trackPoints = useRangeSliderTrackPoints({max, min, step, centered});
69+
const {
70+
gesture,
71+
selectedRange,
72+
thumbMinSliding,
73+
thumbMaxSliding,
74+
animMinValueProps,
75+
animMaxValueProps,
76+
filledTrackAnimatedStyle,
77+
remainingTrackAfterAnimatedStyle,
78+
remainingTrackBeforeAnimatedStyle,
79+
slideToTrackPoint,
80+
setUpSliderLayout,
81+
} = useRangeSlider({max, min, centered, step, damping}, range, onChangeRange);
82+
83+
const handleLayoutChange = (e: LayoutChangeEvent) => {
84+
setUpSliderLayout(e);
85+
86+
if (onLayout) {
87+
onLayout(e);
88+
}
89+
};
90+
91+
const renderTrackPoint = (pointValue: number) => (
92+
<SliderTrackPoint
93+
key={pointValue}
94+
value={pointValue}
95+
disabled={disabled}
96+
selectedValue={selectedRange}
97+
onPress={slideToTrackPoint}
98+
style={trackPointStyle}
99+
/>
100+
);
101+
102+
return (
103+
<GestureDetector gesture={gesture.enabled(!disabled)}>
104+
<View style={[styles.container, style]} onLayout={handleLayoutChange} {...props}>
105+
<SliderTrack
106+
style={[{backgroundColor: remainingTrackColor}, styles.remainingBeforeTrack, remainingTrackBeforeAnimatedStyle, filledTrackStyle]}
107+
/>
108+
<SliderIndicator
109+
animValueProps={animMinValueProps}
110+
sliding={thumbMinSliding}
111+
disabled={disabled}
112+
style={[styles.thumb, indicatorStyle]}
113+
thumbStyle={thumbStyle}
114+
valueStyle={valueStyle}
115+
valueHeight={valueHeight}
116+
thumbWidthActive={thumbWidthActive}
117+
thumbWidthInactive={thumbWidthInactive}
118+
/>
119+
<SliderTrack style={[{backgroundColor: filledTrackColor}, styles.filledTrack, filledTrackAnimatedStyle, filledTrackStyle]} />
120+
<SliderIndicator
121+
animValueProps={animMaxValueProps}
122+
sliding={thumbMaxSliding}
123+
disabled={disabled}
124+
style={[styles.thumb, indicatorStyle]}
125+
thumbStyle={thumbStyle}
126+
valueStyle={valueStyle}
127+
valueHeight={valueHeight}
128+
thumbWidthActive={thumbWidthActive}
129+
thumbWidthInactive={thumbWidthInactive}
130+
/>
131+
<SliderTrack
132+
style={[{backgroundColor: remainingTrackColor}, styles.remainingAfterTrack, remainingTrackAfterAnimatedStyle, remainingTrackStyle]}
133+
/>
134+
<View style={[styles.trackPoints, trackPointsStyle]}>{trackPoints.map(renderTrackPoint)}</View>
135+
</View>
136+
</GestureDetector>
137+
);
138+
};
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import {StyleSheet} from 'react-native';
2+
3+
export const styles = StyleSheet.create({
4+
container: {
5+
flexDirection: 'row',
6+
alignItems: 'center',
7+
},
8+
thumb: {
9+
zIndex: 1,
10+
},
11+
trackPoints: {
12+
position: 'absolute',
13+
14+
flexDirection: 'row',
15+
justifyContent: 'space-between',
16+
17+
width: '100%',
18+
paddingHorizontal: 4,
19+
},
20+
filledTrack: {
21+
borderRadius: 2,
22+
},
23+
remainingBeforeTrack: {
24+
borderTopEndRadius: 2,
25+
borderBottomEndRadius: 2,
26+
borderTopStartRadius: 16,
27+
borderBottomStartRadius: 16,
28+
},
29+
remainingAfterTrack: {
30+
justifyContent: 'center',
31+
32+
borderTopEndRadius: 16,
33+
borderBottomEndRadius: 16,
34+
borderTopStartRadius: 2,
35+
borderBottomStartRadius: 2,
36+
},
37+
});

0 commit comments

Comments
 (0)