@rn-bridge-tools/expo 0.0.2 → 0.0.4

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.js CHANGED
@@ -1,3 +1,10 @@
1
+ var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
2
+ get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
3
+ }) : x)(function(x) {
4
+ if (typeof require !== "undefined") return require.apply(this, arguments);
5
+ throw Error('Dynamic require of "' + x + '" is not supported');
6
+ });
7
+
1
8
  // src/WebViewBridge.tsx
2
9
  import { forwardRef, useImperativeHandle, useMemo, useRef } from "react";
3
10
  import { bridge, createWebView } from "@webview-bridge/react-native";
@@ -38,11 +45,14 @@ var WebViewBridge = forwardRef(
38
45
  );
39
46
 
40
47
  // src/handlers/camera.ts
41
- import { moduleNotInstalledError, tryImport } from "@rn-bridge-tools/core";
42
48
  var cameraHandlers = {
43
49
  "camera.take": async (payload) => {
44
- const ImagePicker = await tryImport("expo-image-picker");
45
- if (!ImagePicker) return moduleNotInstalledError("expo-image-picker");
50
+ let ImagePicker = null;
51
+ try {
52
+ ImagePicker = __require("expo-image-picker");
53
+ } catch {
54
+ }
55
+ if (!ImagePicker) return { success: false, error: "MODULE_NOT_INSTALLED: expo-image-picker" };
46
56
  const result = await ImagePicker.launchCameraAsync({
47
57
  quality: payload.quality ?? 0.8,
48
58
  cameraType: payload.facing === "front" ? ImagePicker.CameraType.front : ImagePicker.CameraType.back,
@@ -62,8 +72,12 @@ var cameraHandlers = {
62
72
  };
63
73
  },
64
74
  "camera.pickImage": async (payload) => {
65
- const ImagePicker = await tryImport("expo-image-picker");
66
- if (!ImagePicker) return moduleNotInstalledError("expo-image-picker");
75
+ let ImagePicker = null;
76
+ try {
77
+ ImagePicker = __require("expo-image-picker");
78
+ } catch {
79
+ }
80
+ if (!ImagePicker) return { success: false, error: "MODULE_NOT_INSTALLED: expo-image-picker" };
67
81
  const result = await ImagePicker.launchImageLibraryAsync({
68
82
  allowsMultipleSelection: payload.allowsMultipleSelection ?? false,
69
83
  quality: payload.quality ?? 0.8,
@@ -86,13 +100,16 @@ var cameraHandlers = {
86
100
  };
87
101
 
88
102
  // src/handlers/location.ts
89
- import { moduleNotInstalledError as moduleNotInstalledError2, tryImport as tryImport2 } from "@rn-bridge-tools/core";
90
103
  var watchSubscriptions = /* @__PURE__ */ new Map();
91
104
  var watchCounter = 0;
92
105
  var locationHandlers = {
93
106
  "location.getCurrent": async (payload) => {
94
- const Location = await tryImport2("expo-location");
95
- if (!Location) return moduleNotInstalledError2("expo-location");
107
+ let Location = null;
108
+ try {
109
+ Location = __require("expo-location");
110
+ } catch {
111
+ }
112
+ if (!Location) return { success: false, error: "MODULE_NOT_INSTALLED: expo-location" };
96
113
  const accuracyMap = {
97
114
  lowest: Location.Accuracy.Lowest,
98
115
  low: Location.Accuracy.Low,
@@ -112,8 +129,12 @@ var locationHandlers = {
112
129
  };
113
130
  },
114
131
  "location.watchStart": async (payload) => {
115
- const Location = await tryImport2("expo-location");
116
- if (!Location) return moduleNotInstalledError2("expo-location");
132
+ let Location = null;
133
+ try {
134
+ Location = __require("expo-location");
135
+ } catch {
136
+ }
137
+ if (!Location) return { success: false, error: "MODULE_NOT_INSTALLED: expo-location" };
117
138
  watchCounter += 1;
118
139
  const watchId = `watch_${watchCounter}`;
119
140
  const accuracyMap = {
@@ -145,11 +166,14 @@ var locationHandlers = {
145
166
  };
146
167
 
147
168
  // src/handlers/file.ts
148
- import { moduleNotInstalledError as moduleNotInstalledError3, tryImport as tryImport3 } from "@rn-bridge-tools/core";
149
169
  var fileHandlers = {
150
170
  "file.download": async (payload) => {
151
- const FS = await tryImport3("expo-file-system");
152
- if (!FS) return moduleNotInstalledError3("expo-file-system");
171
+ let FS = null;
172
+ try {
173
+ FS = __require("expo-file-system");
174
+ } catch {
175
+ }
176
+ if (!FS) return { success: false, error: "MODULE_NOT_INSTALLED: expo-file-system" };
153
177
  try {
154
178
  const response = await fetch(payload.url);
155
179
  const text = await response.text();
@@ -161,8 +185,12 @@ var fileHandlers = {
161
185
  }
162
186
  },
163
187
  "file.read": async (payload) => {
164
- const FS = await tryImport3("expo-file-system");
165
- if (!FS) return moduleNotInstalledError3("expo-file-system");
188
+ let FS = null;
189
+ try {
190
+ FS = __require("expo-file-system");
191
+ } catch {
192
+ }
193
+ if (!FS) return { success: false, error: "MODULE_NOT_INSTALLED: expo-file-system" };
166
194
  try {
167
195
  const file = new FS.File(payload.uri);
168
196
  const content = await file.text();
@@ -172,8 +200,12 @@ var fileHandlers = {
172
200
  }
173
201
  },
174
202
  "file.write": async (payload) => {
175
- const FS = await tryImport3("expo-file-system");
176
- if (!FS) return moduleNotInstalledError3("expo-file-system");
203
+ let FS = null;
204
+ try {
205
+ FS = __require("expo-file-system");
206
+ } catch {
207
+ }
208
+ if (!FS) return { success: false, error: "MODULE_NOT_INSTALLED: expo-file-system" };
177
209
  try {
178
210
  const dirMap = {
179
211
  document: FS.Paths.document,
@@ -189,8 +221,12 @@ var fileHandlers = {
189
221
  }
190
222
  },
191
223
  "file.pick": async (payload) => {
192
- const DocumentPicker = await tryImport3("expo-document-picker");
193
- if (!DocumentPicker) return moduleNotInstalledError3("expo-document-picker");
224
+ let DocumentPicker = null;
225
+ try {
226
+ DocumentPicker = __require("expo-document-picker");
227
+ } catch {
228
+ }
229
+ if (!DocumentPicker) return { success: false, error: "MODULE_NOT_INSTALLED: expo-document-picker" };
194
230
  try {
195
231
  const result = await DocumentPicker.getDocumentAsync({
196
232
  type: payload.type ?? ["*/*"],
@@ -215,11 +251,14 @@ var fileHandlers = {
215
251
  };
216
252
 
217
253
  // src/handlers/share.ts
218
- import { moduleNotInstalledError as moduleNotInstalledError4, tryImport as tryImport4 } from "@rn-bridge-tools/core";
219
254
  var shareHandlers = {
220
255
  "share.open": async (payload) => {
221
- const Sharing = await tryImport4("expo-sharing");
222
- if (!Sharing) return moduleNotInstalledError4("expo-sharing");
256
+ let Sharing = null;
257
+ try {
258
+ Sharing = __require("expo-sharing");
259
+ } catch {
260
+ }
261
+ if (!Sharing) return { success: false, error: "MODULE_NOT_INSTALLED: expo-sharing" };
223
262
  try {
224
263
  const isAvailable = await Sharing.isAvailableAsync();
225
264
  if (!isAvailable) {
@@ -236,12 +275,15 @@ var shareHandlers = {
236
275
  };
237
276
 
238
277
  // src/handlers/device.ts
239
- import { moduleNotInstalledError as moduleNotInstalledError5, tryImport as tryImport5 } from "@rn-bridge-tools/core";
240
278
  import { Platform } from "react-native";
241
279
  var deviceHandlers = {
242
280
  "device.getInfo": async (_payload) => {
243
- const Device = await tryImport5("expo-device");
244
- if (!Device) return moduleNotInstalledError5("expo-device");
281
+ let Device = null;
282
+ try {
283
+ Device = __require("expo-device");
284
+ } catch {
285
+ }
286
+ if (!Device) return { success: false, error: "MODULE_NOT_INSTALLED: expo-device" };
245
287
  return {
246
288
  os: Platform.OS,
247
289
  osVersion: Platform.Version?.toString() ?? "",
@@ -255,7 +297,11 @@ var deviceHandlers = {
255
297
  },
256
298
  "device.getBattery": async (_payload) => {
257
299
  try {
258
- const Battery = await tryImport5("expo-battery");
300
+ let Battery = null;
301
+ try {
302
+ Battery = __require("expo-battery");
303
+ } catch {
304
+ }
259
305
  if (!Battery) {
260
306
  return { level: -1, isCharging: false };
261
307
  }
@@ -271,7 +317,11 @@ var deviceHandlers = {
271
317
  },
272
318
  "device.getNetwork": async (_payload) => {
273
319
  try {
274
- const NetInfo = await tryImport5("@react-native-community/netinfo");
320
+ let NetInfo = null;
321
+ try {
322
+ NetInfo = __require("@react-native-community/netinfo");
323
+ } catch {
324
+ }
275
325
  if (!NetInfo) {
276
326
  return { type: "unknown", isConnected: true };
277
327
  }
@@ -329,12 +379,14 @@ var keyboardHandlers = {
329
379
  };
330
380
 
331
381
  // src/handlers/haptic.ts
332
- import { moduleNotInstalledError as moduleNotInstalledError6, tryImport as tryImport6 } from "@rn-bridge-tools/core";
333
382
  var hapticHandlers = {
334
383
  "haptic.impact": async (payload) => {
335
- const Haptics = await tryImport6("expo-haptics");
384
+ let Haptics = null;
385
+ try {
386
+ Haptics = __require("expo-haptics");
387
+ } catch {
388
+ }
336
389
  if (!Haptics) {
337
- moduleNotInstalledError6("expo-haptics");
338
390
  return;
339
391
  }
340
392
  const styleMap = {
@@ -345,9 +397,12 @@ var hapticHandlers = {
345
397
  await Haptics.impactAsync(styleMap[payload.style]);
346
398
  },
347
399
  "haptic.notification": async (payload) => {
348
- const Haptics = await tryImport6("expo-haptics");
400
+ let Haptics = null;
401
+ try {
402
+ Haptics = __require("expo-haptics");
403
+ } catch {
404
+ }
349
405
  if (!Haptics) {
350
- moduleNotInstalledError6("expo-haptics");
351
406
  return;
352
407
  }
353
408
  const typeMap = {
@@ -358,9 +413,12 @@ var hapticHandlers = {
358
413
  await Haptics.notificationAsync(typeMap[payload.type]);
359
414
  },
360
415
  "haptic.selection": async () => {
361
- const Haptics = await tryImport6("expo-haptics");
416
+ let Haptics = null;
417
+ try {
418
+ Haptics = __require("expo-haptics");
419
+ } catch {
420
+ }
362
421
  if (!Haptics) {
363
- moduleNotInstalledError6("expo-haptics");
364
422
  return;
365
423
  }
366
424
  await Haptics.selectionAsync();
@@ -368,28 +426,38 @@ var hapticHandlers = {
368
426
  };
369
427
 
370
428
  // src/handlers/clipboard.ts
371
- import { moduleNotInstalledError as moduleNotInstalledError7, tryImport as tryImport7 } from "@rn-bridge-tools/core";
372
429
  var clipboardHandlers = {
373
430
  "clipboard.copy": async (payload) => {
374
- const Clipboard = await tryImport7("expo-clipboard");
375
- if (!Clipboard) return moduleNotInstalledError7("expo-clipboard");
431
+ let Clipboard = null;
432
+ try {
433
+ Clipboard = __require("expo-clipboard");
434
+ } catch {
435
+ }
436
+ if (!Clipboard) return { success: false, error: "MODULE_NOT_INSTALLED: expo-clipboard" };
376
437
  await Clipboard.setStringAsync(payload.text);
377
438
  return { success: true };
378
439
  },
379
440
  "clipboard.paste": async (_payload) => {
380
- const Clipboard = await tryImport7("expo-clipboard");
381
- if (!Clipboard) return moduleNotInstalledError7("expo-clipboard");
441
+ let Clipboard = null;
442
+ try {
443
+ Clipboard = __require("expo-clipboard");
444
+ } catch {
445
+ }
446
+ if (!Clipboard) return { success: false, error: "MODULE_NOT_INSTALLED: expo-clipboard" };
382
447
  const text = await Clipboard.getStringAsync();
383
448
  return { text, hasContent: text.length > 0 };
384
449
  }
385
450
  };
386
451
 
387
452
  // src/handlers/scanner.ts
388
- import { moduleNotInstalledError as moduleNotInstalledError8, tryImport as tryImport8 } from "@rn-bridge-tools/core";
389
453
  var scannerHandlers = {
390
454
  "scanner.scanQR": async (_payload) => {
391
- const Camera = await tryImport8("expo-camera");
392
- if (!Camera) return moduleNotInstalledError8("expo-camera");
455
+ let Camera = null;
456
+ try {
457
+ Camera = __require("expo-camera");
458
+ } catch {
459
+ }
460
+ if (!Camera) return { success: false, error: "MODULE_NOT_INSTALLED: expo-camera" };
393
461
  try {
394
462
  const { status } = await Camera.Camera.requestCameraPermissionsAsync();
395
463
  if (status !== "granted") {
@@ -403,11 +471,14 @@ var scannerHandlers = {
403
471
  };
404
472
 
405
473
  // src/handlers/auth.ts
406
- import { moduleNotInstalledError as moduleNotInstalledError9, tryImport as tryImport9 } from "@rn-bridge-tools/core";
407
474
  var authHandlers = {
408
475
  "auth.biometric": async (payload) => {
409
- const LocalAuth = await tryImport9("expo-local-authentication");
410
- if (!LocalAuth) return moduleNotInstalledError9("expo-local-authentication");
476
+ let LocalAuth = null;
477
+ try {
478
+ LocalAuth = __require("expo-local-authentication");
479
+ } catch {
480
+ }
481
+ if (!LocalAuth) return { success: false, error: "MODULE_NOT_INSTALLED: expo-local-authentication" };
411
482
  try {
412
483
  const result = await LocalAuth.authenticateAsync({
413
484
  promptMessage: payload.promptMessage ?? "Authenticate",
@@ -423,8 +494,12 @@ var authHandlers = {
423
494
  }
424
495
  },
425
496
  "auth.isBiometricAvailable": async (_payload) => {
426
- const LocalAuth = await tryImport9("expo-local-authentication");
427
- if (!LocalAuth) return moduleNotInstalledError9("expo-local-authentication");
497
+ let LocalAuth = null;
498
+ try {
499
+ LocalAuth = __require("expo-local-authentication");
500
+ } catch {
501
+ }
502
+ if (!LocalAuth) return { success: false, error: "MODULE_NOT_INSTALLED: expo-local-authentication" };
428
503
  try {
429
504
  const available = await LocalAuth.hasHardwareAsync();
430
505
  const types = await LocalAuth.supportedAuthenticationTypesAsync();
@@ -457,12 +532,15 @@ var iapHandlers = {
457
532
  };
458
533
 
459
534
  // src/handlers/push.ts
460
- import { moduleNotInstalledError as moduleNotInstalledError10, tryImport as tryImport10 } from "@rn-bridge-tools/core";
461
535
  import { Platform as Platform2 } from "react-native";
462
536
  var pushHandlers = {
463
537
  "push.getToken": async (_payload) => {
464
- const Notifications = await tryImport10("expo-notifications");
465
- if (!Notifications) return moduleNotInstalledError10("expo-notifications");
538
+ let Notifications = null;
539
+ try {
540
+ Notifications = __require("expo-notifications");
541
+ } catch {
542
+ }
543
+ if (!Notifications) return { success: false, error: "MODULE_NOT_INSTALLED: expo-notifications" };
466
544
  try {
467
545
  const token = await Notifications.getExpoPushTokenAsync();
468
546
  return {
@@ -474,8 +552,12 @@ var pushHandlers = {
474
552
  }
475
553
  },
476
554
  "push.requestPermission": async (_payload) => {
477
- const Notifications = await tryImport10("expo-notifications");
478
- if (!Notifications) return moduleNotInstalledError10("expo-notifications");
555
+ let Notifications = null;
556
+ try {
557
+ Notifications = __require("expo-notifications");
558
+ } catch {
559
+ }
560
+ if (!Notifications) return { success: false, error: "MODULE_NOT_INSTALLED: expo-notifications" };
479
561
  try {
480
562
  const { status } = await Notifications.requestPermissionsAsync();
481
563
  return {
@@ -490,25 +572,36 @@ var pushHandlers = {
490
572
 
491
573
  // src/handlers/permission.ts
492
574
  import { Linking } from "react-native";
493
- import { tryImport as tryImport11 } from "@rn-bridge-tools/core";
494
- async function getPermissionModule(permission) {
575
+ function getPermissionModule(permission) {
495
576
  switch (permission) {
496
577
  case "camera": {
497
- const mod = await tryImport11("expo-camera");
578
+ let mod = null;
579
+ try {
580
+ mod = __require("expo-camera");
581
+ } catch {
582
+ }
498
583
  return mod ? {
499
584
  check: () => mod.Camera.getCameraPermissionsAsync(),
500
585
  request: () => mod.Camera.requestCameraPermissionsAsync()
501
586
  } : null;
502
587
  }
503
588
  case "location": {
504
- const mod = await tryImport11("expo-location");
589
+ let mod = null;
590
+ try {
591
+ mod = __require("expo-location");
592
+ } catch {
593
+ }
505
594
  return mod ? {
506
595
  check: () => mod.getForegroundPermissionsAsync(),
507
596
  request: () => mod.requestForegroundPermissionsAsync()
508
597
  } : null;
509
598
  }
510
599
  case "notifications": {
511
- const mod = await tryImport11("expo-notifications");
600
+ let mod = null;
601
+ try {
602
+ mod = __require("expo-notifications");
603
+ } catch {
604
+ }
512
605
  return mod ? {
513
606
  check: () => mod.getPermissionsAsync(),
514
607
  request: () => mod.requestPermissionsAsync()
@@ -520,7 +613,7 @@ async function getPermissionModule(permission) {
520
613
  }
521
614
  var permissionHandlers = {
522
615
  "permission.check": async (payload) => {
523
- const mod = await getPermissionModule(payload.permission);
616
+ const mod = getPermissionModule(payload.permission);
524
617
  if (!mod) {
525
618
  return { status: "undetermined", canAskAgain: true };
526
619
  }
@@ -535,7 +628,7 @@ var permissionHandlers = {
535
628
  }
536
629
  },
537
630
  "permission.request": async (payload) => {
538
- const mod = await getPermissionModule(payload.permission);
631
+ const mod = getPermissionModule(payload.permission);
539
632
  if (!mod) {
540
633
  return { status: "undetermined", canAskAgain: true };
541
634
  }
@@ -560,28 +653,43 @@ var permissionHandlers = {
560
653
  };
561
654
 
562
655
  // src/handlers/preference.ts
563
- import { tryImport as tryImport12 } from "@rn-bridge-tools/core";
564
656
  var preferenceHandlers = {
565
657
  "preference.get": async (payload) => {
566
- const mod = await tryImport12("@react-native-async-storage/async-storage");
658
+ let mod = null;
659
+ try {
660
+ mod = __require("@react-native-async-storage/async-storage");
661
+ } catch {
662
+ }
567
663
  if (!mod) return { value: null };
568
664
  const value = await mod.default.getItem(payload.key);
569
665
  return { value };
570
666
  },
571
667
  "preference.set": async (payload) => {
572
- const mod = await tryImport12("@react-native-async-storage/async-storage");
668
+ let mod = null;
669
+ try {
670
+ mod = __require("@react-native-async-storage/async-storage");
671
+ } catch {
672
+ }
573
673
  if (!mod) return { success: false };
574
674
  await mod.default.setItem(payload.key, payload.value);
575
675
  return { success: true };
576
676
  },
577
677
  "preference.remove": async (payload) => {
578
- const mod = await tryImport12("@react-native-async-storage/async-storage");
678
+ let mod = null;
679
+ try {
680
+ mod = __require("@react-native-async-storage/async-storage");
681
+ } catch {
682
+ }
579
683
  if (!mod) return { success: false };
580
684
  await mod.default.removeItem(payload.key);
581
685
  return { success: true };
582
686
  },
583
687
  "preference.clear": async (_payload) => {
584
- const mod = await tryImport12("@react-native-async-storage/async-storage");
688
+ let mod = null;
689
+ try {
690
+ mod = __require("@react-native-async-storage/async-storage");
691
+ } catch {
692
+ }
585
693
  if (!mod) return { success: false };
586
694
  await mod.default.clear();
587
695
  return { success: true };
@@ -605,7 +713,6 @@ var navigationHandlers = {
605
713
  };
606
714
 
607
715
  // src/handlers/browser.ts
608
- import { moduleNotInstalledError as moduleNotInstalledError11, tryImport as tryImport13 } from "@rn-bridge-tools/core";
609
716
  import { Linking as Linking2 } from "react-native";
610
717
  var browserHandlers = {
611
718
  "browser.openExternal": async (payload) => {
@@ -617,8 +724,12 @@ var browserHandlers = {
617
724
  }
618
725
  },
619
726
  "browser.openInternal": async (payload) => {
620
- const WebBrowser = await tryImport13("expo-web-browser");
621
- if (!WebBrowser) return moduleNotInstalledError11("expo-web-browser");
727
+ let WebBrowser = null;
728
+ try {
729
+ WebBrowser = __require("expo-web-browser");
730
+ } catch {
731
+ }
732
+ if (!WebBrowser) return { success: false, error: "MODULE_NOT_INSTALLED: expo-web-browser" };
622
733
  try {
623
734
  await WebBrowser.openBrowserAsync(payload.url, {
624
735
  showTitle: payload.showTitle,