From 0e07c36794b516ccce60909be0aa48bb0d527baa Mon Sep 17 00:00:00 2001 From: Mengjue Wang Date: Fri, 24 Jun 2016 19:32:54 -0700 Subject: [PATCH] Provide function that could read app current using language Summary: Provide function that could read the language currently used in the app, so the isRTL is using the app current using language to set isRTL. Reviewed By: fkgozali Differential Revision: D3480654 fbshipit-source-id: dea3ef4769296f594f7f32da2961b4fec1b99a7a --- React/Modules/RCTI18nUtil.m | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/React/Modules/RCTI18nUtil.m b/React/Modules/RCTI18nUtil.m index c66924243db..95c8ed735d2 100644 --- a/React/Modules/RCTI18nUtil.m +++ b/React/Modules/RCTI18nUtil.m @@ -22,9 +22,11 @@ return sharedRCTI18nUtilInstance; } +// If currnent using language is RTL language and meanwhile set forceRTL on the JS side, +// the RN app will automatically have a RTL layout. - (BOOL)isRTL { - if ([self forceRTL] && [self isDevicePreferredLanguageRTL]) { + if ([self forceRTL] && [self isApplicationPreferredLanguageRTL]) { return YES; } return NO; @@ -43,10 +45,19 @@ [[NSUserDefaults standardUserDefaults] synchronize]; } +// Check if the current device language is RTL - (BOOL)isDevicePreferredLanguageRTL { NSLocaleLanguageDirection direction = [NSLocale characterDirectionForLanguage:[[NSLocale preferredLanguages] objectAtIndex:0]]; return direction == NSLocaleLanguageDirectionRightToLeft; } +// Check if the current application language is RTL +- (BOOL)isApplicationPreferredLanguageRTL +{ + NSString *preferredAppLanguage = [[[NSBundle mainBundle] preferredLocalizations] objectAtIndex:0]; + NSLocaleLanguageDirection direction = [NSLocale characterDirectionForLanguage:preferredAppLanguage]; + return direction == NSLocaleLanguageDirectionRightToLeft; +} + @end