@rn-bridge-tools/expo 0.0.10 → 0.0.12
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/dist/handlers/device.d.ts.map +1 -1
- package/dist/handlers/share.d.ts.map +1 -1
- package/package.json +4 -4
- package/src/handlers/device.ts +47 -26
- package/src/handlers/share.ts +11 -19
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"device.d.ts","sourceRoot":"","sources":["../../src/handlers/device.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;
|
|
1
|
+
{"version":3,"file":"device.d.ts","sourceRoot":"","sources":["../../src/handlers/device.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AA0B7D,eAAO,MAAM,cAAc;iCAEb,eAAe,CAAC,gBAAgB,CAAC,CAAC,SAAS,CAAC,KACrD,OAAO,CAAC,eAAe,CAAC,gBAAgB,CAAC,CAAC,UAAU,CAAC,CAAC;oCAsB7C,eAAe,CAAC,mBAAmB,CAAC,CAAC,SAAS,CAAC,KACxD,OAAO,CAAC,eAAe,CAAC,mBAAmB,CAAC,CAAC,UAAU,CAAC,CAAC;oCAkBhD,eAAe,CAAC,mBAAmB,CAAC,CAAC,SAAS,CAAC,KACxD,OAAO,CAAC,eAAe,CAAC,mBAAmB,CAAC,CAAC,UAAU,CAAC,CAAC;CAoB7D,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"share.d.ts","sourceRoot":"","sources":["../../src/handlers/share.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;
|
|
1
|
+
{"version":3,"file":"share.d.ts","sourceRoot":"","sources":["../../src/handlers/share.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAG5D,eAAO,MAAM,aAAa;4BAEb,cAAc,CAAC,YAAY,CAAC,CAAC,SAAS,CAAC,KAC/C,OAAO,CAAC,cAAc,CAAC,YAAY,CAAC,CAAC,UAAU,CAAC,CAAC;CAgBrD,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rn-bridge-tools/expo",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.12",
|
|
4
4
|
"description": "Expo/React Native WebView bridge component and handlers for bridge-tools",
|
|
5
5
|
"main": "./src/index.ts",
|
|
6
6
|
"types": "./dist/index.d.ts",
|
|
@@ -15,11 +15,11 @@
|
|
|
15
15
|
"dist"
|
|
16
16
|
],
|
|
17
17
|
"dependencies": {
|
|
18
|
-
"@rn-bridge-tools/core": "0.0.
|
|
18
|
+
"@rn-bridge-tools/core": "0.0.12"
|
|
19
19
|
},
|
|
20
20
|
"peerDependencies": {
|
|
21
21
|
"@react-native-async-storage/async-storage": "*",
|
|
22
|
-
"
|
|
22
|
+
"expo-network": "*",
|
|
23
23
|
"@webview-bridge/react-native": ">=1.0.0",
|
|
24
24
|
"expo-battery": "*",
|
|
25
25
|
"expo-camera": "*",
|
|
@@ -82,7 +82,7 @@
|
|
|
82
82
|
"@react-native-async-storage/async-storage": {
|
|
83
83
|
"optional": true
|
|
84
84
|
},
|
|
85
|
-
"
|
|
85
|
+
"expo-network": {
|
|
86
86
|
"optional": true
|
|
87
87
|
},
|
|
88
88
|
"expo-battery": {
|
package/src/handlers/device.ts
CHANGED
|
@@ -10,6 +10,20 @@ interface DeviceModule {
|
|
|
10
10
|
DeviceType: { TABLET: number };
|
|
11
11
|
}
|
|
12
12
|
|
|
13
|
+
interface BatteryModule {
|
|
14
|
+
getBatteryLevelAsync: () => Promise<number>;
|
|
15
|
+
getBatteryStateAsync: () => Promise<number>;
|
|
16
|
+
BatteryState: { CHARGING: number };
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
interface NetworkModule {
|
|
20
|
+
getNetworkStateAsync: () => Promise<{
|
|
21
|
+
type: string;
|
|
22
|
+
isConnected: boolean;
|
|
23
|
+
isInternetReachable: boolean;
|
|
24
|
+
}>;
|
|
25
|
+
}
|
|
26
|
+
|
|
13
27
|
export const deviceHandlers = {
|
|
14
28
|
'device.getInfo': async (
|
|
15
29
|
_payload: DeviceNamespace['device.getInfo']['request'],
|
|
@@ -18,54 +32,61 @@ export const deviceHandlers = {
|
|
|
18
32
|
try { Device = require('expo-device') as DeviceModule; } catch {}
|
|
19
33
|
if (!Device) return { success: false, error: 'MODULE_NOT_INSTALLED: expo-device' } as never;
|
|
20
34
|
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
35
|
+
try {
|
|
36
|
+
return {
|
|
37
|
+
os: Platform.OS as 'ios' | 'android',
|
|
38
|
+
osVersion: Platform.Version?.toString() ?? '',
|
|
39
|
+
model: Device.modelName ?? '',
|
|
40
|
+
brand: Device.brand ?? '',
|
|
41
|
+
isTablet: Device.deviceType === Device.DeviceType.TABLET,
|
|
42
|
+
appVersion: '1.0.0',
|
|
43
|
+
buildNumber: '1',
|
|
44
|
+
bundleId: '',
|
|
45
|
+
};
|
|
46
|
+
} catch (e) {
|
|
47
|
+
return { success: false, error: String(e) } as never;
|
|
48
|
+
}
|
|
31
49
|
},
|
|
32
50
|
|
|
33
51
|
'device.getBattery': async (
|
|
34
52
|
_payload: DeviceNamespace['device.getBattery']['request'],
|
|
35
53
|
): Promise<DeviceNamespace['device.getBattery']['response']> => {
|
|
54
|
+
let Battery: BatteryModule | null = null;
|
|
55
|
+
try { Battery = require('expo-battery') as BatteryModule; } catch {}
|
|
56
|
+
if (!Battery) return { success: false, error: 'MODULE_NOT_INSTALLED: expo-battery' } as never;
|
|
57
|
+
|
|
36
58
|
try {
|
|
37
|
-
let Battery: { getBatteryLevelAsync: () => Promise<number>; getBatteryStateAsync: () => Promise<number>; BatteryState: { CHARGING: number } } | null = null;
|
|
38
|
-
try { Battery = require('expo-battery') as { getBatteryLevelAsync: () => Promise<number>; getBatteryStateAsync: () => Promise<number>; BatteryState: { CHARGING: number } }; } catch {}
|
|
39
|
-
if (!Battery) {
|
|
40
|
-
return { level: -1, isCharging: false };
|
|
41
|
-
}
|
|
42
59
|
const level = await Battery.getBatteryLevelAsync();
|
|
43
60
|
const state = await Battery.getBatteryStateAsync();
|
|
44
61
|
return {
|
|
45
62
|
level,
|
|
46
63
|
isCharging: state === Battery.BatteryState.CHARGING,
|
|
47
64
|
};
|
|
48
|
-
} catch {
|
|
49
|
-
return {
|
|
65
|
+
} catch (e) {
|
|
66
|
+
return { success: false, error: String(e) } as never;
|
|
50
67
|
}
|
|
51
68
|
},
|
|
52
69
|
|
|
53
70
|
'device.getNetwork': async (
|
|
54
71
|
_payload: DeviceNamespace['device.getNetwork']['request'],
|
|
55
72
|
): Promise<DeviceNamespace['device.getNetwork']['response']> => {
|
|
73
|
+
let Network: NetworkModule | null = null;
|
|
74
|
+
try { Network = require('expo-network') as NetworkModule; } catch {}
|
|
75
|
+
if (!Network) return { success: false, error: 'MODULE_NOT_INSTALLED: expo-network' } as never;
|
|
76
|
+
|
|
56
77
|
try {
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
78
|
+
const state = await Network.getNetworkStateAsync();
|
|
79
|
+
const typeMap: Record<string, 'wifi' | 'cellular' | 'none' | 'unknown'> = {
|
|
80
|
+
WIFI: 'wifi',
|
|
81
|
+
CELLULAR: 'cellular',
|
|
82
|
+
NONE: 'none',
|
|
83
|
+
};
|
|
63
84
|
return {
|
|
64
|
-
type:
|
|
85
|
+
type: typeMap[state.type] ?? 'unknown',
|
|
65
86
|
isConnected: state.isConnected ?? false,
|
|
66
87
|
};
|
|
67
|
-
} catch {
|
|
68
|
-
return {
|
|
88
|
+
} catch (e) {
|
|
89
|
+
return { success: false, error: String(e) } as never;
|
|
69
90
|
}
|
|
70
91
|
},
|
|
71
92
|
};
|
package/src/handlers/share.ts
CHANGED
|
@@ -1,31 +1,23 @@
|
|
|
1
1
|
import type { ShareNamespace } from '@rn-bridge-tools/core';
|
|
2
|
-
|
|
3
|
-
declare const require: (id: string) => unknown;
|
|
4
|
-
|
|
5
|
-
interface SharingModule {
|
|
6
|
-
isAvailableAsync: () => Promise<boolean>;
|
|
7
|
-
shareAsync: (url: string, opts?: { dialogTitle?: string }) => Promise<void>;
|
|
8
|
-
}
|
|
2
|
+
import { Share } from 'react-native';
|
|
9
3
|
|
|
10
4
|
export const shareHandlers = {
|
|
11
5
|
'share.open': async (
|
|
12
6
|
payload: ShareNamespace['share.open']['request'],
|
|
13
7
|
): Promise<ShareNamespace['share.open']['response']> => {
|
|
14
|
-
let Sharing: SharingModule | null = null;
|
|
15
|
-
try { Sharing = require('expo-sharing') as SharingModule; } catch {}
|
|
16
|
-
if (!Sharing) return { success: false, error: 'MODULE_NOT_INSTALLED: expo-sharing' } as never;
|
|
17
|
-
|
|
18
8
|
try {
|
|
19
|
-
const
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
await Sharing.shareAsync(payload.url ?? '', {
|
|
24
|
-
dialogTitle: payload.title,
|
|
9
|
+
const result = await Share.share({
|
|
10
|
+
message: payload.message,
|
|
11
|
+
title: payload.title,
|
|
12
|
+
url: payload.url,
|
|
25
13
|
});
|
|
26
|
-
|
|
27
|
-
|
|
14
|
+
|
|
15
|
+
if (result.action === Share.sharedAction) {
|
|
16
|
+
return { success: true, activityType: result.activityType ?? undefined };
|
|
17
|
+
}
|
|
28
18
|
return { success: false };
|
|
19
|
+
} catch (e) {
|
|
20
|
+
return { success: false, error: String(e) } as never;
|
|
29
21
|
}
|
|
30
22
|
},
|
|
31
23
|
};
|