react-native-grovs-wrapper
Version:
Grovs react native SDK
63 lines (60 loc) • 2.22 kB
JavaScript
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = exports.TurboModuleGrovs = void 0;
var _reactNative = require("react-native");
var _Logger = require("./Logger.js");
// Get the native module from RN's registry
const NativeModule = _reactNative.TurboModuleRegistry.get('GrovsWrapper');
if (!NativeModule) {
(0, _Logger.log)('info', 'Turbo module - Native module react-native-grovs-wrapper is not linked properly.');
throw new Error('Native module react-native-grovs-wrapper is not linked properly.');
}
class TurboModuleGrovs {
// Simple methods
setIdentifier(identifier) {
NativeModule?.setIdentifier(identifier);
}
setPushToken(pushToken) {
NativeModule?.setPushToken(pushToken);
}
setAttributes(attributes) {
NativeModule?.setAttributes(attributes);
}
setSDK(enabled) {
NativeModule?.setSDK(enabled);
}
setDebug(level) {
NativeModule?.setDebug(level);
}
async generateLink(title, subtitle, imageURL, data, tags, customRedirects, showPreviewIos, showPreviewAndroid) {
if (!NativeModule) {
throw new Error('Native module GrovsWrapper is not linked');
}
return NativeModule?.generateLink(title, subtitle, imageURL, data, tags, customRedirects, showPreviewIos, showPreviewAndroid);
}
async displayMessages() {
return NativeModule?.displayMessages();
}
async numberOfUnreadMessages() {
if (!NativeModule) {
throw new Error('Native module GrovsWrapper is not linked');
}
return NativeModule?.numberOfUnreadMessages();
}
// Event subscription wrapper
onDeeplinkReceived(callback) {
const eventEmitter = NativeModule == null ? null : new _reactNative.NativeEventEmitter(NativeModule);
(0, _Logger.log)('info', 'Turbo module - registering callback');
const subscription = eventEmitter?.addListener('onGrovsDeeplinkReceived', callback);
NativeModule?.markReadyToHandleDeeplinks();
return {
remove: () => subscription?.remove()
};
}
}
// Export a singleton instance if that fits your architecture
exports.TurboModuleGrovs = TurboModuleGrovs;
var _default = exports.default = new TurboModuleGrovs();
//# sourceMappingURL=NativeGrovsWrapper.js.map
;