added support for RTL and LTR switch

This commit is contained in:
Sadaqat Ali 2021-12-30 18:21:58 +05:00
parent f6e6c9b076
commit 912cae60ad
5 changed files with 36 additions and 14 deletions

View File

@ -325,8 +325,8 @@ PODS:
- React-Core
- react-native-receive-sharing-intent (1.0.4):
- React
- react-native-restart (0.0.17):
- React
- react-native-restart (0.0.23):
- React-Core
- react-native-safe-area-context (3.1.9):
- React-Core
- react-native-splash-screen (3.2.0):
@ -731,7 +731,7 @@ SPEC CHECKSUMS:
react-native-netinfo: 30fb89fa913c342be82a887b56e96be6d71201dd
react-native-randombytes: 421f1c7d48c0af8dbcd471b0324393ebf8fe7846
react-native-receive-sharing-intent: feba0a332a07977549a85aa58b496eb44368366a
react-native-restart: d19a0f8d053d065fe64cd2baebb6487111c77149
react-native-restart: aaad36f3ed7031daac3565f4a79d67e4f3884a50
react-native-safe-area-context: b6e0e284002381d2ff29fa4fff42b4d8282e3c94
react-native-splash-screen: 200d11d188e2e78cea3ad319964f6142b6384865
react-native-udp: ff9d13e523f2b58e6bc5d4d32321ac60671b5dc9

View File

@ -112,7 +112,7 @@
"react-native-reanimated": "^1",
"react-native-receive-sharing-intent": "ecency/react-native-receive-sharing-intent",
"react-native-render-html": "^6.0.5",
"react-native-restart": "0.0.17",
"react-native-restart": "^0.0.23",
"react-native-safe-area-context": "^3.1.9",
"react-native-screens": "^2.9.0",
"react-native-scrollable-tab-view": "ecency/react-native-scrollable-tab-view",
@ -141,6 +141,7 @@
"redux-thunk": "^2.3.0",
"rn-fetch-blob": "^0.12.0",
"rn-placeholder": "^1.3.2",
"rtl-detect": "^1.0.4",
"speakingurl": "^14.0.1",
"stacktrace-parser": "0.1.4",
"stream-browserify": "^1.0.0",

View File

@ -6,7 +6,7 @@ import VersionNumber from 'react-native-version-number';
import Config from 'react-native-config';
import { injectIntl } from 'react-intl';
import messaging from '@react-native-firebase/messaging';
import { languageRestart } from '../../../utils/I18nUtils';
// Realm
import {
getExistUser,
@ -91,17 +91,17 @@ class SettingsContainer extends Component {
}
// Component Functions
_handleDropdownSelected = (action, actionType) => {
const { dispatch } = this.props;
_handleDropdownSelected = async (action, actionType) => {
const { dispatch, selectedLanguage } = this.props;
switch (actionType) {
case 'currency':
this._currencyChange(action);
break;
case 'language':
dispatch(setLanguage(LANGUAGE_VALUE[action]));
setLanguage2DB(LANGUAGE_VALUE[action]);
await dispatch(setLanguage(LANGUAGE_VALUE[action]));
await setLanguage2DB(LANGUAGE_VALUE[action]);
await languageRestart(selectedLanguage, LANGUAGE_VALUE[action]); //restart the app and flip change layout according to lang direction
break;
case 'api':

16
src/utils/I18nUtils.js Normal file
View File

@ -0,0 +1,16 @@
import { NativeModules } from 'react-native';
import RNRestart from 'react-native-restart';
import rtlDetect from 'rtl-detect';
export const languageRestart = async (prevLang, lang) => {
if (prevLang != lang) {
// if selected lang is RTL, switch the layout
if (rtlDetect.isRtlLang(lang)) {
await NativeModules.I18nManager.forceRTL(true);
} else {
await NativeModules.I18nManager.forceRTL(false);
}
// restart the app to take changes in UI
RNRestart.Restart();
}
};

View File

@ -8937,10 +8937,10 @@ react-native-render-html@^6.0.5:
stringify-entities "^3.1.0"
urijs "^1.19.6"
react-native-restart@0.0.17:
version "0.0.17"
resolved "https://registry.yarnpkg.com/react-native-restart/-/react-native-restart-0.0.17.tgz#c1f38e019d1a2114248d496698e7951e9435ba91"
integrity sha512-UwFPDssMFoyDbF2aLARIHWt5g/o0TtxCXK9WIY+0iNpkgG9qWd+n80XBwXioNCdgy39ZQ5yfJBJRwtMLDgABag==
react-native-restart@^0.0.23:
version "0.0.23"
resolved "https://registry.yarnpkg.com/react-native-restart/-/react-native-restart-0.0.23.tgz#9b53062ebc692f469d0662c06879cb4d34c62520"
integrity sha512-BTs3YNl0MFyTgYgq6oQOspVV7+8Umm2QeuHWJ8xfRsjdHIUBoKF/Bxe1IMGAO5vHPcNwN+lHE6Mf58Tu4HS9/w==
react-native-safe-area-context@^3.1.9:
version "3.1.9"
@ -9636,6 +9636,11 @@ rsvp@^4.8.4:
resolved "https://registry.yarnpkg.com/rsvp/-/rsvp-4.8.5.tgz#c8f155311d167f68f21e168df71ec5b083113734"
integrity sha512-nfMOlASu9OnRJo1mbEk2cz0D56a1MBNrJ7orjRZQG10XDyuvwksKbuXNp6qa+kbn839HwjwhBzhFmdsaEAfauA==
rtl-detect@^1.0.4:
version "1.0.4"
resolved "https://registry.yarnpkg.com/rtl-detect/-/rtl-detect-1.0.4.tgz#40ae0ea7302a150b96bc75af7d749607392ecac6"
integrity sha512-EBR4I2VDSSYr7PkBmFy04uhycIpDKp+21p/jARYXlCSjQksTBQcJ0HFUPOO79EPPH5JS6VAhiIQbycf0O3JAxQ==
run-async@^2.2.0:
version "2.4.1"
resolved "https://registry.yarnpkg.com/run-async/-/run-async-2.4.1.tgz#8440eccf99ea3e70bd409d49aab88e10c189a455"