Skip to content

Commit 2e1985a

Browse files
authored
Merge pull request #78 from Iterable/MOB-2081-in-app-auto-display-pause
[MOB-2081] add in-app display pause bindings
2 parents 9a5f429 + 3394d5a commit 2e1985a

File tree

9 files changed

+44
-72
lines changed

9 files changed

+44
-72
lines changed

android/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,5 +22,5 @@ def getModuleVersion() {
2222

2323
dependencies {
2424
implementation 'com.facebook.react:react-native:+'
25-
api 'com.iterable:iterableapi:3.2.5'
25+
api 'com.iterable:iterableapi:3.2.6'
2626
}

android/src/main/java/com/iterable/reactnative/RNIterableAPIModule.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -340,6 +340,13 @@ public void setInAppShowResponse(Integer number) {
340340
}
341341
}
342342

343+
@ReactMethod
344+
public void setAutoDisplayPaused(boolean paused) {
345+
IterableLogger.printInfo();
346+
347+
IterableApi.getInstance().getInAppManager().setAutoDisplayPaused(paused);
348+
}
349+
343350
// ---------------------------------------------------------------------------------------
344351
// endregion
345352

ios/RNIterableAPI/RNIterableAPI.m

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
@interface RCT_EXTERN_REMAP_MODULE(RNIterableAPI, ReactIterableAPI, NSObject)
99

10+
// MARK: - SDK Functions
1011
RCT_EXTERN_METHOD(initializeWithApiKey: (nonnull NSString *) apiKey
1112
config: (nonnull NSDictionary *) config
1213
version: (nonnull NSString *) version)
@@ -21,6 +22,7 @@ @interface RCT_EXTERN_REMAP_MODULE(RNIterableAPI, ReactIterableAPI, NSObject)
2122
RCT_EXTERN_METHOD(getUserId: (RCTPromiseResolveBlock) resolve
2223
rejecter: (RCTPromiseRejectBlock) reject)
2324

25+
// MARK: - Iterable API Request Functions
2426
RCT_EXTERN_METHOD(disableDeviceForCurrentUser)
2527

2628
RCT_EXTERN_METHOD(setInAppShowResponse: (nonnull NSNumber *) inAppShowResponse)
@@ -71,6 +73,15 @@ @interface RCT_EXTERN_REMAP_MODULE(RNIterableAPI, ReactIterableAPI, NSObject)
7173
resolver: (RCTPromiseResolveBlock) resolve
7274
rejecter: (RCTPromiseRejectBlock) reject)
7375

76+
RCT_EXTERN_METHOD(updateSubscriptions: (NSArray *) emailListIds
77+
unsubscribedChannelIds: (NSArray *) unsubscribedChannelIds
78+
unsubscribedMessageTypeIds: (NSArray *) unsubscribedMessageTypeIds
79+
subscribedMessageTypeIds: (NSArray *) subscribedMessageTypeIds
80+
campaignId: (nonnull NSNumber *) campaignId
81+
templateId: (nonnull NSNumber *) templateId)
82+
83+
// MARK: - SDK In-App Manager Functions
84+
7485
RCT_EXTERN_METHOD(getInAppMessages: (RCTPromiseResolveBlock) resolve
7586
rejecter: (RCTPromiseRejectBlock) reject)
7687

@@ -96,11 +107,6 @@ @interface RCT_EXTERN_REMAP_MODULE(RNIterableAPI, ReactIterableAPI, NSObject)
96107
RCT_EXTERN_METHOD(setReadForMessage: (nonnull NSString *) messageId
97108
read: (BOOL) read)
98109

99-
RCT_EXTERN_METHOD(updateSubscriptions: (NSArray *) emailListIds
100-
unsubscribedChannelIds: (NSArray *) unsubscribedChannelIds
101-
unsubscribedMessageTypeIds: (NSArray *) unsubscribedMessageTypeIds
102-
subscribedMessageTypeIds: (NSArray *) subscribedMessageTypeIds
103-
campaignId: (nonnull NSNumber *) campaignId
104-
templateId: (nonnull NSNumber *) templateId)
110+
RCT_EXTERN_METHOD(setAutoDisplayPaused: (BOOL) paused)
105111

106112
@end

ios/RNIterableAPI/ReactIterableAPI.swift

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -378,6 +378,13 @@ class ReactIterableAPI: RCTEventEmitter {
378378

379379
IterableAPI.inAppManager.set(read: read, forMessage: message)
380380
}
381+
382+
@objc(setAutoDisplayPaused:)
383+
func set(autoDisplayPaused: Bool) {
384+
ITBInfo()
385+
386+
IterableAPI.inAppManager.isAutoDisplayPaused = autoDisplayPaused
387+
}
381388

382389
// MARK: Private
383390
private var shouldEmit = false

ts/Iterable.ts

Lines changed: 0 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -227,16 +227,6 @@ class Iterable {
227227
RNIterableAPI.setEmail(email)
228228
}
229229

