Skip to content

Commit 4024d1b

Browse files
authored
new segemntTypography prop (#2929)
* new segemntTypography prop * changed the name of the label style prop * added exmaple, fixed review notes * screen fixes * changed custom typo
1 parent b67092c commit 4024d1b

File tree

4 files changed

+33
-15
lines changed

4 files changed

+33
-15
lines changed

demo/src/screens/componentScreens/SegmentedControlScreen.tsx

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import React, {useCallback} from 'react';
22
import {StyleSheet} from 'react-native';
3-
import {Text, View, Colors, SegmentedControl, Assets, Spacings, BorderRadiuses} from 'react-native-ui-lib';
3+
import {Text, View, Colors, SegmentedControl, Assets, Spacings, BorderRadiuses, Typography} from 'react-native-ui-lib';
44

55
const segments = {
66
first: [{label: 'Left'}, {label: 'Right'}],
@@ -16,18 +16,21 @@ const segments = {
1616
],
1717
forth: [{label: 'With'}, {label: 'Custom'}, {label: 'Style'}],
1818
fifth: [{label: 'Full'}, {label: 'Width'}],
19-
sixth: [{label: 'Full'}, {label: 'Width'}, {label: 'With'}, {label: 'A'}, {label: 'Very Long Segment'}]
19+
sixth: [{label: 'Full'}, {label: 'Width'}, {label: 'With'}, {label: 'A'}, {label: 'Very Long Segment'}],
20+
seventh: [{label: '$'}, {label: '%'}]
2021
};
2122

2223
const SegmentedControlScreen = () => {
23-
2424
const onChangeIndex = useCallback((index: number) => {
2525
console.warn('Index ' + index + ' of the second segmentedControl was pressed');
2626
}, []);
2727

2828
return (
2929
<View flex bottom padding-page>
30-
<View flex centerV>
30+
<Text center text40 $textDefault>
31+
Segmented Control
32+
</Text>
33+
<View flex marginT-s8>
3134
<View center>
3235
<SegmentedControl segments={segments.first}/>
3336
<SegmentedControl
@@ -53,18 +56,17 @@ const SegmentedControlScreen = () => {
5356
segmentsStyle={styles.customSegmentsStyle}
5457
/>
5558
</View>
59+
<SegmentedControl containerStyle={styles.container} segments={segments.fifth}/>
60+
<SegmentedControl containerStyle={styles.container} segments={segments.sixth}/>
61+
<Text marginT-s4 center>
62+
Custom Typography
63+
</Text>
5664
<SegmentedControl
5765
containerStyle={styles.container}
58-
segments={segments.fifth}
59-
/>
60-
<SegmentedControl
61-
containerStyle={styles.container}
62-
segments={segments.sixth}
66+
segments={segments.seventh}
67+
segmentLabelStyle={styles.customTypography}
6368
/>
6469
</View>
65-
<Text text40 $textDefault>
66-
Segmented Control
67-
</Text>
6870
</View>
6971
);
7072
};
@@ -79,6 +81,9 @@ const styles = StyleSheet.create({
7981
},
8082
customSegmentsStyle: {
8183
height: 50
84+
},
85+
customTypography: {
86+
...Typography.text80BO
8287
}
8388
});
8489

src/components/segmentedControl/index.tsx

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import _ from 'lodash';
22
import React, {useRef, useCallback} from 'react';
3-
import {StyleSheet, StyleProp, ViewStyle, LayoutChangeEvent} from 'react-native';
3+
import {StyleSheet, StyleProp, ViewStyle, TextStyle, LayoutChangeEvent} from 'react-native';
44
import Reanimated, {
55
Easing,
66
useAnimatedReaction,
@@ -74,6 +74,10 @@ export type SegmentedControlProps = {
7474
* Additional style for the segment
7575
*/
7676
segmentsStyle?: StyleProp<ViewStyle>;
77+
/**
78+
* Segment label style
79+
*/
80+
segmentLabelStyle?: StyleProp<TextStyle>;
7781
/**
7882
* Additional spacing styles for the container
7983
*/
@@ -102,6 +106,7 @@ const SegmentedControl = (props: SegmentedControlProps) => {
102106
outlineWidth = BORDER_WIDTH,
103107
throttleTime = 0,
104108
segmentsStyle: segmentsStyleProp,
109+
segmentLabelStyle,
105110
testID
106111
} = props;
107112
const animatedSelectedIndex = useSharedValue(initialIndex);
@@ -171,6 +176,7 @@ const SegmentedControl = (props: SegmentedControlProps) => {
171176
activeColor={activeColor}
172177
inactiveColor={inactiveColor}
173178
style={segmentsStyleProp}
179+
segmentLabelStyle={segmentLabelStyle}
174180
{...segments?.[index]}
175181
testID={testID}
176182
/>

src/components/segmentedControl/segment.tsx

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,9 @@ import Reanimated, {useAnimatedStyle} from 'react-native-reanimated';
44
import {Spacings, Typography} from '../../style';
55
import {asBaseComponent} from '../../commons/new';
66
import TouchableOpacity from '../touchableOpacity';
7+
import {SegmentedControlProps} from './index';
78

8-
export type SegmentedControlItemProps = {
9+
export type SegmentedControlItemProps = Pick<SegmentedControlProps, 'segmentLabelStyle'> & {
910
/**
1011
* The label of the segment.
1112
*/
@@ -72,6 +73,7 @@ const Segment = React.memo((props: SegmentProps) => {
7273
index,
7374
iconOnRight,
7475
style,
76+
segmentLabelStyle,
7577
testID
7678
} = props;
7779

@@ -116,7 +118,11 @@ const Segment = React.memo((props: SegmentProps) => {
116118
>
117119
{!iconOnRight && renderIcon()}
118120
{label && (
119-
<Reanimated.Text fsTagName={'unmasked'} numberOfLines={1} style={[animatedTextStyle, Typography.text90]}>
121+
<Reanimated.Text
122+
fsTagName={'unmasked'}
123+
numberOfLines={1}
124+
style={[Typography.text90, segmentLabelStyle, animatedTextStyle]}
125+
>
120126
{label}
121127
</Reanimated.Text>
122128
)}

src/components/segmentedControl/segmentedControl.api.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
{"name": "segmentsStyle", "type": "ViewStyle", "description": "Additional style for the segments"},
2020
{"name": "containerStyle", "type": "ViewStyle", "description": "Additional spacing styles for the container"},
2121
{"name": "style", "type": "ViewStyle", "description": "Custom style to inner container"},
22+
{"name": "segmentLabelStyle", "type": "TextStyle", "description": "Segment label style"},
2223
{"name": "testID", "type": "string", "description": "Component test id"}
2324
],
2425
"snippet": [

0 commit comments

Comments
 (0)