Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix icons getting cut off (47) #764

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/core/src/components/Checkbox/Checkbox.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ const Checkbox: React.FC<CheckboxProps & PressableProps & IconSlot> = ({
accessibilityState={{ disabled }}
accessibilityRole="button"
accessibilityLiveRegion="polite"
style={[styles.container, style, { width: size, height: size }]}
style={[styles.container, style]}
>
<Icon
style={styles.icon}
Expand Down
2 changes: 0 additions & 2 deletions packages/core/src/components/IconButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,6 @@ const IconButton: React.FC<React.PropsWithChildren<Props>> = ({
styles.container,
{
opacity: pressed ? activeOpacity : disabled ? disabledOpacity : 1,
width: size,
height: size,
alignItems: "center",
justifyContent: "center",
},
Expand Down
33 changes: 31 additions & 2 deletions packages/native/src/components/Icon.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
StyleProp,
ImageStyle,
Platform,
LayoutChangeEvent,
} from "react-native";

// This must use require to work in both web as a published project and in Snack
Expand All @@ -25,6 +26,16 @@ const Icon: React.FC<React.PropsWithChildren<Props>> = ({
style,
...rest
}) => {
const [calculatedIconWidth, setCalculatedIconWidth] =
React.useState<number>();
const [calculatedIconHeight, setCalculatedIconHeight] =
React.useState<number>();

React.useEffect(() => {
setCalculatedIconWidth(undefined);
setCalculatedIconHeight(undefined);
}, [name]);

if (!name) return null;

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

return (
<View style={[styles.container, { width: size, height: size }, style]}>
<IconSet {...rest} name={name} color={color} size={size} />
<View
style={[
styles.container,
calculatedIconWidth && calculatedIconHeight
? { width: calculatedIconWidth, height: calculatedIconHeight }
: {},
style,
]}
>
<IconSet
{...rest}
onLayout={(e: LayoutChangeEvent) => {
const layout = e.nativeEvent.layout;
setCalculatedIconWidth(layout.width);
setCalculatedIconHeight(layout.height);
}}
name={name}
color={color}
size={size}
/>
</View>
);
};
Expand Down
Loading