1
0
mirror of https://github.com/laurent22/joplin.git synced 2024-12-18 09:35:20 +02:00
joplin/packages/app-mobile/utils/ShareExtension.ts

34 lines
1.0 KiB
TypeScript
Raw Normal View History

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