Skip to content

Commit 23d9bf1

Browse files
RSNarafacebook-github-bot
authored andcommitted
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
1 parent b15f8a3 commit 23d9bf1

File tree

4 files changed

+28
-19
lines changed

4 files changed

+28
-19
lines changed

Libraries/ReactNative/I18nManager.js

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,19 @@ import NativeI18nManager from './NativeI18nManager';
1313
const i18nConstants: {|
1414
doLeftAndRightSwapInRTL: boolean,
1515
isRTL: boolean,
16-
|} = NativeI18nManager
17-
? NativeI18nManager.getConstants()
18-
: {
19-
isRTL: false,
20-
doLeftAndRightSwapInRTL: true,
21-
};
16+
|} = getI18nManagerConstants();
17+
18+
function getI18nManagerConstants() {
19+
if (NativeI18nManager) {
20+
const {isRTL, doLeftAndRightSwapInRTL} = NativeI18nManager.getConstants();
21+
return {isRTL, doLeftAndRightSwapInRTL};
22+
}
23+
24+
return {
25+
isRTL: false,
26+
doLeftAndRightSwapInRTL: true,
27+
};
28+
}
2229

2330
module.exports = {
2431
getConstants: (): {|doLeftAndRightSwapInRTL: boolean, isRTL: boolean|} => {

Libraries/ReactNative/NativeI18nManager.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ export interface Spec extends TurboModule {
1515
+getConstants: () => {|
1616
isRTL: boolean,
1717
doLeftAndRightSwapInRTL: boolean,
18+
localeIdentifier: ?string,
1819
|};
1920
allowRTL: (allowRTL: boolean) => void;
2021
forceRTL: (forceRTL: boolean) => void;

ReactAndroid/src/main/java/com/facebook/react/modules/i18nmanager/BUCK

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
load("//tools/build_defs/oss:rn_defs.bzl", "react_native_dep", "react_native_target", "rn_android_library")
1+
load("//tools/build_defs/oss:rn_defs.bzl", "react_native_dep", "react_native_root_target", "react_native_target", "rn_android_library")
22

33
rn_android_library(
44
name = "i18nmanager",
@@ -22,5 +22,6 @@ rn_android_library(
2222
react_native_target("java/com/facebook/react/bridge:bridge"),
2323
react_native_target("java/com/facebook/react/common:common"),
2424
react_native_target("java/com/facebook/react/module/annotations:annotations"),
25+
react_native_root_target("Libraries:FBReactNativeSpec"),
2526
],
2627
)

ReactAndroid/src/main/java/com/facebook/react/modules/i18nmanager/I18nManagerModule.java

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,23 +8,23 @@
88
package com.facebook.react.modules.i18nmanager;
99

1010
import android.content.Context;
11-
import com.facebook.react.bridge.ContextBaseJavaModule;
11+
import com.facebook.fbreact.specs.NativeI18nManagerSpec;
1212
import com.facebook.react.bridge.NativeModule;
13-
import com.facebook.react.bridge.ReactMethod;
13+
import com.facebook.react.bridge.ReactApplicationContext;
1414
import com.facebook.react.common.MapBuilder;
1515
import com.facebook.react.module.annotations.ReactModule;
1616
import java.util.Locale;
1717
import java.util.Map;
1818

1919
/** {@link NativeModule} that allows JS to set allowRTL and get isRTL status. */
2020
@ReactModule(name = I18nManagerModule.NAME)
21-
public class I18nManagerModule extends ContextBaseJavaModule {
21+
public class I18nManagerModule extends NativeI18nManagerSpec {
2222

2323
public static final String NAME = "I18nManager";
2424

2525
private final I18nUtil sharedI18nUtilInstance = I18nUtil.getInstance();
2626

27-
public I18nManagerModule(Context context) {
27+
public I18nManagerModule(ReactApplicationContext context) {
2828
super(context);
2929
}
3030

@@ -34,8 +34,8 @@ public String getName() {
3434
}
3535

3636
@Override
37-
public Map<String, Object> getConstants() {
38-
final Context context = getContext();
37+
public Map<String, Object> getTypedExportedConstants() {
38+
final Context context = getReactApplicationContext();
3939
final Locale locale = context.getResources().getConfiguration().locale;
4040

4141
final Map<String, Object> constants = MapBuilder.newHashMap();
@@ -46,18 +46,18 @@ public Map<String, Object> getConstants() {
4646
return constants;
4747
}
4848

49-
@ReactMethod
49+
@Override
5050
public void allowRTL(boolean value) {
51-
sharedI18nUtilInstance.allowRTL(getContext(), value);
51+
sharedI18nUtilInstance.allowRTL(getReactApplicationContext(), value);
5252
}
5353

54-
@ReactMethod
54+
@Override
5555
public void forceRTL(boolean value) {
56-
sharedI18nUtilInstance.forceRTL(getContext(), value);
56+
sharedI18nUtilInstance.forceRTL(getReactApplicationContext(), value);
5757
}
5858

59-
@ReactMethod
59+
@Override
6060
public void swapLeftAndRightInRTL(boolean value) {
61-
sharedI18nUtilInstance.swapLeftAndRightInRTL(getContext(), value);
61+
sharedI18nUtilInstance.swapLeftAndRightInRTL(getReactApplicationContext(), value);
6262
}
6363
}

0 commit comments

Comments
 (0)