ordering-ui-react-native 0.23.52 → 0.23.55

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ordering-ui-react-native",
3
- "version": "0.23.52",
3
+ "version": "0.23.55",
4
4
  "description": "Reusable components made in react native",
5
5
  "main": "src/index.tsx",
6
6
  "author": "ordering.inc",
@@ -140,7 +140,8 @@ const NewOrderNotificationUI = (props: any) => {
140
140
  location: JSON.stringify({
141
141
  location: `{
142
142
  lat: ${location.latitude},
143
- lng: ${location.longitude}
143
+ lng: ${location.longitude},
144
+ mock: ${location.mocked}
144
145
  }`
145
146
  })
146
147
  }),
@@ -1,24 +1,26 @@
1
1
  import { useEffect, useState, useRef } from 'react';
2
2
  import GeoLocation from 'react-native-geolocation-service';
3
3
  import { Location } from '../types';
4
- import {useApi, useSession, useLanguage} from 'ordering-components/native'
4
+ import { useApi, useSession, useLanguage } from 'ordering-components/native'
5
5
 
6
6
  export const useLocation = () => {
7
- const [,t] = useLanguage()
7
+ const [, t] = useLanguage()
8
8
  const [ordering] = useApi()
9
- const [{token, user}] = useSession()
9
+ const [{ token, user }] = useSession()
10
10
  const [hasLocation, setHasLocation] = useState(false);
11
11
  const [initialPosition, setInitialPosition] = useState<Location>({
12
12
  longitude: 0,
13
13
  latitude: 0,
14
14
  speed: 0,
15
+ mocked: false
15
16
  });
16
17
  const [userLocation, setUserLocation] = useState<Location>({
17
18
  longitude: 0,
18
19
  latitude: 0,
19
20
  speed: 0,
21
+ mocked: false
20
22
  });
21
- const [newLocation,setNewLocation] = useState<any>({ loading: false, error: null, newLocation: null })
23
+ const [newLocation, setNewLocation] = useState<any>({ loading: false, error: null, newLocation: null })
22
24
  const [routeLines, setRoutesLines] = useState<Location[]>([]);
23
25
  const isMounted = useRef(true);
24
26
 
@@ -37,7 +39,7 @@ export const useLocation = () => {
37
39
  if (!isMounted.current) return;
38
40
  setInitialPosition(location);
39
41
  setUserLocation(location);
40
- setRoutesLines(routes => [...routes, location]);
42
+ setRoutesLines((routes: any) => [...routes, location]);
41
43
  setHasLocation(true);
42
44
  })
43
45
  .catch(err => console.log(err));
@@ -46,14 +48,15 @@ export const useLocation = () => {
46
48
  const getCurrentLocation = (): Promise<Location> => {
47
49
  return new Promise((resolve, reject) => {
48
50
  GeoLocation.getCurrentPosition(
49
- ({ coords }) => {
51
+ ({ coords, mocked }: any) => {
50
52
  resolve({
51
53
  latitude: typeof coords.latitude === 'number' && !Number.isNaN(coords.latitude) ? coords.latitude : 0,
52
54
  longitude: typeof coords.longitude === 'number' && !Number.isNaN(coords.longitude) ? coords.longitude : 0,
53
55
  speed: coords.speed,
56
+ mocked
54
57
  });
55
58
  },
56
- err => reject({ err }),
59
+ (err: any) => reject({ err }),
57
60
  { enableHighAccuracy: true, timeout: 15000, maximumAge: 10000 },
58
61
  );
59
62
  });
@@ -61,18 +64,19 @@ export const useLocation = () => {
61
64
 
62
65
  const followUserLocation = () => {
63
66
  watchId.current = GeoLocation.watchPosition(
64
- ({ coords }) => {
67
+ ({ coords, mocked }: any) => {
65
68
  if (!isMounted.current) return;
66
69
  if (typeof coords.latitude !== 'number' || typeof coords.longitude !== 'number') return
67
70
  const location: Location = {
68
71
  latitude: coords.latitude || 0,
69
72
  longitude: coords.longitude || 0,
70
73
  speed: coords.speed,
74
+ mocked
71
75
  };
72
76
  setUserLocation(location);
73
- setRoutesLines(routes => [...routes, location]);
77
+ setRoutesLines((routes: any) => [...routes, location]);
74
78
  },
75
- err => console.log(err),
79
+ (err: any) => console.log(err),
76
80
  { enableHighAccuracy: true, distanceFilter: 3 },
77
81
  );
78
82
  };
@@ -83,14 +87,14 @@ export const useLocation = () => {
83
87
 
84
88
  const updateDriverPosition = async (newLocation = {}) => {
85
89
  try {
86
- setNewLocation({...newLocation, loading: true})
90
+ setNewLocation({ ...newLocation, loading: true })
87
91
  const { content: { error, result } } = await ordering.setAccessToken(token).users(user?.id).driverLocations().save(newLocation)
88
92
  if (error) {
89
93
  setNewLocation({ ...newLocation, loading: false, error: [result[0] || result || t('ERROR_UPDATING_POSITION', 'Error updating position')] })
90
94
  } else {
91
95
  setNewLocation({ ...newLocation, loading: false, newLocation: { ...newLocation, ...result } })
92
96
  }
93
- } catch (error : any) {
97
+ } catch (error: any) {
94
98
  setNewLocation({ ...newLocation, loading: false, error: [error?.message || t('NETWORK_ERROR', 'Network Error')] })
95
99
  }
96
100
  }
@@ -541,6 +541,7 @@ export interface Location {
541
541
  latitude: number;
542
542
  longitude: number;
543
543
  speed: number;
544
+ mocked?: boolean;
544
545
  }
545
546
 
546
547
  export interface GoogleMapsParams {
@@ -476,15 +476,6 @@ const CheckoutUI = (props: any) => {
476
476
  }
477
477
  }, [cartState?.error, cartState?.cart, cartState?.loading, isFocused])
478
478
 
479
- useEffect(() => {
480
- const keyboardDidShowListener = Keyboard.addListener('keyboardDidShow', () => {
481
- containerRef?.current?.scrollToEnd && containerRef.current.scrollToEnd({ animated: true })
482
- })
483
- return () => {
484
- keyboardDidShowListener.remove()
485
- }
486
- }, [])
487
-
488
479
  useEffect(() => {
489
480
  const onBackFunction = () => {
490
481
  if (webviewPaymethod?.gateway === 'paypal' && showGateway.open) {