2023-02-19 21:53:00 +03:30
|
|
|
import { NativeEventEmitter } from 'react-native';
|
|
|
|
|
2020-06-04 18:40:44 +01:00
|
|
|
const { NativeModules, Platform } = require('react-native');
|
|
|
|
|
|
|
|
export interface SharedData {
|
2020-11-12 19:29:22 +00:00
|
|
|
title?: string;
|
|
|
|
text?: string;
|
|
|
|
resources?: string[];
|
2020-06-04 18:40:44 +01:00
|
|
|
}
|
|
|
|
|
2023-02-19 21:53:00 +03:30
|
|
|
let eventEmitter: NativeEventEmitter | undefined;
|
|
|
|
|
2021-04-24 10:22:11 +02:00
|
|
|
const ShareExtension = (NativeModules.ShareExtension) ?
|
2020-06-04 18:40:44 +01:00
|
|
|
{
|
|
|
|
data: () => NativeModules.ShareExtension.data(),
|
2023-02-18 20:00:56 +03:30
|
|
|
close: () => NativeModules.ShareExtension.close(),
|
2021-04-24 10:22:11 +02:00
|
|
|
shareURL: (Platform.OS === 'ios') ? NativeModules.ShareExtension.getConstants().SHARE_EXTENSION_SHARE_URL : '',
|
2024-04-05 12:16:49 +01:00
|
|
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- Old code before rule was applied
|
2023-02-19 21:53:00 +03:30
|
|
|
addShareListener: (Platform.OS === 'android') ? ((handler: (event: any)=> void) => {
|
|
|
|
if (!eventEmitter) {
|
|
|
|
eventEmitter = new NativeEventEmitter(NativeModules.ShareExtension);
|
|
|
|
}
|
|
|
|
return eventEmitter.addListener('new_share_intent', handler).remove;
|
|
|
|
}) : (() => {}),
|
2020-06-04 18:40:44 +01:00
|
|
|
} :
|
|
|
|
{
|
|
|
|
data: () => {},
|
|
|
|
close: () => {},
|
2021-04-24 10:22:11 +02:00
|
|
|
shareURL: '',
|
2023-02-19 21:53:00 +03:30
|
|
|
addShareListener: () => {},
|
2020-06-04 18:40:44 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
export default ShareExtension;
|