diff --git a/React/Modules/RCTI18nUtil.h b/React/Modules/RCTI18nUtil.h new file mode 100644 index 000000000..ae4327938 --- /dev/null +++ b/React/Modules/RCTI18nUtil.h @@ -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 + +/** + * @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 diff --git a/React/Modules/RCTI18nUtil.m b/React/Modules/RCTI18nUtil.m new file mode 100644 index 000000000..ef1bbc1df --- /dev/null +++ b/React/Modules/RCTI18nUtil.m @@ -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 + +#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