Skip to content

Commit

Permalink
[change] Refactor localization APIs
Browse files Browse the repository at this point in the history
* Control writing direction using 'dir' and 'lang' props.
* Change the compiler output for RTL styles polyfill.
* Export 'useLocaleContext' for working with writing direction context.
* Turn I18nManager into a mock API
  • Loading branch information
necolas committed Mar 22, 2022
1 parent 45cf51f commit ab98561
Show file tree
Hide file tree
Showing 29 changed files with 1,079 additions and 756 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
"normalize-css-color": "^1.0.2",
"postcss-value-parser": "^4.2.0",
"prop-types": "^15.6.0",
"styleq": "0.0.0-b4fc5da"
"styleq": "0.0.0-afc6b2c59"
},
"peerDependencies": {
"react": ">=17.0.2",
Expand Down
93 changes: 0 additions & 93 deletions src/exports/I18nManager/__tests__/index-test.js

This file was deleted.

40 changes: 6 additions & 34 deletions src/exports/I18nManager/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,53 +8,25 @@
* @flow
*/

import ExecutionEnvironment from 'fbjs/lib/ExecutionEnvironment';

type I18nManagerStatus = {
allowRTL: (allowRTL: boolean) => void,
forceRTL: (forceRTL: boolean) => void,
getConstants: () => Constants,
setPreferredLanguageRTL: (setRTL: boolean) => void
getConstants: () => Constants
};

type Constants = {
isRTL: boolean
};

let isPreferredLanguageRTL = false;
let isRTLAllowed = true;
let isRTLForced = false;

const isRTL = () => {
if (isRTLForced) {
return true;
}
return isRTLAllowed && isPreferredLanguageRTL;
};

const onDirectionChange = () => {
if (ExecutionEnvironment.canUseDOM) {
if (document.documentElement && document.documentElement.setAttribute) {
document.documentElement.setAttribute('dir', isRTL() ? 'rtl' : 'ltr');
}
}
};

const I18nManager: I18nManagerStatus = {
allowRTL(bool) {
isRTLAllowed = bool;
onDirectionChange();
allowRTL() {
return;
},
forceRTL(bool) {
isRTLForced = bool;
onDirectionChange();
forceRTL() {
return;
},
getConstants(): Constants {
return { isRTL: isRTL() };
},
setPreferredLanguageRTL(bool) {
isPreferredLanguageRTL = bool;
onDirectionChange();
return { isRTL: false };
}
};

Expand Down
2 changes: 1 addition & 1 deletion src/exports/Image/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import type { ImageProps } from './types';
import * as React from 'react';
import createElement from '../createElement';
import { getAssetByID } from '../../modules/AssetRegistry';
import { createBoxShadowValue } from '../StyleSheet/compiler/preprocess';
import { createBoxShadowValue } from '../StyleSheet/preprocess';
import ImageLoader from '../../modules/ImageLoader';
import PixelRatio from '../PixelRatio';
import StyleSheet from '../StyleSheet';
Expand Down
2 changes: 1 addition & 1 deletion src/exports/Picker/PickerItem.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,5 @@ type Props = {
export default function PickerItem(props: Props) {
const { color, label, testID, value } = props;
const style = { color };
return createElement('option', { style, testID, value }, label);
return createElement('option', { children: label, style, testID, value });
}
Loading

0 comments on commit ab98561

Please sign in to comment.