forked from Iterable/react-native-sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRNIterableAPIPackage.java
More file actions
52 lines (48 loc) · 1.95 KB
/
RNIterableAPIPackage.java
File metadata and controls
52 lines (48 loc) · 1.95 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
package com.iterable.reactnative;
import java.util.HashMap;
import java.util.Map;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import com.facebook.react.BaseReactPackage;
import com.facebook.react.bridge.NativeModule;
import com.facebook.react.bridge.ReactApplicationContext;
import com.facebook.react.module.model.ReactModuleInfo;
import com.facebook.react.module.model.ReactModuleInfoProvider;
import com.iterable.iterableapi.IterableApi;
public class RNIterableAPIPackage extends BaseReactPackage {
@Nullable
@Override
public NativeModule getModule(@NonNull String name, @NonNull ReactApplicationContext reactContext) {
if (RNIterableAPIModuleImpl.NAME.equals(name)) {
// Automatically set the context so users don't need to call
// IterableApi.setContext() manually from MainApplication or MainActivity.
// This resolves issues with IterableApi being unresolvable in
// MainApplication.kt when using the new architecture (RN 0.76+).
IterableApi.setContext(reactContext.getApplicationContext());
return new RNIterableAPIModule(reactContext);
} else {
return null;
}
}
@NonNull
@Override
public ReactModuleInfoProvider getReactModuleInfoProvider() {
return new ReactModuleInfoProvider() {
@NonNull
@Override
public Map<String, ReactModuleInfo> getReactModuleInfos() {
Map<String, ReactModuleInfo> moduleInfos = new HashMap<>();
boolean isTurboModule = BuildConfig.IS_NEW_ARCHITECTURE_ENABLED;
moduleInfos.put(RNIterableAPIModuleImpl.NAME, new ReactModuleInfo(
RNIterableAPIModuleImpl.NAME,
RNIterableAPIModuleImpl.NAME,
false, // canOverrideExistingModule
false, // needsEagerInit
false, // isCxxModule
isTurboModule // isTurboModule
));
return moduleInfos;
}
};
}
}