ordering-ui-react-native 0.21.71-release → 0.21.72-release

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.21.71-release",
3
+ "version": "0.21.72-release",
4
4
  "description": "Reusable components made in react native",
5
5
  "main": "src/index.tsx",
6
6
  "author": "ordering.inc",
@@ -1,4 +1,4 @@
1
- import React, { useState, useEffect, useRef } from 'react';
1
+ import React, { useState, useEffect, useRef, useCallback } from 'react';
2
2
  import { Dimensions, Platform, SafeAreaView, StyleSheet, View } from 'react-native';
3
3
  import MapView, {
4
4
  PROVIDER_GOOGLE,
@@ -69,20 +69,26 @@ export const DriverMap = (props: GoogleMapsParams) => {
69
69
  stopFollowUserLocation,
70
70
  } = useLocation();
71
71
 
72
- const destination = {
73
- latitude: typeof location?.lat === 'string' ? parseFloat(location?.lat) || 0 : location?.lat || 0,
74
- longitude: typeof location?.lng === 'string' ? parseFloat(location?.lng) || 0 : location?.lng || 0
75
- };
72
+ const parsedInitialPosition = useCallback(() => {
73
+ return {
74
+ latitude: typeof initialPosition.latitude === 'string' ? parseFloat(initialPosition.latitude) || 0 : initialPosition.latitude || 0,
75
+ longitude: typeof initialPosition.longitude === 'string' ? parseFloat(initialPosition.longitude) || 0 : initialPosition.longitude || 0,
76
+ }
77
+ }, [JSON.stringify(initialPosition)])
76
78
 
77
- const parsedInitialPosition = {
78
- latitude: typeof initialPosition.latitude === 'string' ? parseFloat(initialPosition.latitude) || 0 : initialPosition.latitude || 0,
79
- longitude: typeof initialPosition.longitude === 'string' ? parseFloat(initialPosition.longitude) || 0 : initialPosition.longitude || 0,
80
- }
79
+ const parsedUserLocation = useCallback(() => {
80
+ return {
81
+ latitude: typeof userLocation?.latitude === 'string' ? parseFloat(userLocation?.latitude) || 0 : userLocation?.latitude || 0,
82
+ longitude: typeof userLocation?.longitude === 'string' ? parseFloat(userLocation?.longitude) || 0 : userLocation?.longitude || 0
83
+ }
84
+ }, [JSON.stringify(userLocation)])
81
85
 
82
- const parsedUserLocation = {
83
- latitude: typeof userLocation?.latitude === 'string' ? parseFloat(userLocation?.latitude) || 0 : userLocation?.latitude || 0,
84
- longitude: typeof userLocation?.longitude === 'string' ? parseFloat(userLocation?.longitude) || 0 : userLocation?.longitude || 0
85
- }
86
+ const parsedDestination = useCallback(() => {
87
+ return {
88
+ latitude: typeof location?.lat === 'string' ? parseFloat(location?.lat) || 0 : location?.lat || 0,
89
+ longitude: typeof location?.lng === 'string' ? parseFloat(location?.lng) || 0 : location?.lng || 0
90
+ }
91
+ }, [JSON.stringify(location)])
86
92
 
87
93
  useEffect(() => {
88
94
  if (isToFollow) {
@@ -170,21 +176,21 @@ export const DriverMap = (props: GoogleMapsParams) => {
170
176
  if (driverUpdateLocation.error) return;
171
177
 
172
178
  calculateDistance(
173
- { lat: parsedUserLocation.latitude, lng: parsedUserLocation.longitude },
174
- destination,
179
+ { lat: parsedUserLocation()?.latitude, lng: parsedUserLocation()?.longitude },
180
+ parsedDestination(),
175
181
  );
176
182
  // geocodePosition(userLocation);
177
183
 
178
184
  if (!following.current) return;
179
185
  fitCoordinates();
180
186
 
181
- const { latitude, longitude } = parsedUserLocation;
187
+ const { latitude, longitude } = parsedUserLocation();
182
188
 
183
189
  mapRef.current?.animateCamera({
184
190
  center: { latitude, longitude },
185
191
  });
186
192
 
187
- }, [parsedUserLocation]);
193
+ }, [JSON.stringify(userLocation)]);
188
194
 
189
195
  const handleArrowBack: any = () => {
190
196
  setDriverUpdateLocation?.({
@@ -250,8 +256,8 @@ export const DriverMap = (props: GoogleMapsParams) => {
250
256
  [
251
257
  { latitude: location.lat, longitude: location.lng },
252
258
  {
253
- latitude: parsedInitialPosition.latitude,
254
- longitude: parsedInitialPosition.longitude,
259
+ latitude: parsedInitialPosition()?.latitude,
260
+ longitude: parsedInitialPosition()?.longitude,
255
261
  },
256
262
  ],
257
263
  {
@@ -264,7 +270,7 @@ export const DriverMap = (props: GoogleMapsParams) => {
264
270
 
265
271
  useEffect(() => {
266
272
  const interval = setInterval(() => {
267
- if (parsedInitialPosition.latitude !== 0 && autoFit.current) {
273
+ if (parsedInitialPosition()?.latitude !== 0 && autoFit.current) {
268
274
  if (mapRef.current) {
269
275
  fitCoordinates();
270
276
  autoFit.current = false;
@@ -272,7 +278,7 @@ export const DriverMap = (props: GoogleMapsParams) => {
272
278
  }
273
279
  }, 1000);
274
280
  return () => clearInterval(interval);
275
- }, [parsedInitialPosition]);
281
+ }, [parsedInitialPosition()]);
276
282
 
277
283
  const fitCoordinatesZoom = () => {
278
284
  following.current = false;
@@ -355,8 +361,8 @@ export const DriverMap = (props: GoogleMapsParams) => {
355
361
  ref={mapRef}
356
362
  provider={PROVIDER_GOOGLE}
357
363
  initialRegion={{
358
- latitude: parsedInitialPosition.latitude,
359
- longitude: parsedInitialPosition.longitude,
364
+ latitude: parsedInitialPosition()?.latitude,
365
+ longitude: parsedInitialPosition()?.longitude,
360
366
  latitudeDelta: 0.001,
361
367
  longitudeDelta: 0.001 * ASPECT_RATIO,
362
368
  }}
@@ -378,8 +384,8 @@ export const DriverMap = (props: GoogleMapsParams) => {
378
384
  <>
379
385
  <Marker
380
386
  coordinate={{
381
- latitude: typeof destination?.latitude !== 'object' ? destination?.latitude : 0,
382
- longitude: typeof destination?.longitude !== 'object' ? destination?.latitude : 0
387
+ latitude: parsedDestination()?.latitude,
388
+ longitude: parsedDestination()?.longitude
383
389
  }}
384
390
  title={location.title}>
385
391
  <Icon
@@ -397,8 +403,8 @@ export const DriverMap = (props: GoogleMapsParams) => {
397
403
  </View>
398
404
  </Marker>
399
405
  <Marker coordinate={{
400
- latitude: typeof parsedUserLocation?.latitude !== 'object' ? parsedUserLocation?.latitude : 0,
401
- longitude: typeof parsedUserLocation?.longitude !== 'object' ? parsedUserLocation?.latitude : 0
406
+ latitude: userLocation?.latitude,
407
+ longitude: userLocation?.longitude
402
408
  }}>
403
409
  <View style={styles.driverIcon}>
404
410
  <OIcon
@@ -413,8 +419,8 @@ export const DriverMap = (props: GoogleMapsParams) => {
413
419
  ) : (
414
420
  <Marker
415
421
  coordinate={{
416
- latitude: typeof parsedUserLocation?.latitude !== 'object' ? parsedUserLocation?.latitude : 0,
417
- longitude: typeof parsedUserLocation?.longitude !== 'object' ? parsedUserLocation?.latitude : 0
422
+ latitude: parsedUserLocation()?.latitude,
423
+ longitude: parsedUserLocation()?.longitude
418
424
  }}
419
425
  title={markerTitle || t('YOUR_LOCATION', 'Your Location')}
420
426
  />
@@ -526,10 +532,10 @@ export const DriverMap = (props: GoogleMapsParams) => {
526
532
  animationIn: 'slideInUp'
527
533
  }}
528
534
  options={{
529
- latitude: destination.latitude,
530
- longitude: destination.longitude,
531
- sourceLatitude: parsedUserLocation.latitude,
532
- sourceLongitude: parsedUserLocation.longitude,
535
+ latitude: parsedDestination()?.latitude,
536
+ longitude: parsedDestination()?.longitude,
537
+ sourceLatitude: parsedUserLocation()?.latitude,
538
+ sourceLongitude: parsedUserLocation()?.longitude,
533
539
  naverCallerName: 'com.deliveryapp',
534
540
  dialogTitle: t('SHOW_IN_OTHER_MAPS', 'Show in other maps'),
535
541
  dialogMessage: t('WHAT_APP_WOULD_YOU_USE', 'What app would you like to use?'),