Skip to content

Commit 4870678

Browse files
authored
Fix/segmented control icon spacings (#3096)
* added spacings between icon and label * changed default object * changed variable name * moved variable location
1 parent cd0ce15 commit 4870678

File tree

1 file changed

+15
-3
lines changed

1 file changed

+15
-3
lines changed

src/components/segmentedControl/segment.tsx

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
import React, {useCallback, useMemo} from 'react';
2-
import {LayoutChangeEvent, ImageStyle, StyleProp, ViewStyle} from 'react-native';
2+
import {LayoutChangeEvent, ImageStyle, StyleProp, ViewStyle, StyleSheet} from 'react-native';
33
import Reanimated, {useAnimatedStyle} from 'react-native-reanimated';
44
import {Spacings, Typography} from '../../style';
55
import {asBaseComponent} from '../../commons/new';
66
import TouchableOpacity from '../touchableOpacity';
77
import {SegmentedControlProps} from './index';
88
import Icon, {IconProps} from '../icon';
99

10+
const ICON_SPACING = Spacings.s1;
11+
1012
export type SegmentedControlItemProps = Pick<SegmentedControlProps, 'segmentLabelStyle'> & {
1113
/**
1214
* The label of the segment.
@@ -112,7 +114,7 @@ const Segment = React.memo((props: SegmentProps) => {
112114
onLayout?.(index, event);
113115
},
114116
[onLayout, index]);
115-
117+
const labelMargins = !!iconSource && (iconOnRight ? styles.rightMargin : styles.leftMargin);
116118
return (
117119
<TouchableOpacity
118120
onLayout={segmentOnLayout}
@@ -128,7 +130,7 @@ const Segment = React.memo((props: SegmentProps) => {
128130
<Reanimated.Text
129131
fsTagName={'unmasked'}
130132
numberOfLines={1}
131-
style={[Typography.text90, segmentLabelStyle, animatedTextStyle]}
133+
style={[Typography.text90, segmentLabelStyle, animatedTextStyle, labelMargins]}
132134
>
133135
{label}
134136
</Reanimated.Text>
@@ -138,4 +140,14 @@ const Segment = React.memo((props: SegmentProps) => {
138140
);
139141
});
140142
Segment.displayName = 'SegmentedControl.Segment';
143+
144+
const styles = StyleSheet.create({
145+
leftMargin: {
146+
marginLeft: ICON_SPACING
147+
},
148+
rightMargin: {
149+
marginRight: ICON_SPACING
150+
}
151+
});
152+
141153
export default asBaseComponent<SegmentProps>(Segment);

0 commit comments

Comments
 (0)