Skip to content

Commit 804cc5c

Browse files
authored
chore: infer SVG size from style (#2742)
* chore: infer SVG size from style * code-review
1 parent 654cb22 commit 804cc5c

File tree

3 files changed

+23
-4
lines changed

3 files changed

+23
-4
lines changed

src/components/button/ButtonTypes.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,10 @@ export type ButtonProps = TouchableOpacityProps &
5151
* Icon image style
5252
*/
5353
iconStyle?: StyleProp<ImageStyle>;
54+
/**
55+
* Other image props that will be passed to the image
56+
*/
57+
iconProps?: Partial<ImageProps>;
5458
/**
5559
* Should the icon be right to the label
5660
*/
@@ -171,7 +175,7 @@ export const DEFAULT_PROPS = {
171175
* @gif: https://github.com/wix/react-native-ui-lib/blob/master/demo/showcase/Button/Button%20Animated.gif?raw=true
172176
* @example: https://github.com/wix/react-native-ui-lib/blob/master/demo/src/screens/componentScreens/ButtonsScreen.tsx
173177
*/
174-
// @ts-ignore
178+
// @ts-ignore
175179
class FakeButtonForDocs extends PureComponent<ButtonProps> { // eslint-disable-line
176180
static displayName = 'Button';
177181

src/components/button/button.api.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
"description": "Icon image source or a callback function that returns a source"
2626
},
2727
{"name": "iconStyle", "type": "ImageStyle", "description": "Icon image style"},
28+
{"name": "iconProps", "type": "Partial<ImageProps>", "description": "Icon image props"},
2829
{"name": "iconOnRight", "type": "boolean", "description": "Should the icon be right to the label"},
2930
{"name": "supportRTL", "type": "boolean", "description": "whether the icon should flip horizontally on RTL locals"},
3031
{"name": "backgroundColor", "type": "string", "description": "Color of the button background"},

src/components/button/index.tsx

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,7 @@ class Button extends PureComponent<Props, ButtonState> {
292292
}
293293

294294
renderIcon() {
295-
const {iconSource, supportRTL, testID} = this.props;
295+
const {iconSource, supportRTL, testID, iconProps} = this.props;
296296

297297
if (iconSource) {
298298
const iconStyle = this.getIconStyle();
@@ -302,10 +302,24 @@ class Button extends PureComponent<Props, ButtonState> {
302302
} else {
303303
if (Constants.isWeb) {
304304
return (
305-
<Icon style={iconStyle} tintColor={Colors.$iconDefault} source={iconSource} testID={`${testID}.icon`}/>
305+
<Icon
306+
style={iconStyle}
307+
tintColor={Colors.$iconDefault}
308+
source={iconSource}
309+
testID={`${testID}.icon`}
310+
{...iconProps}
311+
/>
306312
);
307313
}
308-
return <Image source={iconSource} supportRTL={supportRTL} style={iconStyle} testID={`${testID}.icon`}/>;
314+
return (
315+
<Image
316+
source={iconSource}
317+
supportRTL={supportRTL}
318+
style={iconStyle}
319+
testID={`${testID}.icon`}
320+
{...iconProps}
321+
/>
322+
);
309323
}
310324
}
311325
return null;

0 commit comments

Comments
 (0)