Skip to content

Commit 3568409

Browse files
zakaryan2004Naturalclar
authored andcommitted
feat: Allow the slider component to be styled
Signed-off-by: Gegham Zakaryan <[email protected]>
1 parent a0eaabc commit 3568409

File tree

4 files changed

+35
-1
lines changed

4 files changed

+35
-1
lines changed

README.md

+9
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,15 @@ An object container
241241

242242
Extends [ViewStyles](https://reactnative.dev/docs/view-style-props)
243243

244+
### `sliderStyle`
245+
246+
(Android and Web only) Styles the slider component (Animated.View)
247+
| Type | Required | Platform |
248+
| ------ | -------- | -------- |
249+
| object | No | Android, Web |
250+
251+
Extends [ViewStyles](https://reactnative.dev/docs/view-style-props)
252+
244253
## Tips and Tricks
245254

246255
### How can I increase the height of the tab ?

index.d.ts

+5
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,11 @@ export interface SegmentedControlProps extends ViewProps {
111111
* Touchable style properties for Segmented Control Tab
112112
*/
113113
tabStyle?: ViewStyle;
114+
115+
/**
116+
* Style properties for the Animated.View component
117+
*/
118+
sliderStyle?: ViewStyle;
114119
}
115120

116121
/**

js/SegmentedControl.js

+18-1
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ const SegmentedControl = ({
3838
appearance,
3939
accessibilityHintSeperator = 'out of',
4040
testIDS,
41+
sliderStyle,
4142
}: SegmentedControlProps): React.Node => {
4243
const colorSchemeHook = useColorScheme();
4344
const colorScheme = appearance || colorSchemeHook;
@@ -100,7 +101,8 @@ const SegmentedControl = ({
100101
nativeEvent: {
101102
layout: {width},
102103
},
103-
}) => updateSegmentWidth(width)}>
104+
}) => updateSegmentWidth(width)}
105+
>
104106
{!backgroundColor && !tintColor && (
105107
<SegmentsSeparators
106108
values={values.length}
@@ -118,6 +120,7 @@ const SegmentedControl = ({
118120
backgroundColor:
119121
tintColor || (colorScheme === 'dark' ? '#636366' : 'white'),
120122
},
123+
sliderStyle,
121124
]}
122125
/>
123126
) : null}
@@ -148,6 +151,20 @@ const SegmentedControl = ({
148151
);
149152
})}
150153
</View>
154+
{selectedIndex != null && segmentWidth ? (
155+
<Animated.View
156+
style={[
157+
styles.slider,
158+
sliderStyle,
159+
{
160+
transform: [{translateX: animation}],
161+
width: segmentWidth - 4,
162+
backgroundColor:
163+
tintColor || (colorScheme === 'dark' ? '#636366' : 'white'),
164+
},
165+
]}
166+
/>
167+
) : null}
151168
</View>
152169
);
153170
};

js/types.js

+3
Original file line numberDiff line numberDiff line change
@@ -112,4 +112,7 @@ export type SegmentedControlProps = $ReadOnly<{|
112112
* array testID to each segment button
113113
*/
114114
testIDS: $ReadOnlyArray<string>,
115+
* Style properties for the slider component (Animated.View)
116+
*/
117+
sliderStyle?: ViewStyle,
115118
|}>;

0 commit comments

Comments
 (0)