Make I18nManagerModule TurboModule-compatible

Summary:
This NativeModule will now be type-safe, and TurboModule-compatible.

Changelog: [Internal]

Reviewed By: fkgozali

Differential Revision: D26956332

fbshipit-source-id: 6651a003c70819934869dd6a8c664ef984d0efcb
This commit is contained in:
Ramanpreet Nara
2021-03-10 14:55:29 -08:00
committed by Facebook GitHub Bot
parent b15f8a30e7
commit 23d9bf1a24
4 changed files with 28 additions and 19 deletions
@@ -1,4 +1,4 @@
load("//tools/build_defs/oss:rn_defs.bzl", "react_native_dep", "react_native_target", "rn_android_library")
load("//tools/build_defs/oss:rn_defs.bzl", "react_native_dep", "react_native_root_target", "react_native_target", "rn_android_library")
rn_android_library(
name = "i18nmanager",
@@ -22,5 +22,6 @@ rn_android_library(
react_native_target("java/com/facebook/react/bridge:bridge"),
react_native_target("java/com/facebook/react/common:common"),
react_native_target("java/com/facebook/react/module/annotations:annotations"),
react_native_root_target("Libraries:FBReactNativeSpec"),
],
)
@@ -8,9 +8,9 @@
package com.facebook.react.modules.i18nmanager;
import android.content.Context;
import com.facebook.react.bridge.ContextBaseJavaModule;
import com.facebook.fbreact.specs.NativeI18nManagerSpec;
import com.facebook.react.bridge.NativeModule;
import com.facebook.react.bridge.ReactMethod;
import com.facebook.react.bridge.ReactApplicationContext;
import com.facebook.react.common.MapBuilder;
import com.facebook.react.module.annotations.ReactModule;
import java.util.Locale;
@@ -18,13 +18,13 @@ import java.util.Map;
/** {@link NativeModule} that allows JS to set allowRTL and get isRTL status. */
@ReactModule(name = I18nManagerModule.NAME)
public class I18nManagerModule extends ContextBaseJavaModule {
public class I18nManagerModule extends NativeI18nManagerSpec {
public static final String NAME = "I18nManager";
private final I18nUtil sharedI18nUtilInstance = I18nUtil.getInstance();
public I18nManagerModule(Context context) {
public I18nManagerModule(ReactApplicationContext context) {
super(context);
}
@@ -34,8 +34,8 @@ public class I18nManagerModule extends ContextBaseJavaModule {
}
@Override
public Map<String, Object> getConstants() {
final Context context = getContext();
public Map<String, Object> getTypedExportedConstants() {
final Context context = getReactApplicationContext();
final Locale locale = context.getResources().getConfiguration().locale;
final Map<String, Object> constants = MapBuilder.newHashMap();
@@ -46,18 +46,18 @@ public class I18nManagerModule extends ContextBaseJavaModule {
return constants;
}
@ReactMethod
@Override
public void allowRTL(boolean value) {
sharedI18nUtilInstance.allowRTL(getContext(), value);
sharedI18nUtilInstance.allowRTL(getReactApplicationContext(), value);
}
@ReactMethod
@Override
public void forceRTL(boolean value) {
sharedI18nUtilInstance.forceRTL(getContext(), value);
sharedI18nUtilInstance.forceRTL(getReactApplicationContext(), value);
}
@ReactMethod
@Override
public void swapLeftAndRightInRTL(boolean value) {
sharedI18nUtilInstance.swapLeftAndRightInRTL(getContext(), value);
sharedI18nUtilInstance.swapLeftAndRightInRTL(getReactApplicationContext(), value);
}
}