ordering-ui-react-native 0.18.58-test → 0.18.58-test1

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.18.58-test",
3
+ "version": "0.18.58-test1",
4
4
  "description": "Reusable components made in react native",
5
5
  "main": "src/index.tsx",
6
6
  "author": "ordering.inc",
@@ -6,6 +6,7 @@ import {
6
6
  Keyboard,
7
7
  TouchableWithoutFeedback,
8
8
  Platform,
9
+ Text,
9
10
  } from 'react-native';
10
11
  import {
11
12
  AddressForm as AddressFormController,
@@ -145,6 +146,7 @@ const AddressFormUI = (props: AddressFormParams) => {
145
146
  address: null,
146
147
  });
147
148
  const [isFirstTime, setIsFirstTime] = useState(true);
149
+ const [errorState, setErrorState] = useState({});
148
150
  const [locationChange, setLocationChange] = useState(
149
151
  isEditing
150
152
  ? addressState?.address?.location
@@ -344,6 +346,10 @@ const AddressFormUI = (props: AddressFormParams) => {
344
346
  };
345
347
 
346
348
  const handleChangeAddress = (data: any, details: any) => {
349
+ setErrorState({
350
+ ...errorState,
351
+ handleChangeAddress: {data: data, details: details}
352
+ })
347
353
  const addressSelected = {
348
354
  address: data?.description || data?.address,
349
355
  location: details?.geometry?.location,
@@ -644,6 +650,8 @@ const AddressFormUI = (props: AddressFormParams) => {
644
650
  }}
645
651
  IconButton={<OIcon src={theme.images.general.pin} width={16} />}
646
652
  isIntGeoCoder
653
+ errorState={errorState}
654
+ setErrorState={setErrorState}
647
655
  />
648
656
  </View>
649
657
  )}
@@ -808,6 +816,9 @@ const AddressFormUI = (props: AddressFormParams) => {
808
816
  />
809
817
  )}
810
818
  </FormInput>
819
+ <Text>
820
+ {JSON.stringify(errorState)}
821
+ </Text>
811
822
  {!isHideIcons && (
812
823
  <IconsContainer>
813
824
  {tagsName.map((tag) => (
@@ -3,6 +3,14 @@ import Geocoder from 'react-native-geocoding'
3
3
  import { ActivityIndicator } from 'react-native-paper'
4
4
  import Geolocation from '@react-native-community/geolocation'
5
5
  import { getTrackingStatus, requestTrackingPermission } from 'react-native-tracking-transparency'
6
+ import { Platform } from 'react-native'
7
+
8
+ import {
9
+ PERMISSIONS,
10
+ PermissionStatus,
11
+ request,
12
+ openSettings,
13
+ } from 'react-native-permissions';
6
14
 
7
15
  import { OText } from '../shared'
8
16
  import { GpsButtonStyle } from './styles'
@@ -13,7 +21,9 @@ export const GPSButton = (props: any) => {
13
21
  apiKey,
14
22
  IconButton,
15
23
  IconLoadingButton,
16
- isIntGeoCoder
24
+ isIntGeoCoder,
25
+ errorState,
26
+ setErrorState
17
27
  } = props
18
28
 
19
29
  const [isLoading, setLoading] = useState(false);
@@ -23,6 +33,10 @@ export const GPSButton = (props: any) => {
23
33
  latitude: pos.latitude,
24
34
  longitude: pos.longitude
25
35
  }).then(({ results }: any) => {
36
+ setErrorState({
37
+ ...errorState,
38
+ geoCodePosition: results
39
+ })
26
40
  let zipcode = null
27
41
  if (results && results.length > 0) {
28
42
  for (const component of results[0].address_components) {
@@ -32,7 +46,7 @@ export const GPSButton = (props: any) => {
32
46
  break
33
47
  }
34
48
  }
35
- let data = null
49
+ let data : any
36
50
  const details = {
37
51
  geometry: { location: { lat: pos.latitude, lng: pos.longitude } }
38
52
  }
@@ -52,6 +66,10 @@ export const GPSButton = (props: any) => {
52
66
  setLoading(false);
53
67
  }).catch((err: any) => {
54
68
  console.log(err);
69
+ setErrorState({
70
+ ...errorState,
71
+ fallbackGeoCodePosition: err
72
+ })
55
73
  setLoading(false);
56
74
  })
57
75
  }
@@ -61,17 +79,58 @@ export const GPSButton = (props: any) => {
61
79
  if (trackingStatus === 'not-determined') {
62
80
  trackingStatus = await requestTrackingPermission()
63
81
  }
82
+ setErrorState({
83
+ ...errorState,
84
+ trackingStatus: trackingStatus
85
+ })
64
86
  if (trackingStatus === 'authorized' || trackingStatus === 'unavailable') {
65
87
  setLoading(true)
66
88
  Geolocation.getCurrentPosition((pos) => {
89
+ setErrorState({
90
+ ...errorState,
91
+ getCurrentPosition: pos
92
+ })
67
93
  geoCodePosition(pos.coords)
68
94
  }, (err) => {
95
+ setErrorState({
96
+ ...errorState,
97
+ fallbackGetCurrentPosition: err
98
+ })
69
99
  setLoading(false);
70
100
  console.log(`ERROR(${err.code}): ${err.message}`)
71
101
  }, {
72
102
  enableHighAccuracy: true, timeout: 15000, maximumAge: 10000
73
103
  })
104
+ return
74
105
  }
106
+ let permissionStatus: PermissionStatus;
107
+ setLoading(true)
108
+ if (Platform.OS === 'ios') {
109
+ permissionStatus = await request(PERMISSIONS.IOS.LOCATION_WHEN_IN_USE);
110
+ } else {
111
+ permissionStatus = await request(
112
+ PERMISSIONS.ANDROID.ACCESS_FINE_LOCATION,
113
+ );
114
+ }
115
+ if (permissionStatus === 'denied') {
116
+ openSettings();
117
+ }
118
+ Geolocation.getCurrentPosition((pos) => {
119
+ setErrorState({
120
+ ...errorState,
121
+ getCurrentPositionNew: pos
122
+ })
123
+ geoCodePosition(pos.coords)
124
+ }, (err) => {
125
+ setErrorState({
126
+ ...errorState,
127
+ fallbackGetCurrentPositionNew: err
128
+ })
129
+ setLoading(false);
130
+ console.log(`ERROR(${err.code}): ${err.message}`)
131
+ }, {
132
+ enableHighAccuracy: true, timeout: 15000, maximumAge: 10000
133
+ })
75
134
  }
76
135
 
77
136
  useEffect(() => {