@rn-bridge-tools/expo 0.0.3 → 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.cjs CHANGED
@@ -82,11 +82,14 @@ var WebViewBridge = (0, import_react.forwardRef)(
82
82
  );
83
83
 
84
84
  // src/handlers/camera.ts
85
- var import_core = require("@rn-bridge-tools/core");
86
85
  var cameraHandlers = {
87
86
  "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");
87
+ let ImagePicker = null;
88
+ try {
89
+ ImagePicker = require("expo-image-picker");
90
+ } catch {
91
+ }
92
+ if (!ImagePicker) return { success: false, error: "MODULE_NOT_INSTALLED: expo-image-picker" };
90
93
  const result = await ImagePicker.launchCameraAsync({
91
94
  quality: payload.quality ?? 0.8,
92
95
  cameraType: payload.facing === "front" ? ImagePicker.CameraType.front : ImagePicker.CameraType.back,
@@ -106,8 +109,12 @@ var cameraHandlers = {
106
109
  };
107
110
  },
108
111
  "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");
112
+ let ImagePicker = null;
113
+ try {
114
+ ImagePicker = require("expo-image-picker");
115
+ } catch {
116
+ }
117
+ if (!ImagePicker) return { success: false, error: "MODULE_NOT_INSTALLED: expo-image-picker" };
111
118
  const result = await ImagePicker.launchImageLibraryAsync({
112
119
  allowsMultipleSelection: payload.allowsMultipleSelection ?? false,
113
120
  quality: payload.quality ?? 0.8,
@@ -130,13 +137,16 @@ var cameraHandlers = {
130
137
  };
131
138
 
132
139
  // src/handlers/location.ts
133
- var import_core2 = require("@rn-bridge-tools/core");
134
140
  var watchSubscriptions = /* @__PURE__ */ new Map();
135
141
  var watchCounter = 0;
136
142
  var locationHandlers = {
137
143
  "location.getCurrent": async (payload) => {
138
- const Location = await (0, import_core2.tryImport)("expo-location");
139
- if (!Location) return (0, import_core2.moduleNotInstalledError)("expo-location");
144
+ let Location = null;
145
+ try {
146
+ Location = require("expo-location");
147
+ } catch {
148
+ }
149
+ if (!Location) return { success: false, error: "MODULE_NOT_INSTALLED: expo-location" };
140
150
  const accuracyMap = {
141
151
  lowest: Location.Accuracy.Lowest,
142
152
  low: Location.Accuracy.Low,
@@ -156,8 +166,12 @@ var locationHandlers = {
156
166
  };
157
167
  },
158
168
  "location.watchStart": async (payload) => {
159
- const Location = await (0, import_core2.tryImport)("expo-location");
160
- if (!Location) return (0, import_core2.moduleNotInstalledError)("expo-location");
169
+ let Location = null;
170
+ try {
171
+ Location = require("expo-location");
172
+ } catch {
173
+ }
174
+ if (!Location) return { success: false, error: "MODULE_NOT_INSTALLED: expo-location" };
161
175
  watchCounter += 1;
162
176
  const watchId = `watch_${watchCounter}`;
163
177
  const accuracyMap = {
@@ -189,11 +203,14 @@ var locationHandlers = {
189
203
  };
190
204
 
191
205
  // src/handlers/file.ts
192
- var import_core3 = require("@rn-bridge-tools/core");
193
206
  var fileHandlers = {
194
207
  "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");
208
+ let FS = null;
209
+ try {
210
+ FS = require("expo-file-system");
211
+ } catch {
212
+ }
213
+ if (!FS) return { success: false, error: "MODULE_NOT_INSTALLED: expo-file-system" };
197
214
  try {
198
215
  const response = await fetch(payload.url);
199
216
  const text = await response.text();
@@ -205,8 +222,12 @@ var fileHandlers = {
205
222
  }
206
223
  },
207
224
  "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");
225
+ let FS = null;
226
+ try {
227
+ FS = require("expo-file-system");
228
+ } catch {
229
+ }
230
+ if (!FS) return { success: false, error: "MODULE_NOT_INSTALLED: expo-file-system" };
210
231
  try {
211
232
  const file = new FS.File(payload.uri);
212
233
  const content = await file.text();
@@ -216,8 +237,12 @@ var fileHandlers = {
216
237
  }
217
238
  },
218
239
  "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");
240
+ let FS = null;
241
+ try {
242
+ FS = require("expo-file-system");
243
+ } catch {
244
+ }
245
+ if (!FS) return { success: false, error: "MODULE_NOT_INSTALLED: expo-file-system" };
221
246
  try {
222
247
  const dirMap = {
223
248
  document: FS.Paths.document,
@@ -233,8 +258,12 @@ var fileHandlers = {
233
258
  }
234
259
  },
235
260
  "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");
261
+ let DocumentPicker = null;
262
+ try {
263
+ DocumentPicker = require("expo-document-picker");
264
+ } catch {
265
+ }
266
+ if (!DocumentPicker) return { success: false, error: "MODULE_NOT_INSTALLED: expo-document-picker" };
238
267
  try {
239
268
  const result = await DocumentPicker.getDocumentAsync({
240
269
  type: payload.type ?? ["*/*"],
@@ -259,11 +288,14 @@ var fileHandlers = {
259
288
  };
260
289
 
261
290
  // src/handlers/share.ts
262
- var import_core4 = require("@rn-bridge-tools/core");
263
291
  var shareHandlers = {
264
292
  "share.open": async (payload) => {
265
- const Sharing = await (0, import_core4.tryImport)("expo-sharing");
266
- if (!Sharing) return (0, import_core4.moduleNotInstalledError)("expo-sharing");
293
+ let Sharing = null;
294
+ try {
295
+ Sharing = require("expo-sharing");
296
+ } catch {
297
+ }
298
+ if (!Sharing) return { success: false, error: "MODULE_NOT_INSTALLED: expo-sharing" };
267
299
  try {
268
300
  const isAvailable = await Sharing.isAvailableAsync();
269
301
  if (!isAvailable) {
@@ -280,12 +312,15 @@ var shareHandlers = {
280
312
  };
281
313
 
282
314
  // src/handlers/device.ts
283
- var import_core5 = require("@rn-bridge-tools/core");
284
315
  var import_react_native2 = require("react-native");
285
316
  var deviceHandlers = {
286
317
  "device.getInfo": async (_payload) => {
287
- const Device = await (0, import_core5.tryImport)("expo-device");
288
- if (!Device) return (0, import_core5.moduleNotInstalledError)("expo-device");
318
+ let Device = null;
319
+ try {
320
+ Device = require("expo-device");
321
+ } catch {
322
+ }
323
+ if (!Device) return { success: false, error: "MODULE_NOT_INSTALLED: expo-device" };
289
324
  return {
290
325
  os: import_react_native2.Platform.OS,
291
326
  osVersion: import_react_native2.Platform.Version?.toString() ?? "",
@@ -299,7 +334,11 @@ var deviceHandlers = {
299
334
  },
300
335
  "device.getBattery": async (_payload) => {
301
336
  try {
302
- const Battery = await (0, import_core5.tryImport)("expo-battery");
337
+ let Battery = null;
338
+ try {
339
+ Battery = require("expo-battery");
340
+ } catch {
341
+ }
303
342
  if (!Battery) {
304
343
  return { level: -1, isCharging: false };
305
344
  }
@@ -315,7 +354,11 @@ var deviceHandlers = {
315
354
  },
316
355
  "device.getNetwork": async (_payload) => {
317
356
  try {
318
- const NetInfo = await (0, import_core5.tryImport)("@react-native-community/netinfo");
357
+ let NetInfo = null;
358
+ try {
359
+ NetInfo = require("@react-native-community/netinfo");
360
+ } catch {
361
+ }
319
362
  if (!NetInfo) {
320
363
  return { type: "unknown", isConnected: true };
321
364
  }
@@ -373,12 +416,14 @@ var keyboardHandlers = {
373
416
  };
374
417
 
375
418
  // src/handlers/haptic.ts
376
- var import_core6 = require("@rn-bridge-tools/core");
377
419
  var hapticHandlers = {
378
420
  "haptic.impact": async (payload) => {
379
- const Haptics = await (0, import_core6.tryImport)("expo-haptics");
421
+ let Haptics = null;
422
+ try {
423
+ Haptics = require("expo-haptics");
424
+ } catch {
425
+ }
380
426
  if (!Haptics) {
381
- (0, import_core6.moduleNotInstalledError)("expo-haptics");
382
427
  return;
383
428
  }
384
429
  const styleMap = {
@@ -389,9 +434,12 @@ var hapticHandlers = {
389
434
  await Haptics.impactAsync(styleMap[payload.style]);
390
435
  },
391
436
  "haptic.notification": async (payload) => {
392
- const Haptics = await (0, import_core6.tryImport)("expo-haptics");
437
+ let Haptics = null;
438
+ try {
439
+ Haptics = require("expo-haptics");
440
+ } catch {
441
+ }
393
442
  if (!Haptics) {
394
- (0, import_core6.moduleNotInstalledError)("expo-haptics");
395
443
  return;
396
444
  }
397
445
  const typeMap = {
@@ -402,9 +450,12 @@ var hapticHandlers = {
402
450
  await Haptics.notificationAsync(typeMap[payload.type]);
403
451
  },
404
452
  "haptic.selection": async () => {
405
- const Haptics = await (0, import_core6.tryImport)("expo-haptics");
453
+ let Haptics = null;
454
+ try {
455
+ Haptics = require("expo-haptics");
456
+ } catch {
457
+ }
406
458
  if (!Haptics) {
407
- (0, import_core6.moduleNotInstalledError)("expo-haptics");
408
459
  return;
409
460
  }
410
461
  await Haptics.selectionAsync();
@@ -412,28 +463,38 @@ var hapticHandlers = {
412
463
  };
413
464
 
414
465
  // src/handlers/clipboard.ts
415
- var import_core7 = require("@rn-bridge-tools/core");
416
466
  var clipboardHandlers = {
417
467
  "clipboard.copy": async (payload) => {
418
- const Clipboard = await (0, import_core7.tryImport)("expo-clipboard");
419
- if (!Clipboard) return (0, import_core7.moduleNotInstalledError)("expo-clipboard");
468
+ let Clipboard = null;
469
+ try {
470
+ Clipboard = require("expo-clipboard");
471
+ } catch {
472
+ }
473
+ if (!Clipboard) return { success: false, error: "MODULE_NOT_INSTALLED: expo-clipboard" };
420
474
  await Clipboard.setStringAsync(payload.text);
421
475
  return { success: true };
422
476
  },
423
477
  "clipboard.paste": async (_payload) => {
424
- const Clipboard = await (0, import_core7.tryImport)("expo-clipboard");
425
- if (!Clipboard) return (0, import_core7.moduleNotInstalledError)("expo-clipboard");
478
+ let Clipboard = null;
479
+ try {
480
+ Clipboard = require("expo-clipboard");
481
+ } catch {
482
+ }
483
+ if (!Clipboard) return { success: false, error: "MODULE_NOT_INSTALLED: expo-clipboard" };
426
484
  const text = await Clipboard.getStringAsync();
427
485
  return { text, hasContent: text.length > 0 };
428
486
  }
429
487
  };
430
488
 
431
489
  // src/handlers/scanner.ts
432
- var import_core8 = require("@rn-bridge-tools/core");
433
490
  var scannerHandlers = {
434
491
  "scanner.scanQR": async (_payload) => {
435
- const Camera = await (0, import_core8.tryImport)("expo-camera");
436
- if (!Camera) return (0, import_core8.moduleNotInstalledError)("expo-camera");
492
+ let Camera = null;
493
+ try {
494
+ Camera = require("expo-camera");
495
+ } catch {
496
+ }
497
+ if (!Camera) return { success: false, error: "MODULE_NOT_INSTALLED: expo-camera" };
437
498
  try {
438
499
  const { status } = await Camera.Camera.requestCameraPermissionsAsync();
439
500
  if (status !== "granted") {
@@ -447,11 +508,14 @@ var scannerHandlers = {
447
508
  };
448
509
 
449
510
  // src/handlers/auth.ts
450
- var import_core9 = require("@rn-bridge-tools/core");
451
511
  var authHandlers = {
452
512
  "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");
513
+ let LocalAuth = null;
514
+ try {
515
+ LocalAuth = require("expo-local-authentication");
516
+ } catch {
517
+ }
518
+ if (!LocalAuth) return { success: false, error: "MODULE_NOT_INSTALLED: expo-local-authentication" };
455
519
  try {
456
520
  const result = await LocalAuth.authenticateAsync({
457
521
  promptMessage: payload.promptMessage ?? "Authenticate",
@@ -467,8 +531,12 @@ var authHandlers = {
467
531
  }
468
532
  },
469
533
  "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");
534
+ let LocalAuth = null;
535
+ try {
536
+ LocalAuth = require("expo-local-authentication");
537
+ } catch {
538
+ }
539
+ if (!LocalAuth) return { success: false, error: "MODULE_NOT_INSTALLED: expo-local-authentication" };
472
540
  try {
473
541
  const available = await LocalAuth.hasHardwareAsync();
474
542
  const types = await LocalAuth.supportedAuthenticationTypesAsync();
@@ -501,12 +569,15 @@ var iapHandlers = {
501
569
  };
502
570
 
503
571
  // src/handlers/push.ts
504
- var import_core10 = require("@rn-bridge-tools/core");
505
572
  var import_react_native5 = require("react-native");
506
573
  var pushHandlers = {
507
574
  "push.getToken": async (_payload) => {
508
- const Notifications = await (0, import_core10.tryImport)("expo-notifications");
509
- if (!Notifications) return (0, import_core10.moduleNotInstalledError)("expo-notifications");
575
+ let Notifications = null;
576
+ try {
577
+ Notifications = require("expo-notifications");
578
+ } catch {
579
+ }
580
+ if (!Notifications) return { success: false, error: "MODULE_NOT_INSTALLED: expo-notifications" };
510
581
  try {
511
582
  const token = await Notifications.getExpoPushTokenAsync();
512
583
  return {
@@ -518,8 +589,12 @@ var pushHandlers = {
518
589
  }
519
590
  },
520
591
  "push.requestPermission": async (_payload) => {
521
- const Notifications = await (0, import_core10.tryImport)("expo-notifications");
522
- if (!Notifications) return (0, import_core10.moduleNotInstalledError)("expo-notifications");
592
+ let Notifications = null;
593
+ try {
594
+ Notifications = require("expo-notifications");
595
+ } catch {
596
+ }
597
+ if (!Notifications) return { success: false, error: "MODULE_NOT_INSTALLED: expo-notifications" };
523
598
  try {
524
599
  const { status } = await Notifications.requestPermissionsAsync();
525
600
  return {
@@ -534,25 +609,36 @@ var pushHandlers = {
534
609
 
535
610
  // src/handlers/permission.ts
536
611
  var import_react_native6 = require("react-native");
537
- var import_core11 = require("@rn-bridge-tools/core");
538
- async function getPermissionModule(permission) {
612
+ function getPermissionModule(permission) {
539
613
  switch (permission) {
540
614
  case "camera": {
541
- const mod = await (0, import_core11.tryImport)("expo-camera");
615
+ let mod = null;
616
+ try {
617
+ mod = require("expo-camera");
618
+ } catch {
619
+ }
542
620
  return mod ? {
543
621
  check: () => mod.Camera.getCameraPermissionsAsync(),
544
622
  request: () => mod.Camera.requestCameraPermissionsAsync()
545
623
  } : null;
546
624
  }
547
625
  case "location": {
548
- const mod = await (0, import_core11.tryImport)("expo-location");
626
+ let mod = null;
627
+ try {
628
+ mod = require("expo-location");
629
+ } catch {
630
+ }
549
631
  return mod ? {
550
632
  check: () => mod.getForegroundPermissionsAsync(),
551
633
  request: () => mod.requestForegroundPermissionsAsync()
552
634
  } : null;
553
635
  }
554
636
  case "notifications": {
555
- const mod = await (0, import_core11.tryImport)("expo-notifications");
637
+ let mod = null;
638
+ try {
639
+ mod = require("expo-notifications");
640
+ } catch {
641
+ }
556
642
  return mod ? {
557
643
  check: () => mod.getPermissionsAsync(),
558
644
  request: () => mod.requestPermissionsAsync()
@@ -564,7 +650,7 @@ async function getPermissionModule(permission) {
564
650
  }
565
651
  var permissionHandlers = {
566
652
  "permission.check": async (payload) => {
567
- const mod = await getPermissionModule(payload.permission);
653
+ const mod = getPermissionModule(payload.permission);
568
654
  if (!mod) {
569
655
  return { status: "undetermined", canAskAgain: true };
570
656
  }
@@ -579,7 +665,7 @@ var permissionHandlers = {
579
665
  }
580
666
  },
581
667
  "permission.request": async (payload) => {
582
- const mod = await getPermissionModule(payload.permission);
668
+ const mod = getPermissionModule(payload.permission);
583
669
  if (!mod) {
584
670
  return { status: "undetermined", canAskAgain: true };
585
671
  }
@@ -604,28 +690,43 @@ var permissionHandlers = {
604
690
  };
605
691
 
606
692
  // src/handlers/preference.ts
607
- var import_core12 = require("@rn-bridge-tools/core");
608
693
  var preferenceHandlers = {
609
694
  "preference.get": async (payload) => {
610
- const mod = await (0, import_core12.tryImport)("@react-native-async-storage/async-storage");
695
+ let mod = null;
696
+ try {
697
+ mod = require("@react-native-async-storage/async-storage");
698
+ } catch {
699
+ }
611
700
  if (!mod) return { value: null };
612
701
  const value = await mod.default.getItem(payload.key);
613
702
  return { value };
614
703
  },
615
704
  "preference.set": async (payload) => {
616
- const mod = await (0, import_core12.tryImport)("@react-native-async-storage/async-storage");
705
+ let mod = null;
706
+ try {
707
+ mod = require("@react-native-async-storage/async-storage");
708
+ } catch {
709
+ }
617
710
  if (!mod) return { success: false };
618
711
  await mod.default.setItem(payload.key, payload.value);
619
712
  return { success: true };
620
713
  },
621
714
  "preference.remove": async (payload) => {
622
- const mod = await (0, import_core12.tryImport)("@react-native-async-storage/async-storage");
715
+ let mod = null;
716
+ try {
717
+ mod = require("@react-native-async-storage/async-storage");
718
+ } catch {
719
+ }
623
720
  if (!mod) return { success: false };
624
721
  await mod.default.removeItem(payload.key);
625
722
  return { success: true };
626
723
  },
627
724
  "preference.clear": async (_payload) => {
628
- const mod = await (0, import_core12.tryImport)("@react-native-async-storage/async-storage");
725
+ let mod = null;
726
+ try {
727
+ mod = require("@react-native-async-storage/async-storage");
728
+ } catch {
729
+ }
629
730
  if (!mod) return { success: false };
630
731
  await mod.default.clear();
631
732
  return { success: true };
@@ -649,7 +750,6 @@ var navigationHandlers = {
649
750
  };
650
751
 
651
752
  // src/handlers/browser.ts
652
- var import_core13 = require("@rn-bridge-tools/core");
653
753
  var import_react_native7 = require("react-native");
654
754
  var browserHandlers = {
655
755
  "browser.openExternal": async (payload) => {
@@ -661,8 +761,12 @@ var browserHandlers = {
661
761
  }
662
762
  },
663
763
  "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");
764
+ let WebBrowser = null;
765
+ try {
766
+ WebBrowser = require("expo-web-browser");
767
+ } catch {
768
+ }
769
+ if (!WebBrowser) return { success: false, error: "MODULE_NOT_INSTALLED: expo-web-browser" };
666
770
  try {
667
771
  await WebBrowser.openBrowserAsync(payload.url, {
668
772
  showTitle: payload.showTitle,