mirror of
https://github.com/status-im/react-native.git
synced 2025-01-10 01:25:39 +00:00
fa6022dc1a
Summary: Create isDeviceLanguageRTL function to connect the OS language with isRTL. Now even if a new app could support RTL language, without setting forceRTL at JS side it won't directly change into RTL layout. Reviewed By: fkgozali Differential Revision: D3473109 fbshipit-source-id: ac1410c910e980d44750bb88cad7615febb9e076
53 lines
1.3 KiB
Objective-C
53 lines
1.3 KiB
Objective-C
/**
|
|
* Copyright (c) 2015-present, Facebook, Inc.
|
|
* All rights reserved.
|
|
*
|
|
* This source code is licensed under the BSD-style license found in the
|
|
* LICENSE file in the root directory of this source tree. An additional grant
|
|
* of patent rights can be found in the PATENTS file in the same directory.
|
|
*/
|
|
|
|
#import <Foundation/Foundation.h>
|
|
|
|
#import "RCTI18nUtil.h"
|
|
|
|
@implementation RCTI18nUtil
|
|
|
|
+ (id)sharedInstance {
|
|
static RCTI18nUtil *sharedRCTI18nUtilInstance = nil;
|
|
@synchronized(self) {
|
|
if (sharedRCTI18nUtilInstance == nil)
|
|
sharedRCTI18nUtilInstance = [self new];
|
|
}
|
|
return sharedRCTI18nUtilInstance;
|
|
}
|
|
|
|
- (BOOL)isRTL
|
|
{
|
|
if ([self forceRTL] && [self isDevicePreferredLanguageRTL]) {
|
|
return YES;
|
|
}
|
|
return NO;
|
|
}
|
|
|
|
- (BOOL)forceRTL
|
|
{
|
|
BOOL rtlStatus = [[NSUserDefaults standardUserDefaults]
|
|
boolForKey:@"RCTI18nUtil_forceRTL"];
|
|
return rtlStatus;
|
|
}
|
|
|
|
- (void)setForceRTL:(BOOL)rtlStatus
|
|
{
|
|
[[NSUserDefaults standardUserDefaults] setBool:rtlStatus forKey:@"RCTI18nUtil_forceRTL"];
|
|
[[NSUserDefaults standardUserDefaults] synchronize];
|
|
}
|
|
|
|
- (BOOL)isDevicePreferredLanguageRTL
|
|
{
|
|
NSLocaleLanguageDirection direction = [NSLocale characterDirectionForLanguage:[[NSLocale preferredLanguages] objectAtIndex:0]];
|
|
return direction == NSLocaleLanguageDirectionRightToLeft;
|
|
}
|
|
|
|
@end
|