react-native-fluq
Version:
Firebase Dynamic Links alternative for React Native
43 lines (42 loc) • 1.43 kB
JavaScript
Object.defineProperty(exports, "__esModule", { value: true });
const react_native_1 = require("react-native");
const { RNDynamicLinks } = react_native_1.NativeModules;
class DynamicLinks {
/**
* Get the initial dynamic link that opened the app
*
* @returns Promise that resolves to the dynamic link or null if none
*/
static getInitialLink() {
return RNDynamicLinks.getInitialLink();
}
/**
* Add a listener for dynamic links while the app is running
*
* @param listener The callback function that will receive dynamic link data
* @returns Function to unsubscribe the listener
*/
static onLink(listener) {
const eventEmitter = react_native_1.Platform.OS === 'ios'
? RNDynamicLinks.addListener
: RNDynamicLinks.addListener;
const subscription = eventEmitter('onDynamicLink', (event) => {
listener({
url: event.url,
params: event.params || {},
});
});
return () => subscription.remove();
}
/**
* Create a dynamic link with parameters
*
* @param options The options for creating a dynamic link
* @returns Promise that resolves to the created dynamic link
*/
static async createDynamicLink(options) {
return RNDynamicLinks.createDynamicLink(options);
}
}
exports.default = DynamicLinks;
;