Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 2 additions & 7 deletions src/core/classes/Iterable.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,4 @@
import {
Linking,
NativeEventEmitter,
NativeModules,
Platform,
} from 'react-native';
import { Linking, NativeEventEmitter, Platform } from 'react-native';

import {
IterableInAppCloseSource,
Expand All @@ -21,8 +16,8 @@ import { IterableAuthResponse } from './IterableAuthResponse';
import type { IterableCommerceItem } from './IterableCommerceItem';
import { IterableConfig } from './IterableConfig';
import { IterableLogger } from './IterableLogger';
import { RNIterableAPI } from './RNIterableAPI';

const RNIterableAPI = NativeModules.RNIterableAPI;
const RNEventEmitter = new NativeEventEmitter(RNIterableAPI);

/**
Expand Down
26 changes: 26 additions & 0 deletions src/core/classes/RNIterableAPI.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { NativeModules, Platform } from 'react-native';

const LINKING_ERROR =
`The package '@iterable/react-native-sdk' doesn't seem to be linked. Make sure: \n\n` +
Platform.select({ ios: "- You have run 'pod install'\n", default: '' }) +
'- You rebuilt the app after installing the package\n' +
'- You are not using Expo Go\n';

/**
* A bridge between React Native and the native Iterable SDK.
*
* If the module is not available, it throws an error when accessed.
*
* @type {object}
* @throws {Error} Throws an error if the RNIterableAPI module is not linked properly.
*/
export const RNIterableAPI = NativeModules.RNIterableAPI
? NativeModules.RNIterableAPI
: new Proxy(
{},
{
get() {
throw new Error(LINKING_ERROR);
},
}
);
1 change: 1 addition & 0 deletions src/core/classes/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ export * from './IterableConfig';
export * from './IterableEdgeInsets';
export * from './IterableLogger';
export * from './IterableUtil';
export * from './RNIterableAPI';
7 changes: 1 addition & 6 deletions src/inApp/classes/IterableInAppManager.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,11 @@
import { NativeModules } from 'react-native';

import { Iterable } from '../../core';
import { Iterable, RNIterableAPI } from '../../core';
import type {
IterableInAppDeleteSource,
IterableInAppLocation,
} from '../enums';
import { IterableHtmlInAppContent } from './IterableHtmlInAppContent';
import { IterableInAppMessage } from './IterableInAppMessage';

// TODO: Create a loader for this
const RNIterableAPI = NativeModules.RNIterableAPI;

/**
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice this makes it much cleaner and maintainable

* Manages in-app messages for the current user.
*
Expand Down
6 changes: 1 addition & 5 deletions src/inbox/classes/IterableInboxDataModel.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import { NativeModules } from 'react-native';

import { Iterable } from '../../core';
import { Iterable, RNIterableAPI } from '../../core';
import {
IterableHtmlInAppContent,
IterableInAppDeleteSource,
Expand All @@ -13,8 +11,6 @@ import type {
IterableInboxRowViewModel,
} from '../types';

const RNIterableAPI = NativeModules.RNIterableAPI;

/**
* The `IterableInboxDataModel` class provides methods to manage and manipulate
* inbox messages.
Expand Down
5 changes: 2 additions & 3 deletions src/inbox/components/IterableInbox.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { useEffect, useState } from 'react';
import {
Animated,
NativeEventEmitter,
NativeModules,
Platform,
StyleSheet,
Text,
Expand All @@ -13,12 +12,14 @@ import { SafeAreaView } from 'react-native-safe-area-context';

import {
Iterable,
RNIterableAPI,
useAppStateListener,
useDeviceOrientation,
} from '../../core';
import { IterableInAppDeleteSource, IterableInAppLocation } from '../../inApp';

import { IterableInboxDataModel } from '../classes';
import { ITERABLE_INBOX_COLORS } from '../constants';
import type {
IterableInboxCustomizations,
IterableInboxImpressionRowInfo,
Expand All @@ -30,9 +31,7 @@ import {
IterableInboxMessageList,
type IterableInboxMessageListProps,
} from './IterableInboxMessageList';
import { ITERABLE_INBOX_COLORS } from '../constants';

const RNIterableAPI = NativeModules.RNIterableAPI;
const RNEventEmitter = new NativeEventEmitter(RNIterableAPI);

const DEFAULT_HEADLINE_HEIGHT = 60;
Expand Down