Skip to content
Open
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
- The bridge now displays the message on the main thread, matching `setAutoDisplayPaused` and the iOS SDK. It was calling the native in-app displayer on the React Native native-modules thread, which crashes when the current activity is not a `FragmentActivity` (for example a Jetpack Compose `ComponentActivity`).
- The promise now rejects when the message id is empty or no longer in the native queue instead of crashing with a `NullPointerException`.
- Dismissing a message by tapping outside it now resolves the promise with `null` instead of crashing on `url.toString()`.
- `Iterable.inAppManager.showMessage` now rejects on iOS when the message id is empty or no longer in the native queue, matching Android. Previously the promise never settled.

### Updates

Expand Down
8 changes: 8 additions & 0 deletions ios/RNIterableAPI/ReactIterableAPI.swift
Original file line number Diff line number Diff line change
Expand Up @@ -384,8 +384,16 @@ import React
rejecter: RCTPromiseRejectBlock
) {
ITBInfo()
guard !messageId.isEmpty else {
ITBError("messageId is null or empty")
rejecter("", "messageId is null or empty", NSError(domain: "", code: 0, userInfo: nil))
return
}
guard let message = IterableAPI.inAppManager.getMessage(withId: messageId) else {
ITBError("Could not find message with id: \(messageId)")
rejecter(
"", "Could not find message with id: \(messageId)",
NSError(domain: "", code: 0, userInfo: nil))
return
}
IterableAPI.inAppManager.show(message: message, consume: consume) { (url) in
Expand Down
19 changes: 19 additions & 0 deletions src/__tests__/IterableInApp.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,25 @@ describe('Iterable In App', () => {
});
});

test('showMessage_nativeRejects_propagatesRejectionToJs', async () => {
// JS contract only: the native rejection itself is implemented in the iOS and Android bridges
// GIVEN an in-app message that is no longer in the native queue
const message: IterableInAppMessage = IterableInAppMessage.fromDict({
messageId: 'message1',
campaignId: 1234,
trigger: { type: IterableInAppTriggerType.immediate },
});
const error = new Error('Could not find message with id: message1');

// WHEN the native module rejects the call
MockRNIterableAPI.showMessage.mockRejectedValueOnce(error);

// THEN Iterable.inAppManager.showMessage rejects with the native error
await expect(
Iterable.inAppManager?.showMessage(message, true)
).rejects.toBe(error);
});

test('removeMessage_params_methodCalledWithParams', () => {
// GIVEN an in-app message
const messageDict = {
Expand Down
Loading