Skip to content

Commit 3c8a339

Browse files
committed
fix: use same color for button text and icon (#1894)
1 parent e5b2325 commit 3c8a339

File tree

3 files changed

+13
-7
lines changed

3 files changed

+13
-7
lines changed

example/src/Examples/ButtonExample.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,12 +70,13 @@ const ButtonExample = () => {
7070
Loading
7171
</Button>
7272
<Button
73+
icon="heart"
7374
mode="outlined"
7475
onPress={() => {}}
7576
style={styles.button}
7677
labelStyle={{
7778
fontWeight: '800',
78-
fontSize: 18,
79+
fontSize: 24,
7980
}}
8081
>
8182
Custom Font

src/components/Button.tsx

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,10 @@ class Button extends React.Component<Props, State> {
245245
? StyleSheet.flatten(style).borderRadius || roundness
246246
: roundness,
247247
};
248+
249+
const { color: customLabelColor, fontSize: customLabelSize } =
250+
StyleSheet.flatten(labelStyle) || {};
251+
248252
const textStyle = { color: textColor, ...font };
249253
const elevation =
250254
disabled || mode !== 'contained' ? 0 : this.state.elevation;
@@ -279,13 +283,17 @@ class Button extends React.Component<Props, State> {
279283
<View style={[styles.content, contentStyle]}>
280284
{icon && loading !== true ? (
281285
<View style={styles.icon}>
282-
<Icon source={icon} size={16} color={textColor} />
286+
<Icon
287+
source={icon}
288+
size={customLabelSize || 16}
289+
color={customLabelColor || textColor}
290+
/>
283291
</View>
284292
) : null}
285293
{loading ? (
286294
<ActivityIndicator
287-
size={16}
288-
color={textColor}
295+
size={customLabelSize || 16}
296+
color={customLabelColor || textColor}
289297
style={styles.icon}
290298
/>
291299
) : null}
@@ -323,7 +331,6 @@ const styles = StyleSheet.create({
323331
justifyContent: 'center',
324332
},
325333
icon: {
326-
width: 16,
327334
marginLeft: 12,
328335
marginRight: -4,
329336
},

src/components/__tests__/__snapshots__/Button.test.js.snap

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,6 @@ exports[`renders button with icon 1`] = `
240240
Object {
241241
"marginLeft": 12,
242242
"marginRight": -4,
243-
"width": 16,
244243
}
245244
}
246245
>
@@ -576,7 +575,6 @@ exports[`renders loading button 1`] = `
576575
Object {
577576
"marginLeft": 12,
578577
"marginRight": -4,
579-
"width": 16,
580578
},
581579
]
582580
}

0 commit comments

Comments
 (0)