Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(inappmessaging): add support for triggering custom events #4201

Merged
merged 2 commits into from
Sep 3, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,13 @@ Task<Void> setMessagesDisplaySuppressed(Boolean enabled) {
});
}

Task<Void> triggerEvent(String eventId) {
return Tasks.call(() -> {
FirebaseInAppMessaging.getInstance().triggerEvent(eventId);
return null;
});
}

@Override
public Map<String, Object> getConstants() {
final Map<String, Object> constants = new HashMap<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,17 @@ public void setMessagesDisplaySuppressed(Boolean enabled, Promise promise) {
});
}

@ReactMethod
public void triggerEvent(String eventId, Promise promise) {
module.triggerEvent(eventId).addOnCompleteListener(task -> {
if (task.isSuccessful()) {
promise.resolve(task.getResult());
} else {
rejectPromiseWithExceptionMap(promise, task.getException());
}
});
}

@Override
public Map<String, Object> getConstants() {
return module.getConstants();
Expand Down
11 changes: 11 additions & 0 deletions packages/in-app-messaging/ios/RNFBFiam/RNFBFiamModule.m
Original file line number Diff line number Diff line change
Expand Up @@ -62,5 +62,16 @@ + (BOOL)requiresMainQueueSetup {
[FIRInAppMessaging inAppMessaging].messageDisplaySuppressed = (BOOL) enabled;
resolve([NSNull null]);
}

RCT_EXPORT_METHOD(triggerEvent:
(NSString) eventId
resolver:
(RCTPromiseResolveBlock) resolve
rejecter:
(RCTPromiseRejectBlock) reject) {
[[FIRInAppMessaging inAppMessaging] triggerEvent: eventId];
resolve([NSNull null]);
}


@end
14 changes: 14 additions & 0 deletions packages/in-app-messaging/lib/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,20 @@ export namespace FirebaseInAppMessagingTypes {
* @param enabled Whether automatic data collection is enabled.
*/
setAutomaticDataCollectionEnabled(enabled: boolean): Promise<null>;

/**
* Trigger in-app messages programmatically
*
* #### Example
*
* ```js
* // Suppress messages
* await firebase.inAppMessaging().triggerEvent("exampleTrigger");
* ```
*
* @param eventId The id of the event.
*/
triggerEvent(eventId: string): Promise<null>;
}
}

Expand Down
9 changes: 8 additions & 1 deletion packages/in-app-messaging/lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
*
*/

import { isBoolean } from '@react-native-firebase/app/lib/common';
import { isBoolean, isString } from '@react-native-firebase/app/lib/common';
import {
createModuleNamespace,
FirebaseModule,
Expand Down Expand Up @@ -65,6 +65,13 @@ class FirebaseFiamModule extends FirebaseModule {
this._isAutomaticDataCollectionEnabled = enabled;
return this.native.setAutomaticDataCollectionEnabled(enabled);
}

triggerEvent(eventId) {
if (!isString(eventId)) {
throw new Error("firebase.inAppMessaging().triggerEvent(*) 'eventId' must be a string.");
}
return this.native.triggerEvent(eventId);
}
}

// import { SDK_VERSION } from '@react-native-firebase/in-app-messaging';
Expand Down