mirror of
https://github.com/status-im/react-native.git
synced 2025-01-14 19:44:13 +00:00
Provide forceRTL for LTR language to test
Summary: 1. Provide forceRTL function for developer to test RTL layout in LTR language bundle in I18nUtil and expose it in I18nManager. 2. Rename `allowRTL` and `setAllowRTL` functions Reviewed By: fkgozali Differential Revision: D3663693 fbshipit-source-id: 3db13a44c069ae73d1728c211306422db5dd8122
This commit is contained in:
parent
0dd93b62b4
commit
f0fb228ec7
@ -14,11 +14,13 @@
|
|||||||
type I18nManagerStatus = {
|
type I18nManagerStatus = {
|
||||||
isRTL: boolean,
|
isRTL: boolean,
|
||||||
allowRTL: (allowRTL: boolean) => {},
|
allowRTL: (allowRTL: boolean) => {},
|
||||||
|
forceRTL: (forceRTL: boolean) => {},
|
||||||
};
|
};
|
||||||
|
|
||||||
const I18nManager : I18nManagerStatus = require('NativeModules').I18nManager || {
|
const I18nManager : I18nManagerStatus = require('NativeModules').I18nManager || {
|
||||||
isRTL: false,
|
isRTL: false,
|
||||||
allowRTL: () => {},
|
allowRTL: () => {},
|
||||||
|
forceRTL: () => {},
|
||||||
};
|
};
|
||||||
|
|
||||||
module.exports = I18nManager;
|
module.exports = I18nManager;
|
||||||
|
@ -16,7 +16,12 @@ RCT_EXPORT_MODULE()
|
|||||||
|
|
||||||
RCT_EXPORT_METHOD(allowRTL:(BOOL)value)
|
RCT_EXPORT_METHOD(allowRTL:(BOOL)value)
|
||||||
{
|
{
|
||||||
[[RCTI18nUtil sharedInstance] setAllowRTL:value];
|
[[RCTI18nUtil sharedInstance] allowRTL:value];
|
||||||
|
}
|
||||||
|
|
||||||
|
RCT_EXPORT_METHOD(forceRTL:(BOOL)value)
|
||||||
|
{
|
||||||
|
[[RCTI18nUtil sharedInstance] forceRTL:value];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (NSDictionary *)constantsToExport
|
- (NSDictionary *)constantsToExport
|
||||||
|
@ -18,8 +18,10 @@
|
|||||||
@interface RCTI18nUtil : NSObject
|
@interface RCTI18nUtil : NSObject
|
||||||
|
|
||||||
- (BOOL)isRTL;
|
- (BOOL)isRTL;
|
||||||
- (BOOL)allowRTL;
|
- (BOOL)isRTLAllowed;
|
||||||
- (void)setAllowRTL:(BOOL)value;
|
- (void)allowRTL:(BOOL)value;
|
||||||
|
- (BOOL)isRTLForced;
|
||||||
|
- (void)forceRTL:(BOOL)value;
|
||||||
+ (id)sharedInstance;
|
+ (id)sharedInstance;
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
@ -22,29 +22,57 @@
|
|||||||
return sharedRCTI18nUtilInstance;
|
return sharedRCTI18nUtilInstance;
|
||||||
}
|
}
|
||||||
|
|
||||||
// If current using language is RTL language and meanwhile set allowRTL on the JS side,
|
/**
|
||||||
// the RN app will automatically have a RTL layout.
|
* Check if the app is currently running on an RTL locale.
|
||||||
|
* This only happens when the app:
|
||||||
|
* - is forcing RTL layout, regardless of the active language (for development purpose)
|
||||||
|
* - allows RTL layout when using RTL locale
|
||||||
|
*/
|
||||||
- (BOOL)isRTL
|
- (BOOL)isRTL
|
||||||
{
|
{
|
||||||
if ([self allowRTL] && [self isApplicationPreferredLanguageRTL]) {
|
if ([self isRTLForced]) {
|
||||||
|
return YES;
|
||||||
|
}
|
||||||
|
if ([self isRTLAllowed] && [self isApplicationPreferredLanguageRTL]) {
|
||||||
return YES;
|
return YES;
|
||||||
}
|
}
|
||||||
return NO;
|
return NO;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (BOOL)allowRTL
|
/**
|
||||||
|
* Should be used very early during app start up
|
||||||
|
* Before the bridge is initialized
|
||||||
|
*/
|
||||||
|
- (BOOL)isRTLAllowed
|
||||||
{
|
{
|
||||||
BOOL rtlStatus = [[NSUserDefaults standardUserDefaults]
|
BOOL rtlStatus = [[NSUserDefaults standardUserDefaults]
|
||||||
boolForKey:@"RCTI18nUtil_allowRTL"];
|
boolForKey:@"RCTI18nUtil_allowRTL"];
|
||||||
return rtlStatus;
|
return rtlStatus;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)setAllowRTL:(BOOL)rtlStatus
|
- (void)allowRTL:(BOOL)rtlStatus
|
||||||
{
|
{
|
||||||
[[NSUserDefaults standardUserDefaults] setBool:rtlStatus forKey:@"RCTI18nUtil_allowRTL"];
|
[[NSUserDefaults standardUserDefaults] setBool:rtlStatus forKey:@"RCTI18nUtil_allowRTL"];
|
||||||
[[NSUserDefaults standardUserDefaults] synchronize];
|
[[NSUserDefaults standardUserDefaults] synchronize];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Could be used to test RTL layout with English
|
||||||
|
* Used for development and testing purpose
|
||||||
|
*/
|
||||||
|
- (BOOL)isRTLForced
|
||||||
|
{
|
||||||
|
BOOL rtlStatus = [[NSUserDefaults standardUserDefaults]
|
||||||
|
boolForKey:@"RCTI18nUtil_forceRTL"];
|
||||||
|
return rtlStatus;
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void)forceRTL:(BOOL)rtlStatus
|
||||||
|
{
|
||||||
|
[[NSUserDefaults standardUserDefaults] setBool:rtlStatus forKey:@"RCTI18nUtil_forceRTL"];
|
||||||
|
[[NSUserDefaults standardUserDefaults] synchronize];
|
||||||
|
}
|
||||||
|
|
||||||
// Check if the current device language is RTL
|
// Check if the current device language is RTL
|
||||||
- (BOOL)isDevicePreferredLanguageRTL
|
- (BOOL)isDevicePreferredLanguageRTL
|
||||||
{
|
{
|
||||||
|
Loading…
x
Reference in New Issue
Block a user