Skip to content

Commit

Permalink
[NEW] Support RTL (#2656)
Browse files Browse the repository at this point in the history
* wip: RTL (iOS)

* wip: RTL (Android)

* wip: reload bundle when change between RTL languages

* fix: Stack Animation on Android

* fix: update snapshot

* fix: Swipe Room Actions in RTL mode

* fix: snapshots

* Move isRTL to i18n

* Fix styling

* Update tests

* Update pods

Co-authored-by: Diego Mello <diegolmello@gmail.com>
  • Loading branch information
djorkaeffalexandre and diegolmello authored Nov 30, 2020
1 parent 40490ea commit 10ba9d5
Show file tree
Hide file tree
Showing 60 changed files with 20,708 additions and 18,485 deletions.
2,618 changes: 2,142 additions & 476 deletions __tests__/__snapshots__/Storyshots.test.js.snap

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions android/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
android:icon="@mipmap/ic_launcher"
android:theme="@style/AppTheme"
android:networkSecurityConfig="@xml/network_security_config"
android:supportsRtl="true"
android:requestLegacyExternalStorage="true"
android:allowBackup="false"
tools:replace="android:allowBackup"
Expand Down
4 changes: 2 additions & 2 deletions app/containers/ActionSheet/styles.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ export default StyleSheet.create({
},
text: {
fontSize: 16,
textAlign: 'center',
...sharedStyles.textMedium
...sharedStyles.textMedium,
...sharedStyles.textAlignCenter
}
});
4 changes: 2 additions & 2 deletions app/containers/Button/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ const styles = StyleSheet.create({
},
text: {
fontSize: 16,
textAlign: 'center',
...sharedStyles.textMedium
...sharedStyles.textMedium,
...sharedStyles.textAlignCenter
},
disabled: {
opacity: 0.3
Expand Down
4 changes: 3 additions & 1 deletion app/containers/EmojiPicker/styles.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { StyleSheet } from 'react-native';

import sharedStyles from '../../views/Styles';

export default StyleSheet.create({
container: {
flex: 1
Expand Down Expand Up @@ -46,8 +48,8 @@ export default StyleSheet.create({
flex: 1
},
categoryEmoji: {
...sharedStyles.textAlignCenter,
backgroundColor: 'transparent',
textAlign: 'center',
color: '#ffffff'
},
customCategoryEmoji: {
Expand Down
12 changes: 9 additions & 3 deletions app/containers/List/ListIcon.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,13 @@ const styles = StyleSheet.create({
}
});

const ListIcon = React.memo(({ theme, name, color }) => (
<View style={styles.icon}>
const ListIcon = React.memo(({
theme,
name,
color,
style
}) => (
<View style={[styles.icon, style]}>
<CustomIcon
name={name}
color={color ?? themes[theme].auxiliaryText}
Expand All @@ -26,7 +31,8 @@ const ListIcon = React.memo(({ theme, name, color }) => (
ListIcon.propTypes = {
theme: PropTypes.string,
name: PropTypes.string,
color: PropTypes.string
color: PropTypes.string,
style: PropTypes.object
};

ListIcon.displayName = 'List.Icon';
Expand Down
14 changes: 12 additions & 2 deletions app/containers/List/ListItem.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
import React from 'react';
import { View, Text, StyleSheet } from 'react-native';
import {
View,
Text,
StyleSheet,
I18nManager
} from 'react-native';
import PropTypes from 'prop-types';

import Touch from '../../utils/touch';
Expand Down Expand Up @@ -39,6 +44,11 @@ const styles = StyleSheet.create({
subtitle: {
fontSize: 14,
...sharedStyles.textRegular
},
actionIndicator: {
...I18nManager.isRTL
? { transform: [{ rotate: '180deg' }] }
: {}
}
});

Expand All @@ -64,7 +74,7 @@ const Content = React.memo(({
? (
<View style={styles.rightContainer}>
{right ? right() : null}
{showActionIndicator ? <Icon name='chevron-right' /> : null}
{showActionIndicator ? <Icon name='chevron-right' style={styles.actionIndicator} /> : null}
</View>
)
: null}
Expand Down
3 changes: 2 additions & 1 deletion app/containers/MessageActions/Header.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import CustomEmoji from '../EmojiPicker/CustomEmoji';
import database from '../../lib/database';
import { Button } from '../ActionSheet';
import { useDimensions } from '../../dimensions';
import sharedStyles from '../../views/Styles';

export const HEADER_HEIGHT = 36;
const ITEM_SIZE = 36;
Expand All @@ -32,7 +33,7 @@ const styles = StyleSheet.create({
alignItems: 'center'
},
headerIcon: {
textAlign: 'center',
...sharedStyles.textAlignCenter,
fontSize: 20,
color: '#fff'
},
Expand Down
6 changes: 3 additions & 3 deletions app/containers/MessageBox/styles.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,13 @@ export default StyleSheet.create({
width: 46,
height: 36,
fontSize: isIOS ? 30 : 25,
textAlign: 'center'
...sharedStyles.textAlignCenter
},
fixedMentionAvatar: {
textAlign: 'center',
width: 46,
fontSize: 14,
...sharedStyles.textBold
...sharedStyles.textBold,
...sharedStyles.textAlignCenter
},
mentionText: {
fontSize: 14,
Expand Down
4 changes: 2 additions & 2 deletions app/containers/ReactionsModal.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ const styles = StyleSheet.create({
paddingVertical: 10
},
title: {
textAlign: 'center',
fontSize: 16,
...sharedStyles.textSemibold
...sharedStyles.textSemibold,
...sharedStyles.textAlignCenter
},
reactCount: {
fontSize: 13,
Expand Down
5 changes: 2 additions & 3 deletions app/containers/TextInput.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import ActivityIndicator from './ActivityIndicator';

const styles = StyleSheet.create({
error: {
textAlign: 'center',
...sharedStyles.textAlignCenter,
paddingTop: 5
},
inputContainer: {
Expand All @@ -26,8 +26,7 @@ const styles = StyleSheet.create({
...sharedStyles.textRegular,
height: 48,
fontSize: 16,
paddingLeft: 14,
paddingRight: 14,
paddingHorizontal: 14,
borderWidth: StyleSheet.hairlineWidth,
borderRadius: 2
},
Expand Down
4 changes: 2 additions & 2 deletions app/containers/Toast.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ const styles = StyleSheet.create({
padding: 10
},
text: {
...sharedStyles.textRegular,
fontSize: 14,
textAlign: 'center'
...sharedStyles.textRegular,
...sharedStyles.textAlignCenter
}
});

Expand Down
2 changes: 1 addition & 1 deletion app/containers/markdown/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ class Markdown extends PureComponent {
return null;
}
return (
<Text style={[style, { color: themes[theme].bodyText }]} numberOfLines={numberOfLines}>
<Text style={[styles.text, style, { color: themes[theme].bodyText }]} numberOfLines={numberOfLines}>
{children}
</Text>
);
Expand Down
2 changes: 1 addition & 1 deletion app/containers/message/styles.js
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ export default StyleSheet.create({
},
time: {
fontSize: 12,
paddingLeft: 8,
marginLeft: 8,
...sharedStyles.textRegular
},
repliedThread: {
Expand Down
4 changes: 4 additions & 0 deletions app/i18n/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import i18n from 'i18n-js';
import { I18nManager } from 'react-native';
import * as RNLocalize from 'react-native-localize';

export * from './isRTL';

export const LANGUAGES = [
{
label: 'English',
Expand Down Expand Up @@ -67,6 +69,8 @@ const availableLanguages = Object.keys(i18n.translations);
const { languageTag, isRTL } = RNLocalize.findBestAvailableLanguage(availableLanguages) || defaultLanguage;

I18nManager.forceRTL(isRTL);
I18nManager.swapLeftAndRightInRTL(isRTL);
i18n.locale = languageTag;
i18n.isRTL = I18nManager.isRTL;

export default i18n;
16 changes: 16 additions & 0 deletions app/i18n/isRTL.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// https://github.com/zoontek/react-native-localize/blob/master/src/constants.ts#L5
const USES_RTL_LAYOUT = [
'ar',
'ckb',
'fa',
'he',
'ks',
'lrc',
'mzn',
'ps',
'ug',
'ur',
'yi'
];

export const isRTL = locale => USES_RTL_LAYOUT.includes(locale);
52 changes: 25 additions & 27 deletions app/presentation/RoomItem/Actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,18 @@ import styles, { ACTION_WIDTH, LONG_SWIPE } from './styles';
import { CustomIcon } from '../../lib/Icons';
import { themes } from '../../constants/colors';

const reverse = new Animated.Value(I18n.isRTL ? -1 : 1);

export const LeftActions = React.memo(({
theme, transX, isRead, width, onToggleReadPress
}) => {
const translateX = transX.interpolate({
inputRange: [0, ACTION_WIDTH],
outputRange: [-ACTION_WIDTH, 0]
});
const translateXIcon = transX.interpolate({
inputRange: [0, ACTION_WIDTH, LONG_SWIPE - 2, LONG_SWIPE],
outputRange: [0, 0, -LONG_SWIPE + ACTION_WIDTH + 2, 0],
extrapolate: 'clamp'
});
const translateX = Animated.multiply(
transX.interpolate({
inputRange: [0, ACTION_WIDTH],
outputRange: [-ACTION_WIDTH, 0]
}),
reverse
);
return (
<View
style={[styles.actionsContainer, styles.actionLeftContainer]}
Expand All @@ -36,22 +36,14 @@ export const LeftActions = React.memo(({
}
]}
>
<Animated.View
style={[
styles.actionLeftButtonContainer,
{
right: 0,
transform: [{ translateX: translateXIcon }]
}
]}
>
<View style={styles.actionLeftButtonContainer}>
<RectButton style={styles.actionButton} onPress={onToggleReadPress}>
<>
<CustomIcon size={20} name={isRead ? 'flag' : 'check'} color='white' />
<Text style={[styles.actionText, { color: themes[theme].buttonText }]}>{I18n.t(isRead ? 'Unread' : 'Read')}</Text>
</>
</RectButton>
</Animated.View>
</View>
</Animated.View>
</View>
);
Expand All @@ -60,14 +52,20 @@ export const LeftActions = React.memo(({
export const RightActions = React.memo(({
transX, favorite, width, toggleFav, onHidePress, theme
}) => {
const translateXFav = transX.interpolate({
inputRange: [-width / 2, -ACTION_WIDTH * 2, 0],
outputRange: [width / 2, width - ACTION_WIDTH * 2, width]
});
const translateXHide = transX.interpolate({
inputRange: [-width, -LONG_SWIPE, -ACTION_WIDTH * 2, 0],
outputRange: [0, width - LONG_SWIPE, width - ACTION_WIDTH, width]
});
const translateXFav = Animated.multiply(
transX.interpolate({
inputRange: [-width / 2, -ACTION_WIDTH * 2, 0],
outputRange: [width / 2, width - ACTION_WIDTH * 2, width]
}),
reverse
);
const translateXHide = Animated.multiply(
transX.interpolate({
inputRange: [-width, -LONG_SWIPE, -ACTION_WIDTH * 2, 0],
outputRange: [0, width - LONG_SWIPE, width - ACTION_WIDTH, width]
}),
reverse
);
return (
<View
style={{
Expand Down
Loading

0 comments on commit 10ba9d5

Please sign in to comment.