Skip to content

chore: infer SVG size from style #2742

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

Merged
merged 2 commits into from
Sep 18, 2023
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
6 changes: 5 additions & 1 deletion src/components/button/ButtonTypes.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@ export type ButtonProps = TouchableOpacityProps &
* Icon image style
*/
iconStyle?: StyleProp<ImageStyle>;
/**
* Other image props that will be passed to the image
*/
iconProps?: Partial<ImageProps>;
/**
* Should the icon be right to the label
*/
Expand Down Expand Up @@ -171,7 +175,7 @@ export const DEFAULT_PROPS = {
* @gif: https://github.com/wix/react-native-ui-lib/blob/master/demo/showcase/Button/Button%20Animated.gif?raw=true
* @example: https://github.com/wix/react-native-ui-lib/blob/master/demo/src/screens/componentScreens/ButtonsScreen.tsx
*/
// @ts-ignore
// @ts-ignore
class FakeButtonForDocs extends PureComponent<ButtonProps> { // eslint-disable-line
static displayName = 'Button';

Expand Down
1 change: 1 addition & 0 deletions src/components/button/button.api.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
"description": "Icon image source or a callback function that returns a source"
},
{"name": "iconStyle", "type": "ImageStyle", "description": "Icon image style"},
{"name": "iconProps", "type": "Partial<ImageProps>", "description": "Icon image props"},
{"name": "iconOnRight", "type": "boolean", "description": "Should the icon be right to the label"},
{"name": "supportRTL", "type": "boolean", "description": "whether the icon should flip horizontally on RTL locals"},
{"name": "backgroundColor", "type": "string", "description": "Color of the button background"},
Expand Down
20 changes: 17 additions & 3 deletions src/components/button/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ class Button extends PureComponent<Props, ButtonState> {
}

renderIcon() {
const {iconSource, supportRTL, testID} = this.props;
const {iconSource, supportRTL, testID, iconProps} = this.props;

if (iconSource) {
const iconStyle = this.getIconStyle();
Expand All @@ -302,10 +302,24 @@ class Button extends PureComponent<Props, ButtonState> {
} else {
if (Constants.isWeb) {
return (
<Icon style={iconStyle} tintColor={Colors.$iconDefault} source={iconSource} testID={`${testID}.icon`}/>
<Icon
style={iconStyle}
tintColor={Colors.$iconDefault}
source={iconSource}
testID={`${testID}.icon`}
{...iconProps}
/>
);
}
return <Image source={iconSource} supportRTL={supportRTL} style={iconStyle} testID={`${testID}.icon`}/>;
return (
<Image
source={iconSource}
supportRTL={supportRTL}
style={iconStyle}
testID={`${testID}.icon`}
{...iconProps}
/>
);
}
}
return null;
Expand Down