Skip to content

Commit be548ef

Browse files
authored
Fix icons getting cut off (#763)
1 parent 8579574 commit be548ef

File tree

3 files changed

+32
-5
lines changed

3 files changed

+32
-5
lines changed

packages/core/src/components/Checkbox/Checkbox.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ const Checkbox: React.FC<CheckboxProps & PressableProps & IconSlot> = ({
9292
accessibilityState={{ disabled }}
9393
accessibilityRole="button"
9494
accessibilityLiveRegion="polite"
95-
style={[styles.container, style, { width: size, height: size }]}
95+
style={[styles.container, style]}
9696
>
9797
<Icon
9898
style={styles.icon}

packages/core/src/components/IconButton.tsx

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,6 @@ const IconButton: React.FC<React.PropsWithChildren<Props>> = ({
5252
styles.container,
5353
{
5454
opacity: pressed ? activeOpacity : disabled ? disabledOpacity : 1,
55-
width: size,
56-
height: size,
5755
alignItems: "center",
5856
justifyContent: "center",
5957
},

packages/native/src/components/Icon.tsx

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import {
66
StyleProp,
77
ImageStyle,
88
Platform,
9+
LayoutChangeEvent,
910
} from "react-native";
1011

1112
// This must use require to work in both web as a published project and in Snack
@@ -25,6 +26,16 @@ const Icon: React.FC<React.PropsWithChildren<Props>> = ({
2526
style,
2627
...rest
2728
}) => {
29+
const [calculatedIconWidth, setCalculatedIconWidth] =
30+
React.useState<number>();
31+
const [calculatedIconHeight, setCalculatedIconHeight] =
32+
React.useState<number>();
33+
34+
React.useEffect(() => {
35+
setCalculatedIconWidth(undefined);
36+
setCalculatedIconHeight(undefined);
37+
}, [name]);
38+
2839
if (!name) return null;
2940

3041
let iconSet = "MaterialIcons";
@@ -35,8 +46,26 @@ const Icon: React.FC<React.PropsWithChildren<Props>> = ({
3546
const IconSet = VectorIcons[iconSet];
3647

3748
return (
38-
<View style={[styles.container, { width: size, height: size }, style]}>
39-
<IconSet {...rest} name={name} color={color} size={size} />
49+
<View
50+
style={[
51+
styles.container,
52+
calculatedIconWidth && calculatedIconHeight
53+
? { width: calculatedIconWidth, height: calculatedIconHeight }
54+
: {},
55+
style,
56+
]}
57+
>
58+
<IconSet
59+
{...rest}
60+
onLayout={(e: LayoutChangeEvent) => {
61+
const layout = e.nativeEvent.layout;
62+
setCalculatedIconWidth(layout.width);
63+
setCalculatedIconHeight(layout.height);
64+
}}
65+
name={name}
66+
color={color}
67+
size={size}
68+
/>
4069
</View>
4170
);
4271
};

0 commit comments

Comments
 (0)