Fixes LocaleList not supported below API level 24

Modifies WritableArray method so that LocaleList is not needed on devices with lower than API level 24.
This commit is contained in:
Dave Pack 2017-06-07 20:10:52 -06:00 committed by GitHub
parent 8e22064009
commit 5e940eeab1

View File

@ -42,14 +42,16 @@ public class RNI18nModule extends ReactContextBaseJavaModule {
} }
private WritableArray getLocaleList() { private WritableArray getLocaleList() {
LocaleList locales = Build.VERSION.SDK_INT >= Build.VERSION_CODES.N
? getReactApplicationContext().getResources().getConfiguration().getLocales()
: new LocaleList(getReactApplicationContext().getResources().getConfiguration().locale);
WritableArray array = Arguments.createArray(); WritableArray array = Arguments.createArray();
for (int i = 0; i < locales.size(); i++) { if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.N) {
array.pushString(this.toLanguageTag(locales.get(i))); LocaleList locales = getReactApplicationContext().getResources().getConfiguration().getLocales();
for (int i = 0; i < locales.size(); i++) {
array.pushString(this.toLanguageTag(locales.get(i)));
}
} else {
array.pushString(this.toLanguageTag(getReactApplicationContext().getResources().getConfiguration().locale));
} }
return array; return array;