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 2 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
Original file line number Diff line number Diff line change
Expand Up @@ -855,6 +855,7 @@ exports[`Button container size should have no padding of button is an icon butto
Object {
"marginRight": 8,
"tintColor": "#FFFFFF",
"transform": undefined,
},
undefined,
]
Expand Down Expand Up @@ -1648,6 +1649,7 @@ exports[`Button icon should apply color on icon 1`] = `
Array [
Object {
"tintColor": "green",
"transform": undefined,
},
undefined,
]
Expand Down Expand Up @@ -1689,6 +1691,7 @@ exports[`Button icon should apply color on icon 2`] = `
Array [
Object {
"tintColor": "#FF563D",
"transform": undefined,
},
undefined,
]
Expand Down Expand Up @@ -1730,6 +1733,7 @@ exports[`Button icon should include custom iconStyle provided as a prop 1`] = `
Array [
Object {
"tintColor": undefined,
"transform": undefined,
},
Object {
"marginRight": 9,
Expand Down Expand Up @@ -1776,6 +1780,7 @@ exports[`Button icon should return icon style according to different variations
Array [
Object {
"tintColor": "#00BBF2",
"transform": undefined,
},
undefined,
]
Expand Down Expand Up @@ -1817,6 +1822,7 @@ exports[`Button icon should return icon style according to different variations
Array [
Object {
"tintColor": "#00BBF2",
"transform": undefined,
},
undefined,
]
Expand Down Expand Up @@ -1858,6 +1864,7 @@ exports[`Button icon should return icon style according to different variations
Array [
Object {
"tintColor": undefined,
"transform": undefined,
},
undefined,
]
Expand Down Expand Up @@ -2800,6 +2807,7 @@ exports[`Button labelColor should return undefined color if this is an icon butt
Array [
Object {
"tintColor": undefined,
"transform": undefined,
},
undefined,
]
Expand Down
10 changes: 8 additions & 2 deletions src/components/button/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,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 @@ -406,10 +410,12 @@ class Button extends PureComponent<Props, ButtonState> {
}

getIconStyle() {
const {disabled, iconStyle: propsIconStyle, iconOnRight} = this.props;
const {disabled, iconStyle: propsIconStyle, iconOnRight, supportRTL} = this.props;
const size = this.props.size || DEFAULT_SIZE;
const shouldFlipRTL = supportRTL && Constants.isRTL;
const iconStyle: ImageStyle = {
tintColor: this.getLabelColor()
tintColor: this.getLabelColor(),
transform: shouldFlipRTL ? [{scaleX: -1}] : undefined
};
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The Image already supports this feature, why not just pass forward the supportRTL prop


const marginSide = [Button.sizes.large, Button.sizes.medium].includes(size) ? 8 : 4;
Expand Down