react-native-advanced-share-intent 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +345 -0
- package/android/build.gradle +37 -0
- package/android/src/main/AndroidManifest.xml +1 -0
- package/android/src/main/java/com/advancedshareintent/AdvancedShareIntentModule.kt +266 -0
- package/android/src/main/java/com/advancedshareintent/AdvancedShareIntentPackage.kt +16 -0
- package/index.d.ts +2 -0
- package/index.js +92 -0
- package/index.mjs +9 -0
- package/ios/AdvancedShareIntent.h +5 -0
- package/ios/AdvancedShareIntent.m +186 -0
- package/ios/ShareExtension/AdvancedShareIntentShareExtension.swift +363 -0
- package/package.json +70 -0
- package/react-native-advanced-share-intent.podspec +18 -0
- package/react-native.config.js +9 -0
- package/src/index.d.ts +44 -0
- package/src/index.ts +134 -0
package/package.json
ADDED
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "react-native-advanced-share-intent",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "Lightweight React Native share intent handling for Android and iOS share extensions.",
|
|
5
|
+
"main": "index.js",
|
|
6
|
+
"module": "index.mjs",
|
|
7
|
+
"types": "index.d.ts",
|
|
8
|
+
"react-native": "src/index.ts",
|
|
9
|
+
"source": "src/index.ts",
|
|
10
|
+
"files": [
|
|
11
|
+
"android/build.gradle",
|
|
12
|
+
"android/src",
|
|
13
|
+
"ios",
|
|
14
|
+
"src",
|
|
15
|
+
"index.d.ts",
|
|
16
|
+
"index.js",
|
|
17
|
+
"index.mjs",
|
|
18
|
+
"react-native.config.js",
|
|
19
|
+
"react-native-advanced-share-intent.podspec",
|
|
20
|
+
"README.md",
|
|
21
|
+
"LICENSE"
|
|
22
|
+
],
|
|
23
|
+
"scripts": {
|
|
24
|
+
"build": "tsc --noEmit",
|
|
25
|
+
"lint": "tsc --noEmit --pretty false",
|
|
26
|
+
"test": "npm run typecheck",
|
|
27
|
+
"typecheck": "tsc --noEmit",
|
|
28
|
+
"prepare": "npm run build",
|
|
29
|
+
"prepack": "npm run build"
|
|
30
|
+
},
|
|
31
|
+
"keywords": [
|
|
32
|
+
"react-native",
|
|
33
|
+
"share",
|
|
34
|
+
"share-intent",
|
|
35
|
+
"android",
|
|
36
|
+
"ios",
|
|
37
|
+
"share-extension",
|
|
38
|
+
"files",
|
|
39
|
+
"mime",
|
|
40
|
+
"typescript",
|
|
41
|
+
"share-sheet"
|
|
42
|
+
],
|
|
43
|
+
"repository": {
|
|
44
|
+
"type": "git",
|
|
45
|
+
"url": "git+https://github.com/engr-touqeer/react-native-advanced-share-intent.git"
|
|
46
|
+
},
|
|
47
|
+
"homepage": "https://github.com/engr-touqeer/react-native-advanced-share-intent#readme",
|
|
48
|
+
"bugs": {
|
|
49
|
+
"url": "https://github.com/engr-touqeer/react-native-advanced-share-intent/issues"
|
|
50
|
+
},
|
|
51
|
+
"author": "Touqeer Ahmed",
|
|
52
|
+
"license": "MIT",
|
|
53
|
+
"peerDependencies": {
|
|
54
|
+
"react": ">=18.2.0",
|
|
55
|
+
"react-native": ">=0.72.0"
|
|
56
|
+
},
|
|
57
|
+
"devDependencies": {
|
|
58
|
+
"@babel/core": "^7.25.2",
|
|
59
|
+
"@types/react": "^19.2.0",
|
|
60
|
+
"react": "19.2.3",
|
|
61
|
+
"react-native": "0.84.1",
|
|
62
|
+
"typescript": "^5.8.3"
|
|
63
|
+
},
|
|
64
|
+
"engines": {
|
|
65
|
+
"node": ">=18"
|
|
66
|
+
},
|
|
67
|
+
"publishConfig": {
|
|
68
|
+
"access": "public"
|
|
69
|
+
}
|
|
70
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
require 'json'
|
|
2
|
+
|
|
3
|
+
package = JSON.parse(File.read(File.join(__dir__, 'package.json')))
|
|
4
|
+
|
|
5
|
+
Pod::Spec.new do |s|
|
|
6
|
+
s.name = 'react-native-advanced-share-intent'
|
|
7
|
+
s.version = package['version']
|
|
8
|
+
s.summary = package['description']
|
|
9
|
+
s.license = package['license']
|
|
10
|
+
s.authors = package['author']
|
|
11
|
+
s.homepage = package['homepage']
|
|
12
|
+
s.source = { :git => package['repository']['url'], :tag => "#{s.version}" }
|
|
13
|
+
s.module_name = 'AdvancedShareIntent'
|
|
14
|
+
s.platforms = { :ios => '13.0' }
|
|
15
|
+
s.source_files = 'ios/**/*.{h,m,mm,swift}'
|
|
16
|
+
s.requires_arc = true
|
|
17
|
+
s.dependency 'React-Core'
|
|
18
|
+
end
|
package/src/index.d.ts
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import type { EmitterSubscription } from 'react-native';
|
|
2
|
+
|
|
3
|
+
export type ShareIntentType = 'text' | 'image' | 'video' | 'document' | 'unknown';
|
|
4
|
+
|
|
5
|
+
export type SharedFile = {
|
|
6
|
+
uri: string;
|
|
7
|
+
fileName?: string;
|
|
8
|
+
name?: string;
|
|
9
|
+
mimeType?: string;
|
|
10
|
+
size?: number;
|
|
11
|
+
type: ShareIntentType;
|
|
12
|
+
dateTaken?: number;
|
|
13
|
+
localIdentifier?: string;
|
|
14
|
+
originalUri?: string;
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
export type ShareIntentPayload = {
|
|
18
|
+
text?: string;
|
|
19
|
+
subject?: string;
|
|
20
|
+
title?: string;
|
|
21
|
+
mimeType?: string;
|
|
22
|
+
files: SharedFile[];
|
|
23
|
+
webUrl?: string;
|
|
24
|
+
isInitial: boolean;
|
|
25
|
+
receivedAt: number;
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
export type ShareIntentListener = (payload: ShareIntentPayload) => void;
|
|
29
|
+
|
|
30
|
+
declare const ShareIntent: {
|
|
31
|
+
getInitialShare(): Promise<ShareIntentPayload | null>;
|
|
32
|
+
addShareListener(listener: ShareIntentListener): EmitterSubscription;
|
|
33
|
+
clearSharedData(): Promise<void>;
|
|
34
|
+
setAppGroupIdentifier(identifier: string): Promise<void>;
|
|
35
|
+
setContainingAppScheme(scheme: string): Promise<void>;
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
export declare const getInitialShare: typeof ShareIntent.getInitialShare;
|
|
39
|
+
export declare const addShareListener: typeof ShareIntent.addShareListener;
|
|
40
|
+
export declare const clearSharedData: typeof ShareIntent.clearSharedData;
|
|
41
|
+
export declare const setAppGroupIdentifier: typeof ShareIntent.setAppGroupIdentifier;
|
|
42
|
+
export declare const setContainingAppScheme: typeof ShareIntent.setContainingAppScheme;
|
|
43
|
+
|
|
44
|
+
export default ShareIntent;
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
import {
|
|
2
|
+
NativeEventEmitter,
|
|
3
|
+
NativeModules,
|
|
4
|
+
Platform,
|
|
5
|
+
type EmitterSubscription,
|
|
6
|
+
} from 'react-native';
|
|
7
|
+
|
|
8
|
+
type NativeShareIntentModule = {
|
|
9
|
+
getInitialShare(): Promise<ShareIntentPayload | null>;
|
|
10
|
+
clearSharedData(): Promise<void>;
|
|
11
|
+
setAppGroupIdentifier?(identifier: string): Promise<void>;
|
|
12
|
+
setContainingAppScheme?(scheme: string): Promise<void>;
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
export type ShareIntentType = 'text' | 'image' | 'video' | 'document' | 'unknown';
|
|
16
|
+
|
|
17
|
+
export type SharedFile = {
|
|
18
|
+
uri: string;
|
|
19
|
+
fileName?: string;
|
|
20
|
+
name?: string;
|
|
21
|
+
mimeType?: string;
|
|
22
|
+
size?: number;
|
|
23
|
+
type: ShareIntentType;
|
|
24
|
+
dateTaken?: number;
|
|
25
|
+
localIdentifier?: string;
|
|
26
|
+
originalUri?: string;
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
export type ShareIntentPayload = {
|
|
30
|
+
text?: string;
|
|
31
|
+
subject?: string;
|
|
32
|
+
title?: string;
|
|
33
|
+
mimeType?: string;
|
|
34
|
+
files: SharedFile[];
|
|
35
|
+
webUrl?: string;
|
|
36
|
+
isInitial: boolean;
|
|
37
|
+
receivedAt: number;
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
export type ShareIntentListener = (payload: ShareIntentPayload) => void;
|
|
41
|
+
|
|
42
|
+
const LINKING_ERROR =
|
|
43
|
+
'react-native-advanced-share-intent is not linked. Rebuild the native app after installing the package.';
|
|
44
|
+
|
|
45
|
+
const NativeAdvancedShareIntent =
|
|
46
|
+
NativeModules.AdvancedShareIntent as NativeShareIntentModule | undefined;
|
|
47
|
+
|
|
48
|
+
const nativeModule = new Proxy({} as NativeShareIntentModule, {
|
|
49
|
+
get(_target, property: keyof NativeShareIntentModule) {
|
|
50
|
+
if (!NativeAdvancedShareIntent) {
|
|
51
|
+
throw new Error(LINKING_ERROR);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
const value = NativeAdvancedShareIntent[property];
|
|
55
|
+
if (typeof value === 'function') {
|
|
56
|
+
return value.bind(NativeAdvancedShareIntent);
|
|
57
|
+
}
|
|
58
|
+
return value;
|
|
59
|
+
},
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
const emitter = NativeAdvancedShareIntent
|
|
63
|
+
? new NativeEventEmitter(NativeAdvancedShareIntent as any)
|
|
64
|
+
: null;
|
|
65
|
+
|
|
66
|
+
const EVENT_NAME = 'AdvancedShareIntentReceived';
|
|
67
|
+
|
|
68
|
+
function normalizePayload(payload: ShareIntentPayload | null): ShareIntentPayload | null {
|
|
69
|
+
if (!payload) {
|
|
70
|
+
return null;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
return {
|
|
74
|
+
...payload,
|
|
75
|
+
files: Array.isArray(payload.files) ? payload.files : [],
|
|
76
|
+
receivedAt: payload.receivedAt ?? Date.now(),
|
|
77
|
+
isInitial: Boolean(payload.isInitial),
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
const ShareIntent = {
|
|
82
|
+
async getInitialShare(): Promise<ShareIntentPayload | null> {
|
|
83
|
+
return normalizePayload(await nativeModule.getInitialShare());
|
|
84
|
+
},
|
|
85
|
+
|
|
86
|
+
addShareListener(listener: ShareIntentListener): EmitterSubscription {
|
|
87
|
+
if (!emitter) {
|
|
88
|
+
throw new Error(LINKING_ERROR);
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
return emitter.addListener(EVENT_NAME, (payload: ShareIntentPayload) => {
|
|
92
|
+
const normalizedPayload = normalizePayload(payload);
|
|
93
|
+
if (normalizedPayload) {
|
|
94
|
+
listener(normalizedPayload);
|
|
95
|
+
}
|
|
96
|
+
});
|
|
97
|
+
},
|
|
98
|
+
|
|
99
|
+
async clearSharedData(): Promise<void> {
|
|
100
|
+
await nativeModule.clearSharedData();
|
|
101
|
+
},
|
|
102
|
+
|
|
103
|
+
async setAppGroupIdentifier(identifier: string): Promise<void> {
|
|
104
|
+
if (Platform.OS !== 'ios') {
|
|
105
|
+
return;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
if (!nativeModule.setAppGroupIdentifier) {
|
|
109
|
+
throw new Error('setAppGroupIdentifier is not available on this platform.');
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
await nativeModule.setAppGroupIdentifier(identifier);
|
|
113
|
+
},
|
|
114
|
+
|
|
115
|
+
async setContainingAppScheme(scheme: string): Promise<void> {
|
|
116
|
+
if (Platform.OS !== 'ios') {
|
|
117
|
+
return;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
if (!nativeModule.setContainingAppScheme) {
|
|
121
|
+
throw new Error('setContainingAppScheme is not available on this platform.');
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
await nativeModule.setContainingAppScheme(scheme);
|
|
125
|
+
},
|
|
126
|
+
};
|
|
127
|
+
|
|
128
|
+
export const getInitialShare = ShareIntent.getInitialShare;
|
|
129
|
+
export const addShareListener = ShareIntent.addShareListener;
|
|
130
|
+
export const clearSharedData = ShareIntent.clearSharedData;
|
|
131
|
+
export const setAppGroupIdentifier = ShareIntent.setAppGroupIdentifier;
|
|
132
|
+
export const setContainingAppScheme = ShareIntent.setContainingAppScheme;
|
|
133
|
+
|
|
134
|
+
export default ShareIntent;
|