1
1
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' ;
3
3
import Reanimated , { useAnimatedStyle } from 'react-native-reanimated' ;
4
4
import { Spacings , Typography } from '../../style' ;
5
5
import { asBaseComponent } from '../../commons/new' ;
6
6
import TouchableOpacity from '../touchableOpacity' ;
7
7
import { SegmentedControlProps } from './index' ;
8
8
import Icon , { IconProps } from '../icon' ;
9
9
10
+ const ICON_SPACING = Spacings . s1 ;
11
+
10
12
export type SegmentedControlItemProps = Pick < SegmentedControlProps , 'segmentLabelStyle' > & {
11
13
/**
12
14
* The label of the segment.
@@ -112,7 +114,7 @@ const Segment = React.memo((props: SegmentProps) => {
112
114
onLayout ?.( index , event ) ;
113
115
} ,
114
116
[ onLayout , index ] ) ;
115
-
117
+ const labelMargins = ! ! iconSource && ( iconOnRight ? styles . rightMargin : styles . leftMargin ) ;
116
118
return (
117
119
< TouchableOpacity
118
120
onLayout = { segmentOnLayout }
@@ -128,7 +130,7 @@ const Segment = React.memo((props: SegmentProps) => {
128
130
< Reanimated . Text
129
131
fsTagName = { 'unmasked' }
130
132
numberOfLines = { 1 }
131
- style = { [ Typography . text90 , segmentLabelStyle , animatedTextStyle ] }
133
+ style = { [ Typography . text90 , segmentLabelStyle , animatedTextStyle , labelMargins ] }
132
134
>
133
135
{ label }
134
136
</ Reanimated . Text >
@@ -138,4 +140,14 @@ const Segment = React.memo((props: SegmentProps) => {
138
140
) ;
139
141
} ) ;
140
142
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
+
141
153
export default asBaseComponent < SegmentProps > ( Segment ) ;
0 commit comments