1 // Copyright 2015-present 650 Industries. All rights reserved. 2 3 import Foundation 4 5 @objc 6 public class EXTextDirectionController: NSObject { 7 class func isRTLPreferredForCurrentLocale() -> Bool { 8 return NSLocale.characterDirection(forLanguage: NSLocale.preferredLanguages.first ?? "en-US") == NSLocale.LanguageDirection.rightToLeft 9 } 10 11 @objc 12 public class func setSupportsRTL(_ supportsRTL: Bool) { 13 // These keys are used by React Native here: https://github.com/facebook/react-native/blob/main/React/Modules/RCTI18nUtil.m 14 // We set them before React loads to ensure it gets rendered correctly the first time the app is opened. 15 // On iOS we need to set both forceRTL and allowRTL so apps don't have to include localization strings. 16 UserDefaults.standard.set(supportsRTL, forKey: "RCTI18nUtil_allowRTL") 17 UserDefaults.standard.set(supportsRTL ? isRTLPreferredForCurrentLocale() : false, forKey: "RCTI18nUtil_forceRTL") 18 UserDefaults.standard.synchronize() 19 } 20 } 21