mirror of
https://github.com/status-im/react-native.git
synced 2025-02-05 06:04:15 +00:00
Connect the OS setting with isRTL
Summary: Provide two function in I18nUtil to get the device and app current using language. And Set isRTL with both allowRTL and current app using language. Reviewed By: fkgozali Differential Revision: D3603412 fbshipit-source-id: 6bb280d56af9a12901148df9fab368366073680f
This commit is contained in:
parent
54a4450309
commit
8c0a045c0d
@ -4,6 +4,7 @@ android_library(
|
||||
name = 'i18nmanager',
|
||||
srcs = glob(['*.java']),
|
||||
deps = [
|
||||
react_native_dep('third-party/android/support/v4:lib-support-v4'),
|
||||
react_native_dep('third-party/java/infer-annotations:infer-annotations'),
|
||||
react_native_dep('third-party/java/jsr-305:jsr-305'),
|
||||
react_native_target('java/com/facebook/react/bridge:bridge'),
|
||||
|
@ -12,6 +12,10 @@ package com.facebook.react.modules.i18nmanager;
|
||||
import android.content.Context;
|
||||
import android.content.SharedPreferences;
|
||||
import android.content.SharedPreferences.Editor;
|
||||
import android.support.v4.text.TextUtilsCompat;
|
||||
import android.support.v4.view.ViewCompat;
|
||||
|
||||
import java.util.Locale;
|
||||
|
||||
public class I18nUtil {
|
||||
private static I18nUtil sharedI18nUtilInstance = null;
|
||||
@ -32,10 +36,11 @@ public class I18nUtil {
|
||||
return sharedI18nUtilInstance;
|
||||
}
|
||||
|
||||
// If set allowRTL on the JS side,
|
||||
// If the current device language is RTL and RTL is allowed for the app,
|
||||
// the RN app will automatically have a RTL layout.
|
||||
public boolean isRTL(Context context) {
|
||||
return allowRTL(context);
|
||||
return allowRTL(context) &&
|
||||
isDevicePreferredLanguageRTL();
|
||||
}
|
||||
|
||||
private boolean allowRTL(Context context) {
|
||||
@ -50,4 +55,11 @@ public class I18nUtil {
|
||||
editor.putBoolean(KEY_FOR_PREFS, allowRTL);
|
||||
editor.apply();
|
||||
}
|
||||
|
||||
// Check if the current device language is RTL
|
||||
private boolean isDevicePreferredLanguageRTL() {
|
||||
final int directionality =
|
||||
TextUtilsCompat.getLayoutDirectionFromLocale(Locale.getDefault());
|
||||
return directionality == ViewCompat.LAYOUT_DIRECTION_RTL;
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user