mirror of
https://github.com/status-im/react-native.git
synced 2025-01-27 01:40:08 +00:00
Create a module for React Native to get IsRTL info and set ForceRTL 1/2
Summary: Create a module for React Native to get IsRTL information and set ForceRTL function. Reviewed By: fkgozali Differential Revision: D3446871 fbshipit-source-id: 736edf138a89d222818071370ac49dc54bda63b7
This commit is contained in:
parent
a59afb98d5
commit
88c6e7a22b
25
React/Modules/RCTI18nUtil.h
Normal file
25
React/Modules/RCTI18nUtil.h
Normal file
@ -0,0 +1,25 @@
|
||||
/**
|
||||
* 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>
|
||||
|
||||
/**
|
||||
* @experimental
|
||||
* This is a experimental module for to expose constance IsRTL to js about the RTL status.
|
||||
* And it allows js to force RLT status for development propose.
|
||||
* This will also provide other i18n related utilities in the future.
|
||||
*/
|
||||
@interface RCTI18nUtil : NSObject
|
||||
|
||||
- (BOOL)isRTL;
|
||||
- (BOOL)forceRTL;
|
||||
- (void)setForceRTL:(BOOL)value;
|
||||
+ (id)sharedInstance;
|
||||
|
||||
@end
|
44
React/Modules/RCTI18nUtil.m
Normal file
44
React/Modules/RCTI18nUtil.m
Normal file
@ -0,0 +1,44 @@
|
||||
/**
|
||||
* 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]) 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];
|
||||
}
|
||||
|
||||
@end
|
Loading…
x
Reference in New Issue
Block a user