230-
// /**
231-
// * Set the user of the SDK by email address and set the authentication token
232-
// * @param email the email address of the user
233-
// * @param token the authentication token of the user
234-
// */
235-
// static setEmailWithToken(email: string | undefined, token: string | undefined) {
236-
// console.log("setEmail: " + email + ", token: " + token)
237-
// RNIterableAPI.setEmailWithToken(email, token)
238-
// }
239-
240230
/**
241231
* Get the email of the current user
242232
*/
@@ -254,16 +244,6 @@ class Iterable {
254244
RNIterableAPI.setUserId(userId)
255245
}
256246

257-
// /**
258-
// * Set the user of the SDK by ID and set the authentication token
259-
// * @param userId the ID of the user
260-
// * @param token the authentication token of the user
261-
// */
262-
// static setUserIdWithToken(userId: string | undefined, token: string | undefined) {
263-
// console.log("setUserId: " + userId + ", token: " + token)
264-
// RNIterableAPI.setUserIdWithToken(userId, token)
265-
// }
266-
267247
/**
268248
* Get the user ID of the current user
269249
*/
@@ -400,16 +380,6 @@ class Iterable {
400380
RNIterableAPI.updateEmail(email)
401381
}
402382

403-
// /**
404-
// *
405-
// * @param email the new email for the user
406-
// * @param token the associated authentication token
407-
// */
408-
// static updateEmailWithToken(email: string, token: string | undefined) {
409-
// console.log("updateEmailWithToken")
410-
// RNIterableAPI.updateEmailWithToken(email, token)
411-
// }
412-
413383
/**
414384
*
415385
* @param {string} link URL in string form to be either opened as an app link or as a normal one

ts/IterableInAppClasses.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -272,6 +272,16 @@ class IterableInAppManager {
272272
return IterableHtmlInAppContent.fromDict(content)
273273
})
274274
}
275+
276+
/**
277+
* Pauses or unpauses the automatic displaying of in-apps
278+
* @param {boolean} paused whether the automatic displaying should be paused
279+
*/
280+
setAutoDisplayPaused(paused: boolean) {
281+
console.log("InAppManager.setAutoDisplayPaused")
282+
283+
RNIterableAPI.setAutoDisplayPaused(paused)
284+
}
275285
}
276286

277287
export {

ts/__mocks__/MockRNIterableAPI.ts

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,8 @@ export class MockRNIterableAPI {
2727
MockRNIterableAPI.userId = userId
2828
}
2929

30-
// static setEmailWithToken = jest.fn()
31-
32-
// static setUserIdWithToken = jest.fn()
33-
3430
static disableDeviceForCurrentUser = jest.fn()
3531

36-
static disableDeviceForAllUsers = jest.fn()
37-
3832
static trackPushOpenWithCampaignId = jest.fn()
3933

4034
static trackPurchase = jest.fn()
@@ -69,6 +63,8 @@ export class MockRNIterableAPI {
6963

7064
static getInAppMessages = jest.fn()
7165

66+
static setAutoDisplayPaused = jest.fn()
67+
7268
static showMessage = jest.fn()
7369

7470
static removeMessage = jest.fn()
@@ -81,8 +77,6 @@ export class MockRNIterableAPI {
8177

8278
static updateEmail = jest.fn()
8379

84-
// static updateEmailWithToken = jest.fn()
85-
8680
static handleAppLink = jest.fn()
8781

8882
static updateSubscriptions = jest.fn()

ts/__tests__/Iterable.spec.ts

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -25,24 +25,6 @@ test("set/get email", () => {
2525
})
2626
})
2727

28-
// test("set email with token", () => {
29-
// const email = "[email protected]"
30-
// const token = "token"
31-
32-
// Iterable.setEmailWithToken(email, token)
33-
34-
// expect(MockRNIterableAPI.setEmailWithToken).toBeCalledWith(email, token)
35-
// })
36-
37-
// test("set userId with token", () => {
38-
// const userId = "testUserId"
39-
// const token = "token"
40-
41-
// Iterable.setUserIdWithToken(userId, token)
42-
43-
// expect(MockRNIterableAPI.setUserIdWithToken).toBeCalledWith(userId, token)
44-
// })
45-
4628
test("set/get userId", () => {
4729
Iterable.setUserId("user1")
4830
return Iterable.getUserId().then(userId => {
@@ -131,15 +113,6 @@ test("update email", () => {
131113
expect(MockRNIterableAPI.updateEmail).toBeCalledWith(newEmail)
132114
})
133115

134-
// test("update email with token", () => {
135-
// const newEmail = "[email protected]"
136-
// const newToken = "token"
137-
138-
// Iterable.updateEmailWithToken(newEmail, newToken)
139-
140-
// expect(MockRNIterableAPI.updateEmailWithToken).toBeCalledWith(newEmail, newToken)
141-
// })
142-
143116
test("default config values", () => {
144117
var config = new IterableConfig()
145118

ts/__tests__/IterableInApp.spec.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,3 +167,8 @@ test("in-app set read for message is called", () => {
167167
Iterable.inAppManager.setReadForMessage(message, true)
168168
expect(MockRNIterableAPI.setReadForMessage).toBeCalledWith(message.messageId, true)
169169
})
170+
171+
test("in-app auto display paused", () => {
172+
Iterable.inAppManager.setAutoDisplayPaused(true)
173+
expect(MockRNIterableAPI.setAutoDisplayPaused).toBeCalledWith(true)
174+
})

0 commit comments

Comments
 (0)