Skip to content

Commit ae80c18

Browse files
authored
Merge pull request #612 from Iterable/2.0.0-alpha/MOB-10290-create-loader-for-rniterableapi
[MOB-10290] create-loader-for-rniterableapi
2 parents 59d843a + 5471444 commit ae80c18

File tree

6 files changed

+33
-21
lines changed

6 files changed

+33
-21
lines changed

src/core/classes/Iterable.ts

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,4 @@
1-
import {
2-
Linking,
3-
NativeEventEmitter,
4-
NativeModules,
5-
Platform,
6-
} from 'react-native';
1+
import { Linking, NativeEventEmitter, Platform } from 'react-native';
72

83
import {
94
IterableInAppCloseSource,
@@ -21,8 +16,8 @@ import { IterableAuthResponse } from './IterableAuthResponse';
2116
import type { IterableCommerceItem } from './IterableCommerceItem';
2217
import { IterableConfig } from './IterableConfig';
2318
import { IterableLogger } from './IterableLogger';
19+
import { RNIterableAPI } from './RNIterableAPI';
2420

25-
const RNIterableAPI = NativeModules.RNIterableAPI;
2621
const RNEventEmitter = new NativeEventEmitter(RNIterableAPI);
2722

2823
/**

src/core/classes/RNIterableAPI.ts

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import { NativeModules, Platform } from 'react-native';
2+
3+
const LINKING_ERROR =
4+
`The package '@iterable/react-native-sdk' doesn't seem to be linked. Make sure: \n\n` +
5+
Platform.select({ ios: "- You have run 'pod install'\n", default: '' }) +
6+
'- You rebuilt the app after installing the package\n' +
7+
'- You are not using Expo Go\n';
8+
9+
/**
10+
* A bridge between React Native and the native Iterable SDK.
11+
*
12+
* If the module is not available, it throws an error when accessed.
13+
*
14+
* @type {object}
15+
* @throws {Error} Throws an error if the RNIterableAPI module is not linked properly.
16+
*/
17+
export const RNIterableAPI = NativeModules.RNIterableAPI
18+
? NativeModules.RNIterableAPI
19+
: new Proxy(
20+
{},
21+
{
22+
get() {
23+
throw new Error(LINKING_ERROR);
24+
},
25+
}
26+
);

src/core/classes/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,4 @@ export * from './IterableConfig';
88
export * from './IterableEdgeInsets';
99
export * from './IterableLogger';
1010
export * from './IterableUtil';
11+
export * from './RNIterableAPI';

src/inApp/classes/IterableInAppManager.ts

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,11 @@
1-
import { NativeModules } from 'react-native';
2-
3-
import { Iterable } from '../../core';
1+
import { Iterable, RNIterableAPI } from '../../core';
42
import type {
53
IterableInAppDeleteSource,
64
IterableInAppLocation,
75
} from '../enums';
86
import { IterableHtmlInAppContent } from './IterableHtmlInAppContent';
97
import { IterableInAppMessage } from './IterableInAppMessage';
108

11-
// TODO: Create a loader for this
12-
const RNIterableAPI = NativeModules.RNIterableAPI;
13-
149
/**
1510
* Manages in-app messages for the current user.
1611
*

src/inbox/classes/IterableInboxDataModel.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
import { NativeModules } from 'react-native';
2-
3-
import { Iterable } from '../../core';
1+
import { Iterable, RNIterableAPI } from '../../core';
42
import {
53
IterableHtmlInAppContent,
64
IterableInAppDeleteSource,
@@ -13,8 +11,6 @@ import type {
1311
IterableInboxRowViewModel,
1412
} from '../types';
1513

16-
const RNIterableAPI = NativeModules.RNIterableAPI;
17-
1814
/**
1915
* The `IterableInboxDataModel` class provides methods to manage and manipulate
2016
* inbox messages.

src/inbox/components/IterableInbox.tsx

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import { useEffect, useState } from 'react';
33
import {
44
Animated,
55
NativeEventEmitter,
6-
NativeModules,
76
Platform,
87
StyleSheet,
98
Text,
@@ -13,12 +12,14 @@ import { SafeAreaView } from 'react-native-safe-area-context';
1312

1413
import {
1514
Iterable,
15+
RNIterableAPI,
1616
useAppStateListener,
1717
useDeviceOrientation,
1818
} from '../../core';
1919
import { IterableInAppDeleteSource, IterableInAppLocation } from '../../inApp';
2020

2121
import { IterableInboxDataModel } from '../classes';
22+
import { ITERABLE_INBOX_COLORS } from '../constants';
2223
import type {
2324
IterableInboxCustomizations,
2425
IterableInboxImpressionRowInfo,
@@ -30,9 +31,7 @@ import {
3031
IterableInboxMessageList,
3132
type IterableInboxMessageListProps,
3233
} from './IterableInboxMessageList';
33-
import { ITERABLE_INBOX_COLORS } from '../constants';
3434

35-
const RNIterableAPI = NativeModules.RNIterableAPI;
3635
const RNEventEmitter = new NativeEventEmitter(RNIterableAPI);
3736

3837
const DEFAULT_HEADLINE_HEIGHT = 60;

0 commit comments

Comments
 (0)