Skip to content

Fix/button RTL support #898

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 7 commits into from
Aug 24, 2020
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
124 changes: 114 additions & 10 deletions src/components/button/__tests__/__snapshots__/index.spec.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -849,14 +849,27 @@ exports[`Button container size should have no padding of button is an icon butto
}
>
<Image
accessibilityRole="image"
accessible={false}
assetGroup="icons"
source={14}
style={
Array [
Object {
"marginRight": 8,
"tintColor": "#FFFFFF",
"tintColor": undefined,
},
undefined,
undefined,
undefined,
undefined,
Object {},
Array [
Object {
"marginRight": 8,
"tintColor": "#FFFFFF",
},
undefined,
],
]
}
/>
Expand Down Expand Up @@ -1643,13 +1656,26 @@ exports[`Button icon should apply color on icon 1`] = `
}
>
<Image
accessibilityRole="image"
accessible={false}
assetGroup="icons"
source={12}
style={
Array [
Object {
"tintColor": "green",
"tintColor": undefined,
},
undefined,
undefined,
undefined,
undefined,
Object {},
Array [
Object {
"tintColor": "green",
},
undefined,
],
]
}
/>
Expand Down Expand Up @@ -1684,13 +1710,26 @@ exports[`Button icon should apply color on icon 2`] = `
}
>
<Image
accessibilityRole="image"
accessible={false}
assetGroup="icons"
source={12}
style={
Array [
Object {
"tintColor": "#FF563D",
"tintColor": undefined,
},
undefined,
undefined,
undefined,
undefined,
Object {},
Array [
Object {
"tintColor": "#FF563D",
},
undefined,
],
]
}
/>
Expand Down Expand Up @@ -1725,16 +1764,29 @@ exports[`Button icon should include custom iconStyle provided as a prop 1`] = `
}
>
<Image
accessibilityRole="image"
accessible={false}
assetGroup="icons"
source={12}
style={
Array [
Object {
"tintColor": undefined,
},
Object {
"marginRight": 9,
"tintColor": "red",
},
undefined,
undefined,
undefined,
undefined,
Object {},
Array [
Object {
"tintColor": undefined,
},
Object {
"marginRight": 9,
"tintColor": "red",
},
],
]
}
/>
Expand Down Expand Up @@ -1771,13 +1823,26 @@ exports[`Button icon should return icon style according to different variations
}
>
<Image
accessibilityRole="image"
accessible={false}
assetGroup="icons"
source={12}
style={
Array [
Object {
"tintColor": "#00BBF2",
"tintColor": undefined,
},
undefined,
undefined,
undefined,
undefined,
Object {},
Array [
Object {
"tintColor": "#00BBF2",
},
undefined,
],
]
}
/>
Expand Down Expand Up @@ -1812,13 +1877,26 @@ exports[`Button icon should return icon style according to different variations
}
>
<Image
accessibilityRole="image"
accessible={false}
assetGroup="icons"
source={12}
style={
Array [
Object {
"tintColor": "#00BBF2",
"tintColor": undefined,
},
undefined,
undefined,
undefined,
undefined,
Object {},
Array [
Object {
"tintColor": "#00BBF2",
},
undefined,
],
]
}
/>
Expand Down Expand Up @@ -1853,13 +1931,26 @@ exports[`Button icon should return icon style according to different variations
}
>
<Image
accessibilityRole="image"
accessible={false}
assetGroup="icons"
source={12}
style={
Array [
Object {
"tintColor": undefined,
},
undefined,
undefined,
undefined,
undefined,
Object {},
Array [
Object {
"tintColor": undefined,
},
undefined,
],
]
}
/>
Expand Down Expand Up @@ -2795,13 +2886,26 @@ exports[`Button labelColor should return undefined color if this is an icon butt
}
>
<Image
accessibilityRole="image"
accessible={false}
assetGroup="icons"
source={12}
style={
Array [
Object {
"tintColor": undefined,
},
undefined,
undefined,
undefined,
undefined,
Object {},
Array [
Object {
"tintColor": undefined,
},
undefined,
],
]
}
/>
Expand Down
11 changes: 8 additions & 3 deletions src/components/button/index.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import React, {PureComponent} from 'react';
import {Platform, StyleSheet, LayoutAnimation, Image, LayoutChangeEvent, ImageStyle, TextStyle, StyleProp} from 'react-native';
import {Platform, StyleSheet, LayoutAnimation, LayoutChangeEvent, ImageStyle, TextStyle, StyleProp} from 'react-native';
import {Image} from 'react-native-ui-lib';
import _ from 'lodash';
import {
asBaseComponent,
Expand Down Expand Up @@ -56,6 +57,10 @@ export type ButtonPropTypes = TouchableOpacityProps &
* Should the icon be right to the label
*/
iconOnRight?: boolean;
/**
* whether the icon should flip horizontally on RTL locals
*/
supportRTL?: boolean;
/**
* Color of the button background
*/
Expand Down Expand Up @@ -447,14 +452,14 @@ class Button extends PureComponent<Props, ButtonState> {
}

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

if (iconSource) {
const iconStyle = this.getIconStyle();
if (typeof iconSource === 'function') {
return iconSource(iconStyle);
} else {
return <Image source={iconSource} style={iconStyle}/>;
return <Image source={iconSource} supportRTL={supportRTL} style={iconStyle}/>;
}
}
return null;
Expand Down