@rn-bridge-tools/expo 0.0.1
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/index.cjs +741 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +113 -0
- package/dist/index.d.ts +113 -0
- package/dist/index.js +696 -0
- package/dist/index.js.map +1 -0
- package/package.json +108 -0
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,741 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/index.ts
|
|
21
|
+
var index_exports = {};
|
|
22
|
+
__export(index_exports, {
|
|
23
|
+
WebViewBridge: () => WebViewBridge,
|
|
24
|
+
authHandlers: () => authHandlers,
|
|
25
|
+
browserHandlers: () => browserHandlers,
|
|
26
|
+
cameraHandlers: () => cameraHandlers,
|
|
27
|
+
clipboardHandlers: () => clipboardHandlers,
|
|
28
|
+
createDefaultHandlers: () => createDefaultHandlers,
|
|
29
|
+
deviceHandlers: () => deviceHandlers,
|
|
30
|
+
fileHandlers: () => fileHandlers,
|
|
31
|
+
hapticHandlers: () => hapticHandlers,
|
|
32
|
+
iapHandlers: () => iapHandlers,
|
|
33
|
+
keyboardHandlers: () => keyboardHandlers,
|
|
34
|
+
locationHandlers: () => locationHandlers,
|
|
35
|
+
navigationHandlers: () => navigationHandlers,
|
|
36
|
+
permissionHandlers: () => permissionHandlers,
|
|
37
|
+
preferenceHandlers: () => preferenceHandlers,
|
|
38
|
+
pushHandlers: () => pushHandlers,
|
|
39
|
+
scannerHandlers: () => scannerHandlers,
|
|
40
|
+
shareHandlers: () => shareHandlers,
|
|
41
|
+
statusbarHandlers: () => statusbarHandlers
|
|
42
|
+
});
|
|
43
|
+
module.exports = __toCommonJS(index_exports);
|
|
44
|
+
|
|
45
|
+
// src/WebViewBridge.tsx
|
|
46
|
+
var import_react = require("react");
|
|
47
|
+
var import_react_native = require("@webview-bridge/react-native");
|
|
48
|
+
var import_jsx_runtime = require("react/jsx-runtime");
|
|
49
|
+
var WebViewBridge = (0, import_react.forwardRef)(
|
|
50
|
+
function WebViewBridge2({ handlers, customHandlers, ...webViewProps }, ref) {
|
|
51
|
+
const handlersRef = (0, import_react.useRef)(handlers);
|
|
52
|
+
const customRef = (0, import_react.useRef)(customHandlers);
|
|
53
|
+
const { InternalWebView, postMessage } = (0, import_react.useMemo)(() => {
|
|
54
|
+
const allHandlers = {};
|
|
55
|
+
const mergedHandlers = { ...handlersRef.current, ...customRef.current };
|
|
56
|
+
for (const [key, handler] of Object.entries(mergedHandlers)) {
|
|
57
|
+
if (handler) {
|
|
58
|
+
allHandlers[key] = async (...args) => {
|
|
59
|
+
const payload = args[0] ?? {};
|
|
60
|
+
return handler(payload);
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
const appBridge = (0, import_react_native.bridge)(allHandlers);
|
|
65
|
+
const result = (0, import_react_native.createWebView)({
|
|
66
|
+
bridge: appBridge,
|
|
67
|
+
debug: __DEV__ ?? false
|
|
68
|
+
});
|
|
69
|
+
return { InternalWebView: result.WebView, postMessage: result.postMessage };
|
|
70
|
+
}, []);
|
|
71
|
+
(0, import_react.useImperativeHandle)(
|
|
72
|
+
ref,
|
|
73
|
+
() => ({
|
|
74
|
+
emit: (event, data) => {
|
|
75
|
+
postMessage(event, data);
|
|
76
|
+
}
|
|
77
|
+
}),
|
|
78
|
+
[postMessage]
|
|
79
|
+
);
|
|
80
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(InternalWebView, { ...webViewProps });
|
|
81
|
+
}
|
|
82
|
+
);
|
|
83
|
+
|
|
84
|
+
// src/handlers/camera.ts
|
|
85
|
+
var import_core = require("@rn-bridge-tools/core");
|
|
86
|
+
var cameraHandlers = {
|
|
87
|
+
"camera.take": async (payload) => {
|
|
88
|
+
const ImagePicker = await (0, import_core.tryImport)("expo-image-picker");
|
|
89
|
+
if (!ImagePicker) return (0, import_core.moduleNotInstalledError)("expo-image-picker");
|
|
90
|
+
const result = await ImagePicker.launchCameraAsync({
|
|
91
|
+
quality: payload.quality ?? 0.8,
|
|
92
|
+
cameraType: payload.facing === "front" ? ImagePicker.CameraType.front : ImagePicker.CameraType.back,
|
|
93
|
+
allowsEditing: payload.allowsEditing ?? false
|
|
94
|
+
});
|
|
95
|
+
if (result.canceled) {
|
|
96
|
+
return { success: false, assets: [] };
|
|
97
|
+
}
|
|
98
|
+
const asset = result.assets[0];
|
|
99
|
+
return {
|
|
100
|
+
success: true,
|
|
101
|
+
uri: asset.uri,
|
|
102
|
+
width: asset.width,
|
|
103
|
+
height: asset.height,
|
|
104
|
+
fileSize: asset.fileSize,
|
|
105
|
+
mimeType: asset.mimeType ?? void 0
|
|
106
|
+
};
|
|
107
|
+
},
|
|
108
|
+
"camera.pickImage": async (payload) => {
|
|
109
|
+
const ImagePicker = await (0, import_core.tryImport)("expo-image-picker");
|
|
110
|
+
if (!ImagePicker) return (0, import_core.moduleNotInstalledError)("expo-image-picker");
|
|
111
|
+
const result = await ImagePicker.launchImageLibraryAsync({
|
|
112
|
+
allowsMultipleSelection: payload.allowsMultipleSelection ?? false,
|
|
113
|
+
quality: payload.quality ?? 0.8,
|
|
114
|
+
selectionLimit: payload.maxCount ?? 0
|
|
115
|
+
});
|
|
116
|
+
if (result.canceled) {
|
|
117
|
+
return { success: false, assets: [] };
|
|
118
|
+
}
|
|
119
|
+
return {
|
|
120
|
+
success: true,
|
|
121
|
+
assets: result.assets.map((a) => ({
|
|
122
|
+
uri: a.uri,
|
|
123
|
+
width: a.width,
|
|
124
|
+
height: a.height,
|
|
125
|
+
fileSize: a.fileSize,
|
|
126
|
+
mimeType: a.mimeType ?? void 0
|
|
127
|
+
}))
|
|
128
|
+
};
|
|
129
|
+
}
|
|
130
|
+
};
|
|
131
|
+
|
|
132
|
+
// src/handlers/location.ts
|
|
133
|
+
var import_core2 = require("@rn-bridge-tools/core");
|
|
134
|
+
var watchSubscriptions = /* @__PURE__ */ new Map();
|
|
135
|
+
var watchCounter = 0;
|
|
136
|
+
var locationHandlers = {
|
|
137
|
+
"location.getCurrent": async (payload) => {
|
|
138
|
+
const Location = await (0, import_core2.tryImport)("expo-location");
|
|
139
|
+
if (!Location) return (0, import_core2.moduleNotInstalledError)("expo-location");
|
|
140
|
+
const accuracyMap = {
|
|
141
|
+
lowest: Location.Accuracy.Lowest,
|
|
142
|
+
low: Location.Accuracy.Low,
|
|
143
|
+
balanced: Location.Accuracy.Balanced,
|
|
144
|
+
high: Location.Accuracy.High,
|
|
145
|
+
highest: Location.Accuracy.Highest
|
|
146
|
+
};
|
|
147
|
+
const result = await Location.getCurrentPositionAsync({
|
|
148
|
+
accuracy: accuracyMap[payload.accuracy ?? "balanced"] ?? Location.Accuracy.Balanced
|
|
149
|
+
});
|
|
150
|
+
return {
|
|
151
|
+
lat: result.coords.latitude,
|
|
152
|
+
lng: result.coords.longitude,
|
|
153
|
+
altitude: result.coords.altitude ?? void 0,
|
|
154
|
+
accuracy: result.coords.accuracy ?? void 0,
|
|
155
|
+
timestamp: result.timestamp
|
|
156
|
+
};
|
|
157
|
+
},
|
|
158
|
+
"location.watchStart": async (payload) => {
|
|
159
|
+
const Location = await (0, import_core2.tryImport)("expo-location");
|
|
160
|
+
if (!Location) return (0, import_core2.moduleNotInstalledError)("expo-location");
|
|
161
|
+
watchCounter += 1;
|
|
162
|
+
const watchId = `watch_${watchCounter}`;
|
|
163
|
+
const accuracyMap = {
|
|
164
|
+
low: Location.Accuracy.Low,
|
|
165
|
+
balanced: Location.Accuracy.Balanced,
|
|
166
|
+
high: Location.Accuracy.High
|
|
167
|
+
};
|
|
168
|
+
const subscription = await Location.watchPositionAsync(
|
|
169
|
+
{
|
|
170
|
+
accuracy: accuracyMap[payload.accuracy ?? "balanced"] ?? Location.Accuracy.Balanced,
|
|
171
|
+
distanceInterval: payload.distanceInterval,
|
|
172
|
+
timeInterval: payload.timeInterval
|
|
173
|
+
},
|
|
174
|
+
(_location) => {
|
|
175
|
+
}
|
|
176
|
+
);
|
|
177
|
+
watchSubscriptions.set(watchId, subscription);
|
|
178
|
+
return { watchId };
|
|
179
|
+
},
|
|
180
|
+
"location.watchStop": async (payload) => {
|
|
181
|
+
const subscription = watchSubscriptions.get(payload.watchId);
|
|
182
|
+
if (subscription) {
|
|
183
|
+
subscription.remove();
|
|
184
|
+
watchSubscriptions.delete(payload.watchId);
|
|
185
|
+
return { success: true };
|
|
186
|
+
}
|
|
187
|
+
return { success: false };
|
|
188
|
+
}
|
|
189
|
+
};
|
|
190
|
+
|
|
191
|
+
// src/handlers/file.ts
|
|
192
|
+
var import_core3 = require("@rn-bridge-tools/core");
|
|
193
|
+
var fileHandlers = {
|
|
194
|
+
"file.download": async (payload) => {
|
|
195
|
+
const FS = await (0, import_core3.tryImport)("expo-file-system");
|
|
196
|
+
if (!FS) return (0, import_core3.moduleNotInstalledError)("expo-file-system");
|
|
197
|
+
try {
|
|
198
|
+
const response = await fetch(payload.url);
|
|
199
|
+
const text = await response.text();
|
|
200
|
+
const file = new FS.File(FS.Paths.document, payload.filename);
|
|
201
|
+
file.write(text);
|
|
202
|
+
return { success: true, localUri: file.uri };
|
|
203
|
+
} catch (err) {
|
|
204
|
+
return { success: false, error: String(err) };
|
|
205
|
+
}
|
|
206
|
+
},
|
|
207
|
+
"file.read": async (payload) => {
|
|
208
|
+
const FS = await (0, import_core3.tryImport)("expo-file-system");
|
|
209
|
+
if (!FS) return (0, import_core3.moduleNotInstalledError)("expo-file-system");
|
|
210
|
+
try {
|
|
211
|
+
const file = new FS.File(payload.uri);
|
|
212
|
+
const content = await file.text();
|
|
213
|
+
return { success: true, content };
|
|
214
|
+
} catch (err) {
|
|
215
|
+
return { success: false, error: String(err) };
|
|
216
|
+
}
|
|
217
|
+
},
|
|
218
|
+
"file.write": async (payload) => {
|
|
219
|
+
const FS = await (0, import_core3.tryImport)("expo-file-system");
|
|
220
|
+
if (!FS) return (0, import_core3.moduleNotInstalledError)("expo-file-system");
|
|
221
|
+
try {
|
|
222
|
+
const dirMap = {
|
|
223
|
+
document: FS.Paths.document,
|
|
224
|
+
cache: FS.Paths.cache,
|
|
225
|
+
temp: FS.Paths.cache
|
|
226
|
+
};
|
|
227
|
+
const baseDir = dirMap[payload.directory ?? "document"];
|
|
228
|
+
const file = new FS.File(baseDir, payload.filename);
|
|
229
|
+
file.write(payload.content);
|
|
230
|
+
return { success: true, uri: file.uri };
|
|
231
|
+
} catch (err) {
|
|
232
|
+
return { success: false, error: String(err) };
|
|
233
|
+
}
|
|
234
|
+
},
|
|
235
|
+
"file.pick": async (payload) => {
|
|
236
|
+
const DocumentPicker = await (0, import_core3.tryImport)("expo-document-picker");
|
|
237
|
+
if (!DocumentPicker) return (0, import_core3.moduleNotInstalledError)("expo-document-picker");
|
|
238
|
+
try {
|
|
239
|
+
const result = await DocumentPicker.getDocumentAsync({
|
|
240
|
+
type: payload.type ?? ["*/*"],
|
|
241
|
+
multiple: payload.multiple ?? false
|
|
242
|
+
});
|
|
243
|
+
if (result.canceled) {
|
|
244
|
+
return { success: false, files: [] };
|
|
245
|
+
}
|
|
246
|
+
return {
|
|
247
|
+
success: true,
|
|
248
|
+
files: result.assets.map((a) => ({
|
|
249
|
+
uri: a.uri,
|
|
250
|
+
name: a.name,
|
|
251
|
+
size: a.size ?? 0,
|
|
252
|
+
mimeType: a.mimeType ?? "application/octet-stream"
|
|
253
|
+
}))
|
|
254
|
+
};
|
|
255
|
+
} catch {
|
|
256
|
+
return { success: false, files: [] };
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
};
|
|
260
|
+
|
|
261
|
+
// src/handlers/share.ts
|
|
262
|
+
var import_core4 = require("@rn-bridge-tools/core");
|
|
263
|
+
var shareHandlers = {
|
|
264
|
+
"share.open": async (payload) => {
|
|
265
|
+
const Sharing = await (0, import_core4.tryImport)("expo-sharing");
|
|
266
|
+
if (!Sharing) return (0, import_core4.moduleNotInstalledError)("expo-sharing");
|
|
267
|
+
try {
|
|
268
|
+
const isAvailable = await Sharing.isAvailableAsync();
|
|
269
|
+
if (!isAvailable) {
|
|
270
|
+
return { success: false };
|
|
271
|
+
}
|
|
272
|
+
await Sharing.shareAsync(payload.url ?? "", {
|
|
273
|
+
dialogTitle: payload.title
|
|
274
|
+
});
|
|
275
|
+
return { success: true };
|
|
276
|
+
} catch {
|
|
277
|
+
return { success: false };
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
};
|
|
281
|
+
|
|
282
|
+
// src/handlers/device.ts
|
|
283
|
+
var import_core5 = require("@rn-bridge-tools/core");
|
|
284
|
+
var import_react_native2 = require("react-native");
|
|
285
|
+
var deviceHandlers = {
|
|
286
|
+
"device.getInfo": async (_payload) => {
|
|
287
|
+
const Device = await (0, import_core5.tryImport)("expo-device");
|
|
288
|
+
if (!Device) return (0, import_core5.moduleNotInstalledError)("expo-device");
|
|
289
|
+
return {
|
|
290
|
+
os: import_react_native2.Platform.OS,
|
|
291
|
+
osVersion: import_react_native2.Platform.Version?.toString() ?? "",
|
|
292
|
+
model: Device.modelName ?? "",
|
|
293
|
+
brand: Device.brand ?? "",
|
|
294
|
+
isTablet: Device.deviceType === Device.DeviceType.TABLET,
|
|
295
|
+
appVersion: "1.0.0",
|
|
296
|
+
buildNumber: "1",
|
|
297
|
+
bundleId: ""
|
|
298
|
+
};
|
|
299
|
+
},
|
|
300
|
+
"device.getBattery": async (_payload) => {
|
|
301
|
+
try {
|
|
302
|
+
const Battery = await (0, import_core5.tryImport)("expo-battery");
|
|
303
|
+
if (!Battery) {
|
|
304
|
+
return { level: -1, isCharging: false };
|
|
305
|
+
}
|
|
306
|
+
const level = await Battery.getBatteryLevelAsync();
|
|
307
|
+
const state = await Battery.getBatteryStateAsync();
|
|
308
|
+
return {
|
|
309
|
+
level,
|
|
310
|
+
isCharging: state === Battery.BatteryState.CHARGING
|
|
311
|
+
};
|
|
312
|
+
} catch {
|
|
313
|
+
return { level: -1, isCharging: false };
|
|
314
|
+
}
|
|
315
|
+
},
|
|
316
|
+
"device.getNetwork": async (_payload) => {
|
|
317
|
+
try {
|
|
318
|
+
const NetInfo = await (0, import_core5.tryImport)("@react-native-community/netinfo");
|
|
319
|
+
if (!NetInfo) {
|
|
320
|
+
return { type: "unknown", isConnected: true };
|
|
321
|
+
}
|
|
322
|
+
const state = await NetInfo.fetch();
|
|
323
|
+
return {
|
|
324
|
+
type: state.type ?? "unknown",
|
|
325
|
+
isConnected: state.isConnected ?? false
|
|
326
|
+
};
|
|
327
|
+
} catch {
|
|
328
|
+
return { type: "unknown", isConnected: true };
|
|
329
|
+
}
|
|
330
|
+
}
|
|
331
|
+
};
|
|
332
|
+
|
|
333
|
+
// src/handlers/statusbar.ts
|
|
334
|
+
var import_react_native3 = require("react-native");
|
|
335
|
+
var statusbarHandlers = {
|
|
336
|
+
"statusbar.setStyle": async (payload) => {
|
|
337
|
+
const styleMap = {
|
|
338
|
+
light: "light-content",
|
|
339
|
+
dark: "dark-content",
|
|
340
|
+
auto: "default"
|
|
341
|
+
};
|
|
342
|
+
import_react_native3.StatusBar.setBarStyle(styleMap[payload.style] ?? "default");
|
|
343
|
+
return { success: true };
|
|
344
|
+
},
|
|
345
|
+
"statusbar.setBackgroundColor": async (payload) => {
|
|
346
|
+
import_react_native3.StatusBar.setBackgroundColor(payload.color, payload.animated ?? false);
|
|
347
|
+
return { success: true };
|
|
348
|
+
},
|
|
349
|
+
"statusbar.setHidden": async (payload) => {
|
|
350
|
+
const animationMap = {
|
|
351
|
+
fade: "fade",
|
|
352
|
+
slide: "slide",
|
|
353
|
+
none: "none"
|
|
354
|
+
};
|
|
355
|
+
import_react_native3.StatusBar.setHidden(payload.hidden, animationMap[payload.animation ?? "none"]);
|
|
356
|
+
return { success: true };
|
|
357
|
+
}
|
|
358
|
+
};
|
|
359
|
+
|
|
360
|
+
// src/handlers/keyboard.ts
|
|
361
|
+
var import_react_native4 = require("react-native");
|
|
362
|
+
var keyboardHandlers = {
|
|
363
|
+
"keyboard.dismiss": async (_payload) => {
|
|
364
|
+
import_react_native4.Keyboard.dismiss();
|
|
365
|
+
return { success: true };
|
|
366
|
+
},
|
|
367
|
+
"keyboard.getState": async (_payload) => {
|
|
368
|
+
return {
|
|
369
|
+
visible: false,
|
|
370
|
+
height: 0
|
|
371
|
+
};
|
|
372
|
+
}
|
|
373
|
+
};
|
|
374
|
+
|
|
375
|
+
// src/handlers/haptic.ts
|
|
376
|
+
var import_core6 = require("@rn-bridge-tools/core");
|
|
377
|
+
var hapticHandlers = {
|
|
378
|
+
"haptic.impact": async (payload) => {
|
|
379
|
+
const Haptics = await (0, import_core6.tryImport)("expo-haptics");
|
|
380
|
+
if (!Haptics) {
|
|
381
|
+
(0, import_core6.moduleNotInstalledError)("expo-haptics");
|
|
382
|
+
return;
|
|
383
|
+
}
|
|
384
|
+
const styleMap = {
|
|
385
|
+
light: Haptics.ImpactFeedbackStyle.Light,
|
|
386
|
+
medium: Haptics.ImpactFeedbackStyle.Medium,
|
|
387
|
+
heavy: Haptics.ImpactFeedbackStyle.Heavy
|
|
388
|
+
};
|
|
389
|
+
await Haptics.impactAsync(styleMap[payload.style]);
|
|
390
|
+
},
|
|
391
|
+
"haptic.notification": async (payload) => {
|
|
392
|
+
const Haptics = await (0, import_core6.tryImport)("expo-haptics");
|
|
393
|
+
if (!Haptics) {
|
|
394
|
+
(0, import_core6.moduleNotInstalledError)("expo-haptics");
|
|
395
|
+
return;
|
|
396
|
+
}
|
|
397
|
+
const typeMap = {
|
|
398
|
+
success: Haptics.NotificationFeedbackType.Success,
|
|
399
|
+
warning: Haptics.NotificationFeedbackType.Warning,
|
|
400
|
+
error: Haptics.NotificationFeedbackType.Error
|
|
401
|
+
};
|
|
402
|
+
await Haptics.notificationAsync(typeMap[payload.type]);
|
|
403
|
+
},
|
|
404
|
+
"haptic.selection": async () => {
|
|
405
|
+
const Haptics = await (0, import_core6.tryImport)("expo-haptics");
|
|
406
|
+
if (!Haptics) {
|
|
407
|
+
(0, import_core6.moduleNotInstalledError)("expo-haptics");
|
|
408
|
+
return;
|
|
409
|
+
}
|
|
410
|
+
await Haptics.selectionAsync();
|
|
411
|
+
}
|
|
412
|
+
};
|
|
413
|
+
|
|
414
|
+
// src/handlers/clipboard.ts
|
|
415
|
+
var import_core7 = require("@rn-bridge-tools/core");
|
|
416
|
+
var clipboardHandlers = {
|
|
417
|
+
"clipboard.copy": async (payload) => {
|
|
418
|
+
const Clipboard = await (0, import_core7.tryImport)("expo-clipboard");
|
|
419
|
+
if (!Clipboard) return (0, import_core7.moduleNotInstalledError)("expo-clipboard");
|
|
420
|
+
await Clipboard.setStringAsync(payload.text);
|
|
421
|
+
return { success: true };
|
|
422
|
+
},
|
|
423
|
+
"clipboard.paste": async (_payload) => {
|
|
424
|
+
const Clipboard = await (0, import_core7.tryImport)("expo-clipboard");
|
|
425
|
+
if (!Clipboard) return (0, import_core7.moduleNotInstalledError)("expo-clipboard");
|
|
426
|
+
const text = await Clipboard.getStringAsync();
|
|
427
|
+
return { text, hasContent: text.length > 0 };
|
|
428
|
+
}
|
|
429
|
+
};
|
|
430
|
+
|
|
431
|
+
// src/handlers/scanner.ts
|
|
432
|
+
var import_core8 = require("@rn-bridge-tools/core");
|
|
433
|
+
var scannerHandlers = {
|
|
434
|
+
"scanner.scanQR": async (_payload) => {
|
|
435
|
+
const Camera = await (0, import_core8.tryImport)("expo-camera");
|
|
436
|
+
if (!Camera) return (0, import_core8.moduleNotInstalledError)("expo-camera");
|
|
437
|
+
try {
|
|
438
|
+
const { status } = await Camera.Camera.requestCameraPermissionsAsync();
|
|
439
|
+
if (status !== "granted") {
|
|
440
|
+
return { success: false, cancelled: true };
|
|
441
|
+
}
|
|
442
|
+
return { success: false, error: "Use Camera component for QR scanning" };
|
|
443
|
+
} catch {
|
|
444
|
+
return { success: false };
|
|
445
|
+
}
|
|
446
|
+
}
|
|
447
|
+
};
|
|
448
|
+
|
|
449
|
+
// src/handlers/auth.ts
|
|
450
|
+
var import_core9 = require("@rn-bridge-tools/core");
|
|
451
|
+
var authHandlers = {
|
|
452
|
+
"auth.biometric": async (payload) => {
|
|
453
|
+
const LocalAuth = await (0, import_core9.tryImport)("expo-local-authentication");
|
|
454
|
+
if (!LocalAuth) return (0, import_core9.moduleNotInstalledError)("expo-local-authentication");
|
|
455
|
+
try {
|
|
456
|
+
const result = await LocalAuth.authenticateAsync({
|
|
457
|
+
promptMessage: payload.promptMessage ?? "Authenticate",
|
|
458
|
+
cancelLabel: payload.cancelLabel,
|
|
459
|
+
fallbackLabel: payload.fallbackLabel
|
|
460
|
+
});
|
|
461
|
+
if (result.success) {
|
|
462
|
+
return { success: true };
|
|
463
|
+
}
|
|
464
|
+
return { success: false, error: result.error };
|
|
465
|
+
} catch (err) {
|
|
466
|
+
return { success: false, error: String(err) };
|
|
467
|
+
}
|
|
468
|
+
},
|
|
469
|
+
"auth.isBiometricAvailable": async (_payload) => {
|
|
470
|
+
const LocalAuth = await (0, import_core9.tryImport)("expo-local-authentication");
|
|
471
|
+
if (!LocalAuth) return (0, import_core9.moduleNotInstalledError)("expo-local-authentication");
|
|
472
|
+
try {
|
|
473
|
+
const available = await LocalAuth.hasHardwareAsync();
|
|
474
|
+
const types = await LocalAuth.supportedAuthenticationTypesAsync();
|
|
475
|
+
let biometryType;
|
|
476
|
+
if (types.includes(LocalAuth.AuthenticationType.FACIAL_RECOGNITION)) {
|
|
477
|
+
biometryType = "facial";
|
|
478
|
+
} else if (types.includes(LocalAuth.AuthenticationType.FINGERPRINT)) {
|
|
479
|
+
biometryType = "fingerprint";
|
|
480
|
+
} else if (types.includes(LocalAuth.AuthenticationType.IRIS)) {
|
|
481
|
+
biometryType = "iris";
|
|
482
|
+
}
|
|
483
|
+
return { available, biometryType };
|
|
484
|
+
} catch {
|
|
485
|
+
return { available: false };
|
|
486
|
+
}
|
|
487
|
+
}
|
|
488
|
+
};
|
|
489
|
+
|
|
490
|
+
// src/handlers/iap.ts
|
|
491
|
+
var iapHandlers = {
|
|
492
|
+
"iap.getProducts": async (_payload) => {
|
|
493
|
+
return { products: [] };
|
|
494
|
+
},
|
|
495
|
+
"iap.purchase": async (_payload) => {
|
|
496
|
+
return { success: false, error: "IAP not configured" };
|
|
497
|
+
},
|
|
498
|
+
"iap.restore": async (_payload) => {
|
|
499
|
+
return { purchases: [] };
|
|
500
|
+
}
|
|
501
|
+
};
|
|
502
|
+
|
|
503
|
+
// src/handlers/push.ts
|
|
504
|
+
var import_core10 = require("@rn-bridge-tools/core");
|
|
505
|
+
var import_react_native5 = require("react-native");
|
|
506
|
+
var pushHandlers = {
|
|
507
|
+
"push.getToken": async (_payload) => {
|
|
508
|
+
const Notifications = await (0, import_core10.tryImport)("expo-notifications");
|
|
509
|
+
if (!Notifications) return (0, import_core10.moduleNotInstalledError)("expo-notifications");
|
|
510
|
+
try {
|
|
511
|
+
const token = await Notifications.getExpoPushTokenAsync();
|
|
512
|
+
return {
|
|
513
|
+
token: token.data,
|
|
514
|
+
platform: import_react_native5.Platform.OS === "ios" ? "apns" : "fcm"
|
|
515
|
+
};
|
|
516
|
+
} catch {
|
|
517
|
+
return { token: "", platform: import_react_native5.Platform.OS === "ios" ? "apns" : "fcm" };
|
|
518
|
+
}
|
|
519
|
+
},
|
|
520
|
+
"push.requestPermission": async (_payload) => {
|
|
521
|
+
const Notifications = await (0, import_core10.tryImport)("expo-notifications");
|
|
522
|
+
if (!Notifications) return (0, import_core10.moduleNotInstalledError)("expo-notifications");
|
|
523
|
+
try {
|
|
524
|
+
const { status } = await Notifications.requestPermissionsAsync();
|
|
525
|
+
return {
|
|
526
|
+
granted: status === "granted",
|
|
527
|
+
status
|
|
528
|
+
};
|
|
529
|
+
} catch {
|
|
530
|
+
return { granted: false, status: "denied" };
|
|
531
|
+
}
|
|
532
|
+
}
|
|
533
|
+
};
|
|
534
|
+
|
|
535
|
+
// src/handlers/permission.ts
|
|
536
|
+
var import_react_native6 = require("react-native");
|
|
537
|
+
var import_core11 = require("@rn-bridge-tools/core");
|
|
538
|
+
async function getPermissionModule(permission) {
|
|
539
|
+
switch (permission) {
|
|
540
|
+
case "camera": {
|
|
541
|
+
const mod = await (0, import_core11.tryImport)("expo-camera");
|
|
542
|
+
return mod ? {
|
|
543
|
+
check: () => mod.Camera.getCameraPermissionsAsync(),
|
|
544
|
+
request: () => mod.Camera.requestCameraPermissionsAsync()
|
|
545
|
+
} : null;
|
|
546
|
+
}
|
|
547
|
+
case "location": {
|
|
548
|
+
const mod = await (0, import_core11.tryImport)("expo-location");
|
|
549
|
+
return mod ? {
|
|
550
|
+
check: () => mod.getForegroundPermissionsAsync(),
|
|
551
|
+
request: () => mod.requestForegroundPermissionsAsync()
|
|
552
|
+
} : null;
|
|
553
|
+
}
|
|
554
|
+
case "notifications": {
|
|
555
|
+
const mod = await (0, import_core11.tryImport)("expo-notifications");
|
|
556
|
+
return mod ? {
|
|
557
|
+
check: () => mod.getPermissionsAsync(),
|
|
558
|
+
request: () => mod.requestPermissionsAsync()
|
|
559
|
+
} : null;
|
|
560
|
+
}
|
|
561
|
+
default:
|
|
562
|
+
return null;
|
|
563
|
+
}
|
|
564
|
+
}
|
|
565
|
+
var permissionHandlers = {
|
|
566
|
+
"permission.check": async (payload) => {
|
|
567
|
+
const mod = await getPermissionModule(payload.permission);
|
|
568
|
+
if (!mod) {
|
|
569
|
+
return { status: "undetermined", canAskAgain: true };
|
|
570
|
+
}
|
|
571
|
+
try {
|
|
572
|
+
const result = await mod.check();
|
|
573
|
+
return {
|
|
574
|
+
status: result.status,
|
|
575
|
+
canAskAgain: result.canAskAgain ?? true
|
|
576
|
+
};
|
|
577
|
+
} catch {
|
|
578
|
+
return { status: "undetermined", canAskAgain: true };
|
|
579
|
+
}
|
|
580
|
+
},
|
|
581
|
+
"permission.request": async (payload) => {
|
|
582
|
+
const mod = await getPermissionModule(payload.permission);
|
|
583
|
+
if (!mod) {
|
|
584
|
+
return { status: "undetermined", canAskAgain: true };
|
|
585
|
+
}
|
|
586
|
+
try {
|
|
587
|
+
const result = await mod.request();
|
|
588
|
+
return {
|
|
589
|
+
status: result.status,
|
|
590
|
+
canAskAgain: result.canAskAgain ?? true
|
|
591
|
+
};
|
|
592
|
+
} catch {
|
|
593
|
+
return { status: "undetermined", canAskAgain: true };
|
|
594
|
+
}
|
|
595
|
+
},
|
|
596
|
+
"permission.openSettings": async (_payload) => {
|
|
597
|
+
try {
|
|
598
|
+
await import_react_native6.Linking.openSettings();
|
|
599
|
+
return { success: true };
|
|
600
|
+
} catch {
|
|
601
|
+
return { success: false };
|
|
602
|
+
}
|
|
603
|
+
}
|
|
604
|
+
};
|
|
605
|
+
|
|
606
|
+
// src/handlers/preference.ts
|
|
607
|
+
var import_core12 = require("@rn-bridge-tools/core");
|
|
608
|
+
var preferenceHandlers = {
|
|
609
|
+
"preference.get": async (payload) => {
|
|
610
|
+
const mod = await (0, import_core12.tryImport)("@react-native-async-storage/async-storage");
|
|
611
|
+
if (!mod) return { value: null };
|
|
612
|
+
const value = await mod.default.getItem(payload.key);
|
|
613
|
+
return { value };
|
|
614
|
+
},
|
|
615
|
+
"preference.set": async (payload) => {
|
|
616
|
+
const mod = await (0, import_core12.tryImport)("@react-native-async-storage/async-storage");
|
|
617
|
+
if (!mod) return { success: false };
|
|
618
|
+
await mod.default.setItem(payload.key, payload.value);
|
|
619
|
+
return { success: true };
|
|
620
|
+
},
|
|
621
|
+
"preference.remove": async (payload) => {
|
|
622
|
+
const mod = await (0, import_core12.tryImport)("@react-native-async-storage/async-storage");
|
|
623
|
+
if (!mod) return { success: false };
|
|
624
|
+
await mod.default.removeItem(payload.key);
|
|
625
|
+
return { success: true };
|
|
626
|
+
},
|
|
627
|
+
"preference.clear": async (_payload) => {
|
|
628
|
+
const mod = await (0, import_core12.tryImport)("@react-native-async-storage/async-storage");
|
|
629
|
+
if (!mod) return { success: false };
|
|
630
|
+
await mod.default.clear();
|
|
631
|
+
return { success: true };
|
|
632
|
+
}
|
|
633
|
+
};
|
|
634
|
+
|
|
635
|
+
// src/handlers/navigation.ts
|
|
636
|
+
var navigationHandlers = {
|
|
637
|
+
"navigation.goBack": async (_payload) => {
|
|
638
|
+
return { success: true };
|
|
639
|
+
},
|
|
640
|
+
"navigation.push": async (_payload) => {
|
|
641
|
+
return { success: true };
|
|
642
|
+
},
|
|
643
|
+
"navigation.close": async (_payload) => {
|
|
644
|
+
return { success: true };
|
|
645
|
+
},
|
|
646
|
+
"navigation.setSwipeBack": async (_payload) => {
|
|
647
|
+
return { success: true };
|
|
648
|
+
}
|
|
649
|
+
};
|
|
650
|
+
|
|
651
|
+
// src/handlers/browser.ts
|
|
652
|
+
var import_core13 = require("@rn-bridge-tools/core");
|
|
653
|
+
var import_react_native7 = require("react-native");
|
|
654
|
+
var browserHandlers = {
|
|
655
|
+
"browser.openExternal": async (payload) => {
|
|
656
|
+
try {
|
|
657
|
+
await import_react_native7.Linking.openURL(payload.url);
|
|
658
|
+
return { success: true };
|
|
659
|
+
} catch {
|
|
660
|
+
return { success: false };
|
|
661
|
+
}
|
|
662
|
+
},
|
|
663
|
+
"browser.openInternal": async (payload) => {
|
|
664
|
+
const WebBrowser = await (0, import_core13.tryImport)("expo-web-browser");
|
|
665
|
+
if (!WebBrowser) return (0, import_core13.moduleNotInstalledError)("expo-web-browser");
|
|
666
|
+
try {
|
|
667
|
+
await WebBrowser.openBrowserAsync(payload.url, {
|
|
668
|
+
showTitle: payload.showTitle,
|
|
669
|
+
toolbarColor: payload.toolbarColor
|
|
670
|
+
});
|
|
671
|
+
return { success: true };
|
|
672
|
+
} catch {
|
|
673
|
+
return { success: false };
|
|
674
|
+
}
|
|
675
|
+
}
|
|
676
|
+
};
|
|
677
|
+
|
|
678
|
+
// src/createHandlers.ts
|
|
679
|
+
var handlerRegistry = {
|
|
680
|
+
camera: cameraHandlers,
|
|
681
|
+
location: locationHandlers,
|
|
682
|
+
file: fileHandlers,
|
|
683
|
+
share: shareHandlers,
|
|
684
|
+
device: deviceHandlers,
|
|
685
|
+
statusbar: statusbarHandlers,
|
|
686
|
+
keyboard: keyboardHandlers,
|
|
687
|
+
haptic: hapticHandlers,
|
|
688
|
+
clipboard: clipboardHandlers,
|
|
689
|
+
scanner: scannerHandlers,
|
|
690
|
+
auth: authHandlers,
|
|
691
|
+
iap: iapHandlers,
|
|
692
|
+
push: pushHandlers,
|
|
693
|
+
permission: permissionHandlers,
|
|
694
|
+
preference: preferenceHandlers,
|
|
695
|
+
navigation: navigationHandlers,
|
|
696
|
+
browser: browserHandlers
|
|
697
|
+
};
|
|
698
|
+
function createDisabledHandler(_namespace, _action) {
|
|
699
|
+
return async () => ({
|
|
700
|
+
success: false,
|
|
701
|
+
error: `not_enabled: ${_namespace}.${_action}`
|
|
702
|
+
});
|
|
703
|
+
}
|
|
704
|
+
function createDefaultHandlers(options = {}) {
|
|
705
|
+
const result = {};
|
|
706
|
+
for (const [namespace, handlers] of Object.entries(handlerRegistry)) {
|
|
707
|
+
const enabled = options[namespace] ?? false;
|
|
708
|
+
for (const [action, handler] of Object.entries(handlers)) {
|
|
709
|
+
if (enabled) {
|
|
710
|
+
result[action] = handler;
|
|
711
|
+
} else {
|
|
712
|
+
const actionName = action.split(".")[1] ?? action;
|
|
713
|
+
result[action] = createDisabledHandler(namespace, actionName);
|
|
714
|
+
}
|
|
715
|
+
}
|
|
716
|
+
}
|
|
717
|
+
return result;
|
|
718
|
+
}
|
|
719
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
720
|
+
0 && (module.exports = {
|
|
721
|
+
WebViewBridge,
|
|
722
|
+
authHandlers,
|
|
723
|
+
browserHandlers,
|
|
724
|
+
cameraHandlers,
|
|
725
|
+
clipboardHandlers,
|
|
726
|
+
createDefaultHandlers,
|
|
727
|
+
deviceHandlers,
|
|
728
|
+
fileHandlers,
|
|
729
|
+
hapticHandlers,
|
|
730
|
+
iapHandlers,
|
|
731
|
+
keyboardHandlers,
|
|
732
|
+
locationHandlers,
|
|
733
|
+
navigationHandlers,
|
|
734
|
+
permissionHandlers,
|
|
735
|
+
preferenceHandlers,
|
|
736
|
+
pushHandlers,
|
|
737
|
+
scannerHandlers,
|
|
738
|
+
shareHandlers,
|
|
739
|
+
statusbarHandlers
|
|
740
|
+
});
|
|
741
|
+
//# sourceMappingURL=index.cjs.map
|