react-native-notificare-in-app-messaging
Version:
Notificare In-App Messaging React Native module.
141 lines (130 loc) • 5.59 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.NotificareInAppMessaging = void 0;
var _reactNative = require("react-native");
const LINKING_ERROR = `The package 'react-native-notificare-in-app-messaging' doesn't seem to be linked. Make sure: \n\n` + _reactNative.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';
// @ts-expect-error
const isTurboModuleEnabled = global.__turboModuleProxy != null;
const NotificareInAppMessagingModule = isTurboModuleEnabled ? require('./NativeNotificareInAppMessagingModule').default : _reactNative.NativeModules.NotificareInAppMessagingModule;
const NativeModule = NotificareInAppMessagingModule ? NotificareInAppMessagingModule : new Proxy({}, {
get() {
throw new Error(LINKING_ERROR);
}
});
class NotificareInAppMessaging {
static eventEmitter = new _reactNative.NativeEventEmitter(NativeModule);
//
// Methods
//
/**
* Indicates whether in-app messages are currently suppressed.
*
* @returns {Promise<boolean>} - A promise that resolves to `true` if message
* dispatching and the presentation of in-app messages are temporarily
* suppressed and `false` if in-app messages are allowed to be presented.
*/
static async hasMessagesSuppressed() {
return await NativeModule.hasMessagesSuppressed();
}
/**
* Sets the message suppression state.
*
* When messages are suppressed, in-app messages will not be presented to the
* user. By default, stopping the in-app message suppression does not
* re-evaluate the foreground context.
*
* To trigger a new context evaluation after stopping in-app message
* suppression, set the `evaluateContext` parameter to `true`.
*
* @param {boolean} suppressed - Set to `true` to suppress in-app messages, or
* `false` to stop suppressing them.
* @param {boolean} evaluateContext - Set to `true` to re-evaluate the foreground
* context when stopping in-app message suppression.
* @returns {Promise<void>} - A promise that resolves when the message suppression
* state has been successfully set.
*/
static async setMessagesSuppressed(suppressed, evaluateContext) {
const data = {
suppressed: suppressed,
evaluateContext: evaluateContext
};
await NativeModule.setMessagesSuppressed(data);
}
//
// Events
//
/**
* Called when an in-app message is successfully presented to the user.
*
* @param callback - A callback that will be invoked with the result of the
* onMessagePresented event. It will provide the {@link NotificareInAppMessage}
* that was presented.
* @returns {EmitterSubscription} - The {@link EmitterSubscription} for the
* onMessagePresented event.
*/
static onMessagePresented(callback) {
return this.eventEmitter.addListener('re.notifica.iam.message_presented', callback);
}
/**
* Called when the presentation of an in-app message has finished.
*
* This method is invoked after the message is no longer visible to the user.
*
* @param callback - A callback that will be invoked with the result of the
* onMessageFinishedPresenting event. It will provide the
* {@link NotificareInAppMessage} that finished presenting.
* @returns {EmitterSubscription} - The {@link EmitterSubscription} for the
* onMessageFinishedPresenting event.
*/
static onMessageFinishedPresenting(callback) {
return this.eventEmitter.addListener('re.notifica.iam.message_finished_presenting', callback);
}
/**
* Called when an in-app message failed to present.
*
* @param callback - A callback that will be invoked with the result of the
* onMessageFailedToPresent event. It will provide the
* {@link NotificareInAppMessage} that failed to present.
* @returns {EmitterSubscription} - The {@link EmitterSubscription} for the
* onMessageFailedToPresent event.
*/
static onMessageFailedToPresent(callback) {
return this.eventEmitter.addListener('re.notifica.iam.message_failed_to_present', callback);
}
/**
* Called when an action is successfully executed for an in-app message.
*
* @param callback - A callback that will be invoked with the result of the
* onActionExecuted event. It will provide the
* {@link NotificareInAppMessageAction} that was executed and the
* {@link NotificareInAppMessage} for which the action was executed.
* @returns {EmitterSubscription} - The {@link EmitterSubscription} for the
* onActionExecuted event.
*/
static onActionExecuted(callback) {
return this.eventEmitter.addListener('re.notifica.iam.action_executed', callback);
}
/**
* Called when an action execution failed for an in-app message.
*
* This method is triggered when an error occurs while attempting to execute
* an action.
*
* @param callback - A callback that will be invoked with the result of the
* onActionFailedToExecuted event. It will provide the
* {@link NotificareInAppMessageAction} that failed to execute and the
* {@link NotificareInAppMessage} for which the action was attempted.
* @returns {EmitterSubscription} - The {@link EmitterSubscription} for the
* onActionFailedToExecute event.
*/
static onActionFailedToExecute(callback) {
return this.eventEmitter.addListener('re.notifica.iam.action_failed_to_execute', callback);
}
}
exports.NotificareInAppMessaging = NotificareInAppMessaging;
//# sourceMappingURL=notificare-in-app-messaging.js.map