1 package host.exp.exponent.utils 2 3 import android.content.Context 4 import expo.modules.manifests.core.Manifest 5 6 // must be kept in sync with https://github.com/facebook/react-native/blob/main/ReactAndroid/src/main/java/com/facebook/react/modules/i18nmanager/I18nUtil.java 7 private const val SHARED_PREFS_NAME = "com.facebook.react.modules.i18nmanager.I18nUtil" 8 private const val KEY_FOR_PREFS_ALLOWRTL = "RCTI18nUtil_allowRTL" 9 10 class ExperienceRTLManager { 11 companion object { setSupportsRTLnull12 fun setSupportsRTL(context: Context, allowRTL: Boolean) { 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 context 16 .getSharedPreferences(SHARED_PREFS_NAME, Context.MODE_PRIVATE) 17 .edit() 18 .also { 19 it.putBoolean(KEY_FOR_PREFS_ALLOWRTL, allowRTL) 20 it.apply() 21 } 22 } 23 setSupportsRTLFromManifestnull24 fun setSupportsRTLFromManifest(context: Context, manifest: Manifest) { 25 setSupportsRTL( 26 context, 27 (manifest.getExpoClientConfigRootObject()?.optJSONObject("extra")?.optBoolean("supportsRTL") ?: false) 28 ) 29 } 30 } 31 } 32