feat: RTL support. closes #434, #375

This commit is contained in:
iyad
2018-06-27 21:22:32 +03:00
committed by Satyajit Sahoo
parent 787379005a
commit e49ba4e661
14 changed files with 943 additions and 209 deletions

View File

@@ -1,7 +1,7 @@
/* @flow */
import * as React from 'react';
import { View, Image, StyleSheet, Platform } from 'react-native';
import { View, Image, I18nManager, StyleSheet, Platform } from 'react-native';
import AppbarAction from './AppbarAction';
@@ -46,14 +46,23 @@ class AppbarBackAction extends React.Component<Props> {
icon={
Platform.OS === 'ios'
? ({ size, color }) => (
<View style={[styles.wrapper, { width: size, height: size }]}>
<View
style={[
styles.wrapper,
{
width: size,
height: size,
transform: [{ scaleX: I18nManager.isRTL ? -1 : 1 }],
},
]}
>
<Image
source={require('../../assets/back-chevron.png')}
style={[styles.icon, { tintColor: color }]}
/>
</View>
)
: 'arrow-back'
: { source: 'arrow-back', direction: 'auto' }
}
/>
);

View File

@@ -1,7 +1,8 @@
/* @flow */
import * as React from 'react';
import { Image, Text, StyleSheet } from 'react-native';
import { Image, Text, StyleSheet, I18nManager } from 'react-native';
import type { ImageSource } from 'react-native/Libraries/Image/ImageSource';
let MaterialIcons;
@@ -27,10 +28,11 @@ try {
};
}
type IconSourceBase = string | ImageSource;
export type IconSource =
| string
| number
| { uri: string }
| IconSourceBase
| $ReadOnly<{ source: IconSourceBase, direction: 'rtl' | 'ltr' | 'auto' }>
| ((props: IconProps) => React.Node);
type IconProps = {
@@ -71,25 +73,46 @@ export const isEqualIcon = (a: any, b: any) =>
a === b || getIconId(a) === getIconId(b);
const Icon = ({ source, color, size, ...rest }: Props) => {
if (typeof source === 'string') {
const direction =
typeof source === 'object' && source.direction && source.source
? source.direction === 'auto'
? I18nManager.isRTL
? 'rtl'
: 'ltr'
: source.direction
: null;
const s =
typeof source === 'object' && source.direction && source.source
? source.source
: source;
if (typeof s === 'string') {
return (
<MaterialIcons
{...rest}
name={source}
name={s}
color={color}
size={size}
style={styles.icon}
style={[
{
transform: [{ scaleX: direction === 'rtl' ? -1 : 1 }],
},
styles.icon,
]}
pointerEvents="none"
accessibilityElementsHidden
importantForAccessibility="no-hide-descendants"
/>
);
} else if (isImageSource(source)) {
} else if (isImageSource(s)) {
return (
<Image
{...rest}
source={source}
source={s}
style={[
{
transform: [{ scaleX: direction === 'rtl' ? -1 : 1 }],
},
{
width: size,
height: size,
@@ -101,8 +124,8 @@ const Icon = ({ source, color, size, ...rest }: Props) => {
importantForAccessibility="no-hide-descendants"
/>
);
} else if (typeof source === 'function') {
return source({ color, size });
} else if (typeof s === 'function') {
return s({ color, size });
}
return null;

View File

@@ -2,6 +2,7 @@
import color from 'color';
import * as React from 'react';
import { I18nManager } from 'react-native';
import Text from './Text';
import { withTheme } from '../../core/theming';
import type { Theme } from '../../types';
@@ -21,11 +22,16 @@ class StyledText extends React.Component<Props> {
.rgb()
.string();
const fontFamily = theme.fonts[family];
const writingDirection = I18nManager.isRTL ? 'rtl' : 'ltr';
return (
<Text
{...rest}
style={[{ color: textColor, fontFamily }, style, this.props.style]}
style={[
{ color: textColor, fontFamily, textAlign: 'left', writingDirection },
style,
this.props.style,
]}
/>
);
}

View File

@@ -1,7 +1,7 @@
/* @flow */
import * as React from 'react';
import { Text as NativeText } from 'react-native';
import { Text as NativeText, I18nManager } from 'react-native';
import { withTheme } from '../../core/theming';
import type { Theme } from '../../types';
@@ -30,6 +30,7 @@ class Text extends React.Component<Props> {
render() {
const { style, theme } = this.props;
const writingDirection = I18nManager.isRTL ? 'rtl' : 'ltr';
return (
<NativeText
@@ -38,7 +39,12 @@ class Text extends React.Component<Props> {
this._root = c;
}}
style={[
{ fontFamily: theme.fonts.regular, color: theme.colors.text },
{
fontFamily: theme.fonts.regular,
color: theme.colors.text,
textAlign: 'left',
writingDirection,
},
style,
]}
/>

View File

@@ -59,6 +59,8 @@ exports[`renders button with color 1`] = `
Object {
"color": "#000000",
"fontFamily": "Helvetica Neue",
"textAlign": "left",
"writingDirection": "ltr",
},
Array [
Object {
@@ -179,9 +181,18 @@ exports[`renders button with icon 1`] = `
"color": "#6200ee",
"fontSize": 16,
},
Object {
"backgroundColor": "transparent",
},
Array [
Object {
"transform": Array [
Object {
"scaleX": 1,
},
],
},
Object {
"backgroundColor": "transparent",
},
],
Object {
"fontFamily": "Material Icons",
"fontStyle": "normal",
@@ -203,6 +214,8 @@ exports[`renders button with icon 1`] = `
Object {
"color": "#000000",
"fontFamily": "Helvetica Neue",
"textAlign": "left",
"writingDirection": "ltr",
},
Array [
Object {
@@ -319,6 +332,8 @@ exports[`renders contained contained with mode 1`] = `
Object {
"color": "#000000",
"fontFamily": "Helvetica Neue",
"textAlign": "left",
"writingDirection": "ltr",
},
Array [
Object {
@@ -432,6 +447,8 @@ exports[`renders disabled button 1`] = `
Object {
"color": "#000000",
"fontFamily": "Helvetica Neue",
"textAlign": "left",
"writingDirection": "ltr",
},
Array [
Object {
@@ -553,6 +570,8 @@ exports[`renders loading button 1`] = `
Object {
"color": "#000000",
"fontFamily": "Helvetica Neue",
"textAlign": "left",
"writingDirection": "ltr",
},
Array [
Object {
@@ -661,6 +680,8 @@ exports[`renders outlined button with mode 1`] = `
Object {
"color": "#000000",
"fontFamily": "Helvetica Neue",
"textAlign": "left",
"writingDirection": "ltr",
},
Array [
Object {
@@ -769,6 +790,8 @@ exports[`renders text button by default 1`] = `
Object {
"color": "#000000",
"fontFamily": "Helvetica Neue",
"textAlign": "left",
"writingDirection": "ltr",
},
Array [
Object {
@@ -877,6 +900,8 @@ exports[`renders text button with mode 1`] = `
Object {
"color": "#000000",
"fontFamily": "Helvetica Neue",
"textAlign": "left",
"writingDirection": "ltr",
},
Array [
Object {

View File

@@ -75,9 +75,18 @@ exports[`renders chip with icon 1`] = `
"color": "rgba(0, 0, 0, 0.54)",
"fontSize": 18,
},
Object {
"backgroundColor": "transparent",
},
Array [
Object {
"transform": Array [
Object {
"scaleX": 1,
},
],
},
Object {
"backgroundColor": "transparent",
},
],
Object {
"fontFamily": "Material Icons",
"fontStyle": "normal",
@@ -99,6 +108,8 @@ exports[`renders chip with icon 1`] = `
Object {
"color": "#000000",
"fontFamily": "Helvetica Neue",
"textAlign": "left",
"writingDirection": "ltr",
},
Array [
Object {
@@ -207,6 +218,8 @@ exports[`renders chip with onPress 1`] = `
Object {
"color": "#000000",
"fontFamily": "Helvetica Neue",
"textAlign": "left",
"writingDirection": "ltr",
},
Array [
Object {
@@ -328,9 +341,18 @@ exports[`renders deletable chip 1`] = `
"color": "rgba(0, 0, 0, 0.54)",
"fontSize": 18,
},
Object {
"backgroundColor": "transparent",
},
Array [
Object {
"transform": Array [
Object {
"scaleX": 1,
},
],
},
Object {
"backgroundColor": "transparent",
},
],
Object {
"fontFamily": "Material Icons",
"fontStyle": "normal",
@@ -352,6 +374,8 @@ exports[`renders deletable chip 1`] = `
Object {
"color": "#000000",
"fontFamily": "Helvetica Neue",
"textAlign": "left",
"writingDirection": "ltr",
},
Array [
Object {
@@ -461,6 +485,8 @@ exports[`renders outlined disabled chip 1`] = `
Object {
"color": "#000000",
"fontFamily": "Helvetica Neue",
"textAlign": "left",
"writingDirection": "ltr",
},
Array [
Object {
@@ -583,9 +609,18 @@ exports[`renders selected chip 1`] = `
"color": "rgba(0, 0, 0, 0.54)",
"fontSize": 18,
},
Object {
"backgroundColor": "transparent",
},
Array [
Object {
"transform": Array [
Object {
"scaleX": 1,
},
],
},
Object {
"backgroundColor": "transparent",
},
],
Object {
"fontFamily": "Material Icons",
"fontStyle": "normal",
@@ -607,6 +642,8 @@ exports[`renders selected chip 1`] = `
Object {
"color": "#000000",
"fontFamily": "Helvetica Neue",
"textAlign": "left",
"writingDirection": "ltr",
},
Array [
Object {

View File

@@ -53,9 +53,18 @@ exports[`renders DrawerItem with icon 1`] = `
"color": "rgba(0, 0, 0, 0.68)",
"fontSize": 24,
},
Object {
"backgroundColor": "transparent",
},
Array [
Object {
"transform": Array [
Object {
"scaleX": 1,
},
],
},
Object {
"backgroundColor": "transparent",
},
],
Object {
"fontFamily": "Material Icons",
"fontStyle": "normal",
@@ -76,6 +85,8 @@ exports[`renders DrawerItem with icon 1`] = `
Object {
"color": "#000000",
"fontFamily": "Helvetica Neue",
"textAlign": "left",
"writingDirection": "ltr",
},
Array [
Object {
@@ -172,9 +183,18 @@ exports[`renders active DrawerItem 1`] = `
"color": "#6200ee",
"fontSize": 24,
},
Object {
"backgroundColor": "transparent",
},
Array [
Object {
"transform": Array [
Object {
"scaleX": 1,
},
],
},
Object {
"backgroundColor": "transparent",
},
],
Object {
"fontFamily": "Material Icons",
"fontStyle": "normal",
@@ -195,6 +215,8 @@ exports[`renders active DrawerItem 1`] = `
Object {
"color": "#000000",
"fontFamily": "Helvetica Neue",
"textAlign": "left",
"writingDirection": "ltr",
},
Array [
Object {
@@ -288,6 +310,8 @@ exports[`renders basic DrawerItem 1`] = `
Object {
"color": "#000000",
"fontFamily": "Helvetica Neue",
"textAlign": "left",
"writingDirection": "ltr",
},
Array [
Object {

View File

@@ -105,9 +105,18 @@ exports[`renders extended FAB 1`] = `
"color": "rgba(0, 0, 0, .54)",
"fontSize": 24,
},
Object {
"backgroundColor": "transparent",
},
Array [
Object {
"transform": Array [
Object {
"scaleX": 1,
},
],
},
Object {
"backgroundColor": "transparent",
},
],
Object {
"fontFamily": "Material Icons",
"fontStyle": "normal",
@@ -129,6 +138,8 @@ exports[`renders extended FAB 1`] = `
Object {
"color": "#000000",
"fontFamily": "Helvetica Neue",
"textAlign": "left",
"writingDirection": "ltr",
},
Array [
Object {
@@ -275,9 +286,18 @@ exports[`renders normal FAB 1`] = `
"color": "rgba(0, 0, 0, .54)",
"fontSize": 24,
},
Object {
"backgroundColor": "transparent",
},
Array [
Object {
"transform": Array [
Object {
"scaleX": 1,
},
],
},
Object {
"backgroundColor": "transparent",
},
],
Object {
"fontFamily": "Material Icons",
"fontStyle": "normal",
@@ -399,9 +419,18 @@ exports[`renders small FAB 1`] = `
"color": "rgba(0, 0, 0, .54)",
"fontSize": 24,
},
Object {
"backgroundColor": "transparent",
},
Array [
Object {
"transform": Array [
Object {
"scaleX": 1,
},
],
},
Object {
"backgroundColor": "transparent",
},
],
Object {
"fontFamily": "Material Icons",
"fontStyle": "normal",

View File

@@ -58,9 +58,18 @@ exports[`renders disabled icon button 1`] = `
"color": "#000000",
"fontSize": 24,
},
Object {
"backgroundColor": "transparent",
},
Array [
Object {
"transform": Array [
Object {
"scaleX": 1,
},
],
},
Object {
"backgroundColor": "transparent",
},
],
Object {
"fontFamily": "Material Icons",
"fontStyle": "normal",
@@ -126,9 +135,18 @@ exports[`renders icon button by default 1`] = `
"color": "#000000",
"fontSize": 24,
},
Object {
"backgroundColor": "transparent",
},
Array [
Object {
"transform": Array [
Object {
"scaleX": 1,
},
],
},
Object {
"backgroundColor": "transparent",
},
],
Object {
"fontFamily": "Material Icons",
"fontStyle": "normal",
@@ -194,9 +212,18 @@ exports[`renders icon button with color 1`] = `
"color": "#e91e63",
"fontSize": 24,
},
Object {
"backgroundColor": "transparent",
},
Array [
Object {
"transform": Array [
Object {
"scaleX": 1,
},
],
},
Object {
"backgroundColor": "transparent",
},
],
Object {
"fontFamily": "Material Icons",
"fontStyle": "normal",
@@ -262,9 +289,18 @@ exports[`renders icon button with size 1`] = `
"color": "#000000",
"fontSize": 30,
},
Object {
"backgroundColor": "transparent",
},
Array [
Object {
"transform": Array [
Object {
"scaleX": 1,
},
],
},
Object {
"backgroundColor": "transparent",
},
],
Object {
"fontFamily": "Material Icons",
"fontStyle": "normal",

View File

@@ -56,9 +56,18 @@ exports[`renders list accordion with children 1`] = `
"color": "rgba(0, 0, 0, 0.54)",
"fontSize": 24,
},
Object {
"backgroundColor": "transparent",
},
Array [
Object {
"transform": Array [
Object {
"scaleX": 1,
},
],
},
Object {
"backgroundColor": "transparent",
},
],
Object {
"fontFamily": "Material Icons",
"fontStyle": "normal",
@@ -93,6 +102,8 @@ exports[`renders list accordion with children 1`] = `
Object {
"color": "#000000",
"fontFamily": "Helvetica Neue",
"textAlign": "left",
"writingDirection": "ltr",
},
Array [
Object {
@@ -153,9 +164,18 @@ exports[`renders list accordion with children 1`] = `
"color": "rgba(0, 0, 0, 0.87)",
"fontSize": 24,
},
Object {
"backgroundColor": "transparent",
},
Array [
Object {
"transform": Array [
Object {
"scaleX": 1,
},
],
},
Object {
"backgroundColor": "transparent",
},
],
Object {
"fontFamily": "Material Icons",
"fontStyle": "normal",
@@ -228,9 +248,18 @@ exports[`renders list accordion with icons 1`] = `
"color": "rgba(0, 0, 0, 0.54)",
"fontSize": 24,
},
Object {
"backgroundColor": "transparent",
},
Array [
Object {
"transform": Array [
Object {
"scaleX": 1,
},
],
},
Object {
"backgroundColor": "transparent",
},
],
Object {
"fontFamily": "Material Icons",
"fontStyle": "normal",
@@ -265,6 +294,8 @@ exports[`renders list accordion with icons 1`] = `
Object {
"color": "#000000",
"fontFamily": "Helvetica Neue",
"textAlign": "left",
"writingDirection": "ltr",
},
Array [
Object {
@@ -325,9 +356,18 @@ exports[`renders list accordion with icons 1`] = `
"color": "rgba(0, 0, 0, 0.87)",
"fontSize": 24,
},
Object {
"backgroundColor": "transparent",
},
Array [
Object {
"transform": Array [
Object {
"scaleX": 1,
},
],
},
Object {
"backgroundColor": "transparent",
},
],
Object {
"fontFamily": "Material Icons",
"fontStyle": "normal",
@@ -397,6 +437,8 @@ exports[`renders multiline list accordion 1`] = `
Object {
"color": "#000000",
"fontFamily": "Helvetica Neue",
"textAlign": "left",
"writingDirection": "ltr",
},
Array [
Object {
@@ -443,6 +485,8 @@ exports[`renders multiline list accordion 1`] = `
Object {
"color": "#000000",
"fontFamily": "Helvetica Neue",
"textAlign": "left",
"writingDirection": "ltr",
},
Array [
Object {
@@ -507,9 +551,18 @@ exports[`renders multiline list accordion 1`] = `
"color": "rgba(0, 0, 0, 0.87)",
"fontSize": 24,
},
Object {
"backgroundColor": "transparent",
},
Array [
Object {
"transform": Array [
Object {
"scaleX": 1,
},
],
},
Object {
"backgroundColor": "transparent",
},
],
Object {
"fontFamily": "Material Icons",
"fontStyle": "normal",

View File

@@ -72,6 +72,8 @@ exports[`renders list item with avatar 1`] = `
Object {
"color": "#000000",
"fontFamily": "Helvetica Neue",
"textAlign": "left",
"writingDirection": "ltr",
},
Array [
Object {
@@ -189,6 +191,8 @@ exports[`renders list item with avatar and icon 1`] = `
Object {
"color": "#000000",
"fontFamily": "Helvetica Neue",
"textAlign": "left",
"writingDirection": "ltr",
},
Array [
Object {
@@ -235,6 +239,8 @@ exports[`renders list item with avatar and icon 1`] = `
Object {
"color": "#000000",
"fontFamily": "Helvetica Neue",
"textAlign": "left",
"writingDirection": "ltr",
},
Array [
Object {
@@ -300,9 +306,18 @@ exports[`renders list item with avatar and icon 1`] = `
"color": "rgba(0, 0, 0, 0.54)",
"fontSize": 24,
},
Object {
"backgroundColor": "transparent",
},
Array [
Object {
"transform": Array [
Object {
"scaleX": 1,
},
],
},
Object {
"backgroundColor": "transparent",
},
],
Object {
"fontFamily": "Material Icons",
"fontStyle": "normal",
@@ -371,9 +386,18 @@ exports[`renders list item with icon 1`] = `
"color": "rgba(0, 0, 0, 0.54)",
"fontSize": 24,
},
Object {
"backgroundColor": "transparent",
},
Array [
Object {
"transform": Array [
Object {
"scaleX": 1,
},
],
},
Object {
"backgroundColor": "transparent",
},
],
Object {
"fontFamily": "Material Icons",
"fontStyle": "normal",
@@ -409,6 +433,8 @@ exports[`renders list item with icon 1`] = `
Object {
"color": "#000000",
"fontFamily": "Helvetica Neue",
"textAlign": "left",
"writingDirection": "ltr",
},
Array [
Object {
@@ -500,6 +526,8 @@ exports[`renders list item with title and description 1`] = `
Object {
"color": "#000000",
"fontFamily": "Helvetica Neue",
"textAlign": "left",
"writingDirection": "ltr",
},
Array [
Object {
@@ -546,6 +574,8 @@ exports[`renders list item with title and description 1`] = `
Object {
"color": "#000000",
"fontFamily": "Helvetica Neue",
"textAlign": "left",
"writingDirection": "ltr",
},
Array [
Object {

View File

@@ -21,6 +21,8 @@ exports[`renders list section with title 1`] = `
Object {
"color": "#000000",
"fontFamily": "Helvetica Neue",
"textAlign": "left",
"writingDirection": "ltr",
},
Array [
Object {
@@ -111,9 +113,18 @@ exports[`renders list section with title 1`] = `
"color": "rgba(0, 0, 0, 0.54)",
"fontSize": 24,
},
Object {
"backgroundColor": "transparent",
},
Array [
Object {
"transform": Array [
Object {
"scaleX": 1,
},
],
},
Object {
"backgroundColor": "transparent",
},
],
Object {
"fontFamily": "Material Icons",
"fontStyle": "normal",
@@ -149,6 +160,8 @@ exports[`renders list section with title 1`] = `
Object {
"color": "#000000",
"fontFamily": "Helvetica Neue",
"textAlign": "left",
"writingDirection": "ltr",
},
Array [
Object {
@@ -240,9 +253,18 @@ exports[`renders list section with title 1`] = `
"color": "rgba(0, 0, 0, 0.54)",
"fontSize": 24,
},
Object {
"backgroundColor": "transparent",
},
Array [
Object {
"transform": Array [
Object {
"scaleX": 1,
},
],
},
Object {
"backgroundColor": "transparent",
},
],
Object {
"fontFamily": "Material Icons",
"fontStyle": "normal",
@@ -278,6 +300,8 @@ exports[`renders list section with title 1`] = `
Object {
"color": "#000000",
"fontFamily": "Helvetica Neue",
"textAlign": "left",
"writingDirection": "ltr",
},
Array [
Object {
@@ -383,9 +407,18 @@ exports[`renders list section without title 1`] = `
"color": "rgba(0, 0, 0, 0.54)",
"fontSize": 24,
},
Object {
"backgroundColor": "transparent",
},
Array [
Object {
"transform": Array [
Object {
"scaleX": 1,
},
],
},
Object {
"backgroundColor": "transparent",
},
],
Object {
"fontFamily": "Material Icons",
"fontStyle": "normal",
@@ -421,6 +454,8 @@ exports[`renders list section without title 1`] = `
Object {
"color": "#000000",
"fontFamily": "Helvetica Neue",
"textAlign": "left",
"writingDirection": "ltr",
},
Array [
Object {
@@ -512,9 +547,18 @@ exports[`renders list section without title 1`] = `
"color": "rgba(0, 0, 0, 0.54)",
"fontSize": 24,
},
Object {
"backgroundColor": "transparent",
},
Array [
Object {
"transform": Array [
Object {
"scaleX": 1,
},
],
},
Object {
"backgroundColor": "transparent",
},
],
Object {
"fontFamily": "Material Icons",
"fontStyle": "normal",
@@ -550,6 +594,8 @@ exports[`renders list section without title 1`] = `
Object {
"color": "#000000",
"fontFamily": "Helvetica Neue",
"textAlign": "left",
"writingDirection": "ltr",
},
Array [
Object {

View File

@@ -54,6 +54,8 @@ exports[`renders not visible snackbar with content 1`] = `
Object {
"color": "#000000",
"fontFamily": "Helvetica Neue",
"textAlign": "left",
"writingDirection": "ltr",
},
Array [
Object {
@@ -153,6 +155,8 @@ exports[`renders snackbar with Text as a child 1`] = `
Object {
"color": "#000000",
"fontFamily": "Helvetica Neue",
"textAlign": "left",
"writingDirection": "ltr",
},
Array [
Object {
@@ -258,6 +262,8 @@ exports[`renders snackbar with action button 1`] = `
Object {
"color": "#000000",
"fontFamily": "Helvetica Neue",
"textAlign": "left",
"writingDirection": "ltr",
},
Array [
Object {
@@ -358,6 +364,8 @@ exports[`renders snackbar with action button 1`] = `
Object {
"color": "#000000",
"fontFamily": "Helvetica Neue",
"textAlign": "left",
"writingDirection": "ltr",
},
Array [
Object {
@@ -466,6 +474,8 @@ exports[`renders snackbar with content 1`] = `
Object {
"color": "#000000",
"fontFamily": "Helvetica Neue",
"textAlign": "left",
"writingDirection": "ltr",
},
Array [
Object {