@situm/react-native 3.7.6 → 3.9.0-beta.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.
Files changed (59) hide show
  1. package/ios/RNSitumReactNativePlugin.xcodeproj/project.xcworkspace/contents.xcworkspacedata +7 -0
  2. package/ios/RNSitumReactNativePlugin.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist +8 -0
  3. package/ios/RNSitumReactNativePlugin.xcodeproj/project.xcworkspace/xcuserdata/situm.xcuserdatad/UserInterfaceState.xcuserstate +0 -0
  4. package/ios/RNSitumReactNativePlugin.xcodeproj/xcuserdata/situm.xcuserdatad/xcschemes/xcschememanagement.plist +14 -0
  5. package/lib/commonjs/sdk/types/constants.js +0 -2
  6. package/lib/commonjs/sdk/types/constants.js.map +1 -1
  7. package/lib/commonjs/sdk/types/index.js +0 -1
  8. package/lib/commonjs/sdk/types/index.js.map +1 -1
  9. package/lib/commonjs/utils/index.js +0 -11
  10. package/lib/commonjs/utils/index.js.map +1 -1
  11. package/lib/commonjs/wayfinding/components/MapView.js +56 -15
  12. package/lib/commonjs/wayfinding/components/MapView.js.map +1 -1
  13. package/lib/commonjs/wayfinding/hooks/index.js +11 -9
  14. package/lib/commonjs/wayfinding/hooks/index.js.map +1 -1
  15. package/lib/commonjs/wayfinding/store/index.js +4 -10
  16. package/lib/commonjs/wayfinding/store/index.js.map +1 -1
  17. package/lib/commonjs/wayfinding/utils/mapper.js +6 -2
  18. package/lib/commonjs/wayfinding/utils/mapper.js.map +1 -1
  19. package/lib/module/sdk/types/constants.js +0 -2
  20. package/lib/module/sdk/types/constants.js.map +1 -1
  21. package/lib/module/sdk/types/index.js +0 -1
  22. package/lib/module/sdk/types/index.js.map +1 -1
  23. package/lib/module/utils/index.js +0 -1
  24. package/lib/module/utils/index.js.map +1 -1
  25. package/lib/module/wayfinding/components/MapView.js +56 -15
  26. package/lib/module/wayfinding/components/MapView.js.map +1 -1
  27. package/lib/module/wayfinding/hooks/index.js +13 -11
  28. package/lib/module/wayfinding/hooks/index.js.map +1 -1
  29. package/lib/module/wayfinding/store/index.js +4 -10
  30. package/lib/module/wayfinding/store/index.js.map +1 -1
  31. package/lib/module/wayfinding/utils/mapper.js +6 -2
  32. package/lib/module/wayfinding/utils/mapper.js.map +1 -1
  33. package/lib/typescript/src/sdk/types/constants.d.ts +0 -2
  34. package/lib/typescript/src/sdk/types/constants.d.ts.map +1 -1
  35. package/lib/typescript/src/sdk/types/index.d.ts +0 -2
  36. package/lib/typescript/src/sdk/types/index.d.ts.map +1 -1
  37. package/lib/typescript/src/utils/index.d.ts +0 -1
  38. package/lib/typescript/src/utils/index.d.ts.map +1 -1
  39. package/lib/typescript/src/wayfinding/components/MapView.d.ts.map +1 -1
  40. package/lib/typescript/src/wayfinding/hooks/index.d.ts.map +1 -1
  41. package/lib/typescript/src/wayfinding/store/index.d.ts +1 -0
  42. package/lib/typescript/src/wayfinding/store/index.d.ts.map +1 -1
  43. package/lib/typescript/src/wayfinding/utils/mapper.d.ts +3 -1
  44. package/lib/typescript/src/wayfinding/utils/mapper.d.ts.map +1 -1
  45. package/package.json +1 -2
  46. package/src/sdk/types/constants.ts +4 -4
  47. package/src/sdk/types/index.ts +0 -2
  48. package/src/utils/index.ts +0 -1
  49. package/src/wayfinding/components/MapView.tsx +77 -20
  50. package/src/wayfinding/hooks/index.ts +9 -15
  51. package/src/wayfinding/store/index.tsx +6 -4
  52. package/src/wayfinding/utils/mapper.ts +5 -3
  53. package/lib/commonjs/utils/requestPermission.js +0 -54
  54. package/lib/commonjs/utils/requestPermission.js.map +0 -1
  55. package/lib/module/utils/requestPermission.js +0 -48
  56. package/lib/module/utils/requestPermission.js.map +0 -1
  57. package/lib/typescript/src/utils/requestPermission.d.ts +0 -3
  58. package/lib/typescript/src/utils/requestPermission.d.ts.map +0 -1
  59. package/src/utils/requestPermission.ts +0 -83
