ordering-ui-react-native 0.18.58-test2 → 0.18.58-test3
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
|
@@ -3,7 +3,7 @@ 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'
|
|
6
|
+
import { Platform, PermissionsAndroid } from 'react-native'
|
|
7
7
|
|
|
8
8
|
import {
|
|
9
9
|
PERMISSIONS,
|
|
@@ -73,7 +73,30 @@ export const GPSButton = (props: any) => {
|
|
|
73
73
|
setLoading(false);
|
|
74
74
|
})
|
|
75
75
|
}
|
|
76
|
-
|
|
76
|
+
const requestLocationPermission = async () => {
|
|
77
|
+
try {
|
|
78
|
+
const granted = await PermissionsAndroid.request(
|
|
79
|
+
PermissionsAndroid.PERMISSIONS.ACCESS_FINE_LOCATION,
|
|
80
|
+
{
|
|
81
|
+
title: 'Geolocation Permission',
|
|
82
|
+
message: 'Can we access your location?',
|
|
83
|
+
buttonNeutral: 'Ask Me Later',
|
|
84
|
+
buttonNegative: 'Cancel',
|
|
85
|
+
buttonPositive: 'OK',
|
|
86
|
+
},
|
|
87
|
+
);
|
|
88
|
+
console.log('granted', granted);
|
|
89
|
+
if (granted === 'granted') {
|
|
90
|
+
console.log('You can use Geolocation');
|
|
91
|
+
return true;
|
|
92
|
+
} else {
|
|
93
|
+
console.log('You cannot use Geolocation');
|
|
94
|
+
return false;
|
|
95
|
+
}
|
|
96
|
+
} catch (err) {
|
|
97
|
+
return false;
|
|
98
|
+
}
|
|
99
|
+
};
|
|
77
100
|
const getCurrentPosition = async () => {
|
|
78
101
|
let trackingStatus = await getTrackingStatus()
|
|
79
102
|
if (trackingStatus === 'not-determined') {
|
|
@@ -103,15 +126,36 @@ export const GPSButton = (props: any) => {
|
|
|
103
126
|
})
|
|
104
127
|
return
|
|
105
128
|
}
|
|
129
|
+
|
|
106
130
|
let permissionStatus: PermissionStatus;
|
|
107
131
|
setLoading(true)
|
|
108
132
|
if (Platform.OS === 'ios') {
|
|
109
133
|
permissionStatus = await request(PERMISSIONS.IOS.LOCATION_WHEN_IN_USE);
|
|
110
134
|
} else {
|
|
111
|
-
permissionStatus = await request(
|
|
112
|
-
|
|
113
|
-
);
|
|
114
|
-
|
|
135
|
+
// permissionStatus = await request(
|
|
136
|
+
// PERMISSIONS.ANDROID.ACCESS_FINE_LOCATION,
|
|
137
|
+
// );
|
|
138
|
+
const result = requestLocationPermission();
|
|
139
|
+
result.then(res => {
|
|
140
|
+
if (res) {
|
|
141
|
+
Geolocation.getCurrentPosition((pos) => {
|
|
142
|
+
setErrorState({
|
|
143
|
+
...errorState,
|
|
144
|
+
getCurrentPositionNew2: pos
|
|
145
|
+
})
|
|
146
|
+
geoCodePosition(pos.coords)
|
|
147
|
+
}, (err) => {
|
|
148
|
+
setErrorState({
|
|
149
|
+
...errorState,
|
|
150
|
+
fallbackGetCurrentPositionNew2: err
|
|
151
|
+
})
|
|
152
|
+
setLoading(false);
|
|
153
|
+
console.log(`ERROR(${err.code}): ${err.message}`)
|
|
154
|
+
}, {
|
|
155
|
+
enableHighAccuracy: true, timeout: 30000, maximumAge: 10000
|
|
156
|
+
})
|
|
157
|
+
}
|
|
158
|
+
}); }
|
|
115
159
|
if (permissionStatus === 'denied') {
|
|
116
160
|
openSettings();
|
|
117
161
|
}
|