@@ -1,2 +1 @@
1
1
  export * from "./logError";
2
- export * from "./requestPermission";
@@ -20,7 +20,11 @@ import type {
20
20
  WebViewMessageEvent,
21
21
  } from "react-native-webview/lib/WebViewTypes";
22
22
 
23
- import SitumPlugin from "../../sdk";
23
+ import SitumPlugin, {
24
+ type Error,
25
+ type LocationStatus,
26
+ LocationStatusName,
27
+ } from "../../sdk";
24
28
  import useSitum from "../hooks";
25
29
  import {
26
30
  type MapViewDirectionsOptions,
@@ -157,6 +161,8 @@ const MapView = React.forwardRef<MapViewRef, MapViewProps>(
157
161
  useState<OnDirectionsRequestInterceptor>();
158
162
 
159
163
  // Local states
164
+ const [locationStatus, setLocationStatus] = useState<LocationStatusName>();
165
+ const [locationError, setLocationError] = useState<string>();
160
166
  const [mapLoaded, setMapLoaded] = useState<boolean>(false);
161
167
  const [buildingIdentifier, setBuildingIdentifier] = useState<string>(
162
168
  configuration.buildingIdentifier
@@ -164,10 +170,8 @@ const MapView = React.forwardRef<MapViewRef, MapViewProps>(
164
170
  const {
165
171
  init,
166
172
  location,
167
- locationStatus,
168
173
  directions,
169
174
  navigation,
170
-
171
175
  calculateRoute,
172
176
  startNavigation,
173
177
  stopNavigation,
@@ -266,6 +270,22 @@ const MapView = React.forwardRef<MapViewRef, MapViewProps>(
266
270
  );
267
271
  }, []);
268
272
 
273
+ const _onMapIsReady = () => {
274
+ if (locationStatus) {
275
+ sendMessageToViewer(
276
+ webViewRef.current,
277
+ ViewerMapper.locationStatus(locationStatus)
278
+ );
279
+ }
280
+ if (locationError) {
281
+ // Right now, status and errors share message on the viewer:
282
+ sendMessageToViewer(
283
+ webViewRef.current,
284
+ ViewerMapper.locationError(locationError)
285
+ );
286
+ }
287
+ };
288
+
269
289
  /**
270
290
  * API exported to the outside world from the MapViewer
271
291
  *
@@ -351,6 +371,24 @@ const MapView = React.forwardRef<MapViewRef, MapViewProps>(
351
371
  ]
352
372
  );
353
373
 
374
+ useEffect(() => {
375
+ SitumPlugin.onLocationStatus((status: LocationStatus) => {
376
+ // TODO: implement status & error adapter on native SDKs.
377
+ let finalStatus = status.statusName as string;
378
+ if (Platform.OS === "ios" && finalStatus === "CALCULATING") {
379
+ finalStatus = "STARTING";
380
+ }
381
+ if (finalStatus in LocationStatusName) {
382
+ setLocationStatus(finalStatus as LocationStatusName);
383
+ }
384
+ });
385
+ SitumPlugin.onLocationError((e: Error) => {
386
+ setLocationError(e.code);
387
+ });
388
+
389
+ return () => {};
390
+ }, []);
391
+
354
392
  useEffect(() => {
355
393
  if (!error) return;
356
394
 
@@ -363,27 +401,55 @@ const MapView = React.forwardRef<MapViewRef, MapViewProps>(
363
401
 
364
402
  // Updated SDK location
365
403
  useEffect(() => {
366
- if (!webViewRef.current || !location) return;
404
+ if (!webViewRef.current || !location || !mapLoaded) return;
367
405
 
368
406
  sendMessageToViewer(webViewRef.current, ViewerMapper.location(location));
369
- }, [location]);
407
+ }, [location, mapLoaded]);
408
+
409
+ // locationStatus
410
+ useEffect(() => {
411
+ if (!webViewRef.current || !locationStatus || !mapLoaded) return;
412
+
413
+ sendMessageToViewer(
414
+ webViewRef.current,
415
+ ViewerMapper.locationStatus(locationStatus)
416
+ );
417
+ // Callbacks used in `useEffect` won't be invoked if the value of locationStatus
418
+ // is set but hasn't changed. Set locationStatus to null always to avoid missing
419
+ // repeated messages.
420
+ setLocationStatus(null);
421
+ }, [locationStatus, mapLoaded]);
422
+
423
+ // locationError
424
+ useEffect(() => {
425
+ if (!webViewRef.current || !locationError || !mapLoaded) return;
426
+
427
+ sendMessageToViewer(
428
+ webViewRef.current,
429
+ ViewerMapper.locationError(locationError)
430
+ );
431
+ // Callbacks used in `useEffect` won't be invoked if the value of locationStatus
432
+ // is set but hasn't changed. Set locationStatus to null always to avoid missing
433
+ // repeated messages.
434
+ setLocationError(null);
435
+ }, [locationError, mapLoaded]);
370
436
 
371
437
  // Updated SDK navigation
372
438
  useEffect(() => {
373
- if (!webViewRef.current || !navigation) return;
439
+ if (!webViewRef.current || !navigation || !mapLoaded) return;
374
440
 
375
441
  sendMessageToViewer(
376
442
  webViewRef.current,
377
443
  ViewerMapper.navigation(navigation)
378
444
  );
379
- }, [navigation]);
445
+ }, [navigation, mapLoaded]);
380
446
 
381
447
  // Updated SDK route
382
448
  useEffect(() => {
383
- if (!webViewRef.current || !directions) return;
449
+ if (!webViewRef.current || !directions || !mapLoaded) return;
384
450
 
385
451
  sendMessageToViewer(webViewRef.current, ViewerMapper.route(directions));
386
- }, [directions]);
452
+ }, [directions, mapLoaded]);
387
453
 
388
454
  // Update language
389
455
  useEffect(() => {
@@ -411,23 +477,14 @@ const MapView = React.forwardRef<MapViewRef, MapViewProps>(
411
477
  // eslint-disable-next-line react-hooks/exhaustive-deps
412
478
  }, [mapLoaded]);
413
479
 
414
- //locationStatus
415
- useEffect(() => {
416
- if (!webViewRef.current || !locationStatus || !mapLoaded) return;
417
-
418
- sendMessageToViewer(
419
- webViewRef.current,
420
- ViewerMapper.locationStatus(locationStatus)
421
- );
422
- }, [locationStatus, mapLoaded]);
423
-
424
480
  const handleRequestFromViewer = (event: WebViewMessageEvent) => {
425
481
  const eventParsed = JSON.parse(event.nativeEvent.data);
426
482
  switch (eventParsed.type) {
427
483
  case "app.map_is_ready":
428
484
  init();
429
- onLoad && onLoad("");
430
485
  setMapLoaded(true);
486
+ _onMapIsReady();
487
+ onLoad && onLoad("");
431
488
  break;
432
489
  case "directions.requested":
433
490
  calculateRoute(eventParsed.payload, _onDirectionsRequestInterceptor);
@@ -8,11 +8,9 @@ import {
8
8
  ErrorCode,
9
9
  ErrorType,
10
10
  type Location,
11
- type LocationStatus,
12
11
  type NavigationProgress,
13
12
  } from "../../sdk/types";
14
13
  import {
15
- LocationStatusName,
16
14
  NavigationStatus,
17
15
  NavigationUpdateType,
18
16
  } from "../../sdk/types/constants";
@@ -26,7 +24,6 @@ import {
26
24
  setDirections,
27
25
  setError,
28
26
  setLocation,
29
- setLocationStatus,
30
27
  setNavigation,
31
28
  UseSitumContext,
32
29
  } from "../store/index";
@@ -69,18 +66,15 @@ export const useSitumInternal = () => {
69
66
  );
70
67
  });
71
68
 
72
- SitumPlugin.onLocationStatus((status: LocationStatus) => {
73
- if (status.statusName in LocationStatusName) {
74
- console.debug(
75
- `Situm > hook > Positioning state updated ${status.statusName}`
76
- );
77
- dispatch(setLocationStatus(status.statusName as LocationStatusName));
78
- }
79
- });
80
-
81
- SitumPlugin.onLocationError((err: Error) => {
82
- console.error(`Situm > hook > Error while positioning: ${err}}`);
83
- });
69
+ // TODO: not working, using local state at MapView.tsx.
70
+ // SitumPlugin.onLocationStatus((status: LocationStatus) => {
71
+ // if (status.statusName in LocationStatusName) {
72
+ // console.debug(
73
+ // `Situm > hook > Positioning state updated ${status.statusName}`
74
+ // );
75
+ // dispatch(setLocationStatus(status.statusName as LocationStatusName));
76
+ // }
77
+ // });
84
78
 
85
79
  SitumPlugin.onLocationStopped(() => {
86
80
  console.debug("Situm > hook > Stopped positioning");
@@ -23,6 +23,7 @@ export interface State {
23
23
  sdkInitialized: boolean;
24
24
  user?: User;
25
25
  location?: Location;
26
+ locationStatus?: LocationStatusName;
26
27
  buildings: Building[] | null;
27
28
  currentBuilding: Building;
28
29
  pois: Poi[];
@@ -37,7 +38,8 @@ export const initialState: State = {
37
38
  webViewRef: undefined,
38
39
  sdkInitialized: false,
39
40
  user: undefined,
40
- location: { status: LocationStatusName.STOPPED },
41
+ location: null,
42
+ locationStatus: null,
41
43
  buildings: null,
42
44
  currentBuilding: undefined,
43
45
  pois: [],
@@ -67,8 +69,8 @@ const store = createStore<State>({
67
69
  setLocation: (state: State, payload: State["location"]) => {
68
70
  return { ...state, location: payload };
69
71
  },
70
- setLocationStatus: (state: State, payload: LocationStatusName) => {
71
- return { ...state, location: { ...state.location, status: payload } };
72
+ setLocationStatus: (state: State, payload: State["locationStatus"]) => {
73
+ return { ...state, locationStatus: payload };
72
74
  },
73
75
  resetLocation: (state: State) => {
74
76
  return {
@@ -123,7 +125,7 @@ export const selectLocation = (state: State) => {
123
125
  };
124
126
 
125
127
  export const selectLocationStatus = (state: State) => {
126
- return state.location?.status;
128
+ return state.locationStatus;
127
129
  };
128
130
 
129
131
  export const selectBuildings = (state: State) => {
@@ -1,5 +1,5 @@
1
1
  /* eslint-disable @typescript-eslint/no-explicit-any */
2
- import { AccessibilityMode } from "../../sdk";
2
+ import { AccessibilityMode, LocationStatusName } from "../../sdk";
3
3
  import type {
4
4
  Directions,
5
5
  DirectionsRequest,
@@ -128,12 +128,14 @@ const ViewerMapper = {
128
128
  accuracy: location.accuracy,
129
129
  hasBearing: location.hasBearing,
130
130
  }),
131
- status: location.status,
132
131
  });
133
132
  },
134
- locationStatus: (locationStatus: Location["status"]) => {
133
+ locationStatus: (locationStatus: LocationStatusName) => {
135
134
  return mapperWrapper("location.update_status", { status: locationStatus });
136
135
  },
136
+ locationError: (errorCode: string) => {
137
+ return mapperWrapper("location.update_status", { status: errorCode });
138
+ },
137
139
  // Directions
138
140
  route: (directions: Directions) => {
139
141
  return mapperWrapper("directions.update", directions);
@@ -1,54 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.requestPermission = exports.default = void 0;
7
- var _reactNative = require("react-native");
8
- var _reactNativePermissions = require("react-native-permissions");
9
- // TODO: can requestMultiple be used ?
10
- const checkIOSPermissions = async () => {
11
- const granted = await (0, _reactNativePermissions.request)(_reactNativePermissions.PERMISSIONS.IOS.LOCATION_WHEN_IN_USE);
12
-
13
- // Check if already denied
14
- if (granted !== _reactNativePermissions.RESULTS.GRANTED) {
15
- throw "Situm > permissions > ACCESS_FINE_LOCATION denied";
16
- }
17
- console.debug("Situm > permissions > LOCATION_WHEN_IN_USE permission granted");
18
- return true;
19
- };
20
- const checkAndroidPermissions = async () => {
21
- let granted;
22
-
23
- //@ts-ignore
24
- if (_reactNative.Platform.Version <= 30) {
25
- console.debug("Situm > permissions > ANDROID VERSION < 30");
26
- granted = await (0, _reactNativePermissions.request)(_reactNativePermissions.PERMISSIONS.ANDROID.ACCESS_FINE_LOCATION);
27
- if (granted === _reactNativePermissions.RESULTS.GRANTED) {
28
- console.debug("Situm > permissions > ACCESS_FINE_LOCATION granted");
29
- return true;
30
- } else {
31
- throw "Situm > permissions > ACCESS_FINE_LOCATION permission not granted";
32
- }
33
- }
34
- console.debug("Situm > permissions > ANDROID VERSION > 30");
35
- granted = await (0, _reactNativePermissions.requestMultiple)([_reactNativePermissions.PERMISSIONS.ANDROID.ACCESS_FINE_LOCATION, _reactNativePermissions.PERMISSIONS.ANDROID.BLUETOOTH_CONNECT, _reactNativePermissions.PERMISSIONS.ANDROID.BLUETOOTH_SCAN]);
36
- if (granted["android.permission.ACCESS_FINE_LOCATION"] === _reactNativePermissions.RESULTS.GRANTED && granted["android.permission.BLUETOOTH_CONNECT"] === _reactNativePermissions.RESULTS.GRANTED && granted["android.permission.BLUETOOTH_SCAN"] === _reactNativePermissions.RESULTS.GRANTED) {
37
- console.debug("Situm > permissions > ACCESS_FINE_LOCATION, BLUETOOTH_CONNECT and BLUETOOTH_SCAN permissions granted");
38
- return true;
39
- }
40
- throw "Situm > permissions > ACCESS_FINE_LOCATION, BLUETOOTH_CONNECT or BLUETOOTH_SCAN permissions not granted";
41
- };
42
- const requestPermission = async () => {
43
- console.debug("Situm > permissions > Retrieving permissions for platform " + _reactNative.Platform.OS);
44
- if (!["ios", "android"].includes(_reactNative.Platform.OS)) {
45
- throw `Situm > permissions > Platform '${_reactNative.Platform.OS}' not supported`;
46
- }
47
- return await (_reactNative.Platform.OS === "ios" ? checkIOSPermissions() : checkAndroidPermissions()).then(() => null).catch(e => {
48
- console.warn(e);
49
- throw e;
50
- });
51
- };
52
- exports.requestPermission = requestPermission;
53
- var _default = exports.default = requestPermission;
54
- //# sourceMappingURL=requestPermission.js.map
@@ -1 +0,0 @@
1
- {"version":3,"names":["_reactNative","require","_reactNativePermissions","checkIOSPermissions","granted","request","PERMISSIONS","IOS","LOCATION_WHEN_IN_USE","RESULTS","GRANTED","console","debug","checkAndroidPermissions","Platform","Version","ANDROID","ACCESS_FINE_LOCATION","requestMultiple","BLUETOOTH_CONNECT","BLUETOOTH_SCAN","requestPermission","OS","includes","then","catch","e","warn","exports","_default","default"],"sourceRoot":"../../../src","sources":["utils/requestPermission.ts"],"mappings":";;;;;;AAAA,IAAAA,YAAA,GAAAC,OAAA;AACA,IAAAC,uBAAA,GAAAD,OAAA;AAOA;AACA,MAAME,mBAAmB,GAAG,MAAAA,CAAA,KAAY;EACtC,MAAMC,OAAO,GAAG,MAAM,IAAAC,+BAAO,EAACC,mCAAW,CAACC,GAAG,CAACC,oBAAoB,CAAC;;EAEnE;EACA,IAAIJ,OAAO,KAAKK,+BAAO,CAACC,OAAO,EAAE;IAC/B,MAAM,mDAAmD;EAC3D;EAEAC,OAAO,CAACC,KAAK,CACX,+DACF,CAAC;EAED,OAAO,IAAI;AACb,CAAC;AAED,MAAMC,uBAAuB,GAAG,MAAAA,CAAA,KAAY;EAC1C,IAAIT,OAAO;;EAEX;EACA,IAAIU,qBAAQ,CAACC,OAAO,IAAI,EAAE,EAAE;IAC1BJ,OAAO,CAACC,KAAK,CAAC,4CAA4C,CAAC;IAE3DR,OAAO,GAAG,MAAM,IAAAC,+BAAO,EAACC,mCAAW,CAACU,OAAO,CAACC,oBAAoB,CAAC;IAEjE,IAAIb,OAAO,KAAKK,+BAAO,CAACC,OAAO,EAAE;MAC/BC,OAAO,CAACC,KAAK,CAAC,oDAAoD,CAAC;MACnE,OAAO,IAAI;IACb,CAAC,MAAM;MACL,MAAM,mEAAmE;IAC3E;EACF;EAEAD,OAAO,CAACC,KAAK,CAAC,4CAA4C,CAAC;EAC3DR,OAAO,GAAG,MAAM,IAAAc,uCAAe,EAAC,CAC9BZ,mCAAW,CAACU,OAAO,CAACC,oBAAoB,EACxCX,mCAAW,CAACU,OAAO,CAACG,iBAAiB,EACrCb,mCAAW,CAACU,OAAO,CAACI,cAAc,CACnC,CAAC;EAEF,IACEhB,OAAO,CAAC,yCAAyC,CAAC,KAAKK,+BAAO,CAACC,OAAO,IACtEN,OAAO,CAAC,sCAAsC,CAAC,KAAKK,+BAAO,CAACC,OAAO,IACnEN,OAAO,CAAC,mCAAmC,CAAC,KAAKK,+BAAO,CAACC,OAAO,EAChE;IACAC,OAAO,CAACC,KAAK,CACX,sGACF,CAAC;IACD,OAAO,IAAI;EACb;EAEA,MAAM,yGAAyG;AACjH,CAAC;AAEM,MAAMS,iBAAiB,GAAG,MAAAA,CAAA,KAAY;EAC3CV,OAAO,CAACC,KAAK,CACX,4DAA4D,GAAGE,qBAAQ,CAACQ,EAC1E,CAAC;EAED,IAAI,CAAC,CAAC,KAAK,EAAE,SAAS,CAAC,CAACC,QAAQ,CAACT,qBAAQ,CAACQ,EAAE,CAAC,EAAE;IAC7C,MAAO,mCAAkCR,qBAAQ,CAACQ,EAAG,iBAAgB;EACvE;EAEA,OAAO,MAAM,CAACR,qBAAQ,CAACQ,EAAE,KAAK,KAAK,GAC/BnB,mBAAmB,CAAC,CAAC,GACrBU,uBAAuB,CAAC,CAAC,EAE1BW,IAAI,CAAC,MAAM,IAAI,CAAC,CAChBC,KAAK,CAAEC,CAAS,IAAK;IACpBf,OAAO,CAACgB,IAAI,CAACD,CAAC,CAAC;IACf,MAAMA,CAAC;EACT,CAAC,CAAC;AACN,CAAC;AAACE,OAAA,CAAAP,iBAAA,GAAAA,iBAAA;AAAA,IAAAQ,QAAA,GAAAD,OAAA,CAAAE,OAAA,GAEaT,iBAAiB","ignoreList":[]}
@@ -1,48 +0,0 @@
1
- import { Platform } from "react-native";
2
- import { PERMISSIONS, request, requestMultiple, RESULTS } from "react-native-permissions";
3
-
4
- // TODO: can requestMultiple be used ?
5
- const checkIOSPermissions = async () => {
6
- const granted = await request(PERMISSIONS.IOS.LOCATION_WHEN_IN_USE);
7
-
8
- // Check if already denied
9
- if (granted !== RESULTS.GRANTED) {
10
- throw "Situm > permissions > ACCESS_FINE_LOCATION denied";
11
- }
12
- console.debug("Situm > permissions > LOCATION_WHEN_IN_USE permission granted");
13
- return true;
14
- };
15
- const checkAndroidPermissions = async () => {
16
- let granted;
17
-
18
- //@ts-ignore
19
- if (Platform.Version <= 30) {
20
- console.debug("Situm > permissions > ANDROID VERSION < 30");
21
- granted = await request(PERMISSIONS.ANDROID.ACCESS_FINE_LOCATION);
22
- if (granted === RESULTS.GRANTED) {
23
- console.debug("Situm > permissions > ACCESS_FINE_LOCATION granted");
24
- return true;
25
- } else {
26
- throw "Situm > permissions > ACCESS_FINE_LOCATION permission not granted";
27
- }
28
- }
29
- console.debug("Situm > permissions > ANDROID VERSION > 30");
30
- granted = await requestMultiple([PERMISSIONS.ANDROID.ACCESS_FINE_LOCATION, PERMISSIONS.ANDROID.BLUETOOTH_CONNECT, PERMISSIONS.ANDROID.BLUETOOTH_SCAN]);
31
- if (granted["android.permission.ACCESS_FINE_LOCATION"] === RESULTS.GRANTED && granted["android.permission.BLUETOOTH_CONNECT"] === RESULTS.GRANTED && granted["android.permission.BLUETOOTH_SCAN"] === RESULTS.GRANTED) {
32
- console.debug("Situm > permissions > ACCESS_FINE_LOCATION, BLUETOOTH_CONNECT and BLUETOOTH_SCAN permissions granted");
33
- return true;
34
- }
35
- throw "Situm > permissions > ACCESS_FINE_LOCATION, BLUETOOTH_CONNECT or BLUETOOTH_SCAN permissions not granted";
36
- };
37
- export const requestPermission = async () => {
38
- console.debug("Situm > permissions > Retrieving permissions for platform " + Platform.OS);
39
- if (!["ios", "android"].includes(Platform.OS)) {
40
- throw `Situm > permissions > Platform '${Platform.OS}' not supported`;
41
- }
42
- return await (Platform.OS === "ios" ? checkIOSPermissions() : checkAndroidPermissions()).then(() => null).catch(e => {
43
- console.warn(e);
44
- throw e;
45
- });
46
- };
47
- export default requestPermission;
48
- //# sourceMappingURL=requestPermission.js.map
@@ -1 +0,0 @@
1
- {"version":3,"names":["Platform","PERMISSIONS","request","requestMultiple","RESULTS","checkIOSPermissions","granted","IOS","LOCATION_WHEN_IN_USE","GRANTED","console","debug","checkAndroidPermissions","Version","ANDROID","ACCESS_FINE_LOCATION","BLUETOOTH_CONNECT","BLUETOOTH_SCAN","requestPermission","OS","includes","then","catch","e","warn"],"sourceRoot":"../../../src","sources":["utils/requestPermission.ts"],"mappings":"AAAA,SAASA,QAAQ,QAAQ,cAAc;AACvC,SACEC,WAAW,EACXC,OAAO,EACPC,eAAe,EACfC,OAAO,QACF,0BAA0B;;AAEjC;AACA,MAAMC,mBAAmB,GAAG,MAAAA,CAAA,KAAY;EACtC,MAAMC,OAAO,GAAG,MAAMJ,OAAO,CAACD,WAAW,CAACM,GAAG,CAACC,oBAAoB,CAAC;;EAEnE;EACA,IAAIF,OAAO,KAAKF,OAAO,CAACK,OAAO,EAAE;IAC/B,MAAM,mDAAmD;EAC3D;EAEAC,OAAO,CAACC,KAAK,CACX,+DACF,CAAC;EAED,OAAO,IAAI;AACb,CAAC;AAED,MAAMC,uBAAuB,GAAG,MAAAA,CAAA,KAAY;EAC1C,IAAIN,OAAO;;EAEX;EACA,IAAIN,QAAQ,CAACa,OAAO,IAAI,EAAE,EAAE;IAC1BH,OAAO,CAACC,KAAK,CAAC,4CAA4C,CAAC;IAE3DL,OAAO,GAAG,MAAMJ,OAAO,CAACD,WAAW,CAACa,OAAO,CAACC,oBAAoB,CAAC;IAEjE,IAAIT,OAAO,KAAKF,OAAO,CAACK,OAAO,EAAE;MAC/BC,OAAO,CAACC,KAAK,CAAC,oDAAoD,CAAC;MACnE,OAAO,IAAI;IACb,CAAC,MAAM;MACL,MAAM,mEAAmE;IAC3E;EACF;EAEAD,OAAO,CAACC,KAAK,CAAC,4CAA4C,CAAC;EAC3DL,OAAO,GAAG,MAAMH,eAAe,CAAC,CAC9BF,WAAW,CAACa,OAAO,CAACC,oBAAoB,EACxCd,WAAW,CAACa,OAAO,CAACE,iBAAiB,EACrCf,WAAW,CAACa,OAAO,CAACG,cAAc,CACnC,CAAC;EAEF,IACEX,OAAO,CAAC,yCAAyC,CAAC,KAAKF,OAAO,CAACK,OAAO,IACtEH,OAAO,CAAC,sCAAsC,CAAC,KAAKF,OAAO,CAACK,OAAO,IACnEH,OAAO,CAAC,mCAAmC,CAAC,KAAKF,OAAO,CAACK,OAAO,EAChE;IACAC,OAAO,CAACC,KAAK,CACX,sGACF,CAAC;IACD,OAAO,IAAI;EACb;EAEA,MAAM,yGAAyG;AACjH,CAAC;AAED,OAAO,MAAMO,iBAAiB,GAAG,MAAAA,CAAA,KAAY;EAC3CR,OAAO,CAACC,KAAK,CACX,4DAA4D,GAAGX,QAAQ,CAACmB,EAC1E,CAAC;EAED,IAAI,CAAC,CAAC,KAAK,EAAE,SAAS,CAAC,CAACC,QAAQ,CAACpB,QAAQ,CAACmB,EAAE,CAAC,EAAE;IAC7C,MAAO,mCAAkCnB,QAAQ,CAACmB,EAAG,iBAAgB;EACvE;EAEA,OAAO,MAAM,CAACnB,QAAQ,CAACmB,EAAE,KAAK,KAAK,GAC/Bd,mBAAmB,CAAC,CAAC,GACrBO,uBAAuB,CAAC,CAAC,EAE1BS,IAAI,CAAC,MAAM,IAAI,CAAC,CAChBC,KAAK,CAAEC,CAAS,IAAK;IACpBb,OAAO,CAACc,IAAI,CAACD,CAAC,CAAC;IACf,MAAMA,CAAC;EACT,CAAC,CAAC;AACN,CAAC;AAED,eAAeL,iBAAiB","ignoreList":[]}
@@ -1,3 +0,0 @@
1
- export declare const requestPermission: () => Promise<any>;
2
- export default requestPermission;
3
- //# sourceMappingURL=requestPermission.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"requestPermission.d.ts","sourceRoot":"","sources":["../../../../src/utils/requestPermission.ts"],"names":[],"mappings":"AA8DA,eAAO,MAAM,iBAAiB,oBAkB7B,CAAC;AAEF,eAAe,iBAAiB,CAAC"}
@@ -1,83 +0,0 @@
1
- import { Platform } from "react-native";
2
- import {
3
- PERMISSIONS,
4
- request,
5
- requestMultiple,
6
- RESULTS,
7
- } from "react-native-permissions";
8
-
9
- // TODO: can requestMultiple be used ?
10
- const checkIOSPermissions = async () => {
11
- const granted = await request(PERMISSIONS.IOS.LOCATION_WHEN_IN_USE);
12
-
13
- // Check if already denied
14
- if (granted !== RESULTS.GRANTED) {
15
- throw "Situm > permissions > ACCESS_FINE_LOCATION denied";
16
- }
17
-
18
- console.debug(
19
- "Situm > permissions > LOCATION_WHEN_IN_USE permission granted"
20
- );
21
-
22
- return true;
23
- };
24
-
25
- const checkAndroidPermissions = async () => {
26
- let granted;
27
-
28
- //@ts-ignore
29
- if (Platform.Version <= 30) {
30
- console.debug("Situm > permissions > ANDROID VERSION < 30");
31
-
32
- granted = await request(PERMISSIONS.ANDROID.ACCESS_FINE_LOCATION);
33
-
34
- if (granted === RESULTS.GRANTED) {
35
- console.debug("Situm > permissions > ACCESS_FINE_LOCATION granted");
36
- return true;
37
- } else {
38
- throw "Situm > permissions > ACCESS_FINE_LOCATION permission not granted";
39
- }
40
- }
41
-
42
- console.debug("Situm > permissions > ANDROID VERSION > 30");
43
- granted = await requestMultiple([
44
- PERMISSIONS.ANDROID.ACCESS_FINE_LOCATION,
45
- PERMISSIONS.ANDROID.BLUETOOTH_CONNECT,
46
- PERMISSIONS.ANDROID.BLUETOOTH_SCAN,
47
- ]);
48
-
49
- if (
50
- granted["android.permission.ACCESS_FINE_LOCATION"] === RESULTS.GRANTED &&
51
- granted["android.permission.BLUETOOTH_CONNECT"] === RESULTS.GRANTED &&
52
- granted["android.permission.BLUETOOTH_SCAN"] === RESULTS.GRANTED
53
- ) {
54
- console.debug(
55
- "Situm > permissions > ACCESS_FINE_LOCATION, BLUETOOTH_CONNECT and BLUETOOTH_SCAN permissions granted"
56
- );
57
- return true;
58
- }
59
-
60
- throw "Situm > permissions > ACCESS_FINE_LOCATION, BLUETOOTH_CONNECT or BLUETOOTH_SCAN permissions not granted";
61
- };
62
-
63
- export const requestPermission = async () => {
64
- console.debug(
65
- "Situm > permissions > Retrieving permissions for platform " + Platform.OS
66
- );
67
-
68
- if (!["ios", "android"].includes(Platform.OS)) {
69
- throw `Situm > permissions > Platform '${Platform.OS}' not supported`;
70
- }
71
-
72
- return await (Platform.OS === "ios"
73
- ? checkIOSPermissions()
74
- : checkAndroidPermissions()
75
- )
76
- .then(() => null)
77
- .catch((e: string) => {
78
- console.warn(e);
79
- throw e;
80
- });
81
- };
82
-
83
- export default requestPermission;