ordering-ui-react-native 0.12.67 → 0.12.68
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,5 +1,6 @@
|
|
|
1
1
|
import React, { useEffect, useState } from 'react';
|
|
2
2
|
import { Fade, Placeholder, PlaceholderLine } from 'rn-placeholder';
|
|
3
|
+
import Geolocation from '@react-native-community/geolocation'
|
|
3
4
|
import {
|
|
4
5
|
View,
|
|
5
6
|
StyleSheet,
|
|
@@ -16,6 +17,7 @@ import {
|
|
|
16
17
|
useUtils,
|
|
17
18
|
} from 'ordering-components/native';
|
|
18
19
|
import { useTheme } from 'styled-components/native';
|
|
20
|
+
import Ionicons from 'react-native-vector-icons/Ionicons'
|
|
19
21
|
|
|
20
22
|
import {
|
|
21
23
|
Search,
|
|
@@ -25,7 +27,8 @@ import {
|
|
|
25
27
|
HeaderWrapper,
|
|
26
28
|
ListWrapper,
|
|
27
29
|
FeaturedWrapper,
|
|
28
|
-
OrderProgressWrapper
|
|
30
|
+
OrderProgressWrapper,
|
|
31
|
+
FarAwayMessage
|
|
29
32
|
} from './styles';
|
|
30
33
|
|
|
31
34
|
import { SearchBar } from '../SearchBar';
|
|
@@ -38,7 +41,7 @@ import { OrderTypeSelector } from '../OrderTypeSelector';
|
|
|
38
41
|
import { useSafeAreaInsets } from 'react-native-safe-area-context';
|
|
39
42
|
import { BusinessFeaturedController } from '../BusinessFeaturedController';
|
|
40
43
|
import { HighestRatedBusinesses } from '../HighestRatedBusinesses';
|
|
41
|
-
import { getTypesText } from '../../utils';
|
|
44
|
+
import { getTypesText, convertToRadian } from '../../utils';
|
|
42
45
|
import { OrderProgress } from '../OrderProgress';
|
|
43
46
|
import { useIsFocused } from '@react-navigation/native';
|
|
44
47
|
|
|
@@ -85,6 +88,15 @@ const BusinessesListingUI = (props: BusinessesListingParams) => {
|
|
|
85
88
|
},
|
|
86
89
|
searchInput: {
|
|
87
90
|
fontSize: 12,
|
|
91
|
+
},
|
|
92
|
+
iconStyle: {
|
|
93
|
+
fontSize: 18,
|
|
94
|
+
color: theme.colors.warning5,
|
|
95
|
+
marginRight: 8
|
|
96
|
+
},
|
|
97
|
+
farAwayMsg: {
|
|
98
|
+
paddingVertical: 6,
|
|
99
|
+
paddingHorizontal: 20
|
|
88
100
|
}
|
|
89
101
|
});
|
|
90
102
|
|
|
@@ -98,6 +110,7 @@ const BusinessesListingUI = (props: BusinessesListingParams) => {
|
|
|
98
110
|
const { top } = useSafeAreaInsets();
|
|
99
111
|
|
|
100
112
|
const [featuredBusiness, setFeaturedBusinesses] = useState(Array);
|
|
113
|
+
const [isFarAway, setIsFarAway] = useState(false)
|
|
101
114
|
|
|
102
115
|
// const timerId = useRef<any>(false)
|
|
103
116
|
// const panResponder = useRef(
|
|
@@ -127,6 +140,17 @@ const BusinessesListingUI = (props: BusinessesListingParams) => {
|
|
|
127
140
|
}
|
|
128
141
|
};
|
|
129
142
|
|
|
143
|
+
const getDistance = (lat1: any, lon1: any, lat2: any, lon2: any) => {
|
|
144
|
+
const R = 6371 // km
|
|
145
|
+
const dLat = convertToRadian(lat2 - lat1)
|
|
146
|
+
const dLon = convertToRadian(lon2 - lon1)
|
|
147
|
+
const curLat1 = convertToRadian(lat1)
|
|
148
|
+
const curLat2 = convertToRadian(lat2)
|
|
149
|
+
const a = Math.sin(dLat / 2) * Math.sin(dLat / 2) + Math.sin(dLon / 2) * Math.sin(dLon / 2) * Math.cos(curLat1) * Math.cos(curLat2)
|
|
150
|
+
const c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a))
|
|
151
|
+
return R * c
|
|
152
|
+
}
|
|
153
|
+
|
|
130
154
|
useEffect(() => {
|
|
131
155
|
if (businessesList.businesses.length > 0) {
|
|
132
156
|
const fb = businessesList.businesses.filter((b) => b.featured == true);
|
|
@@ -148,6 +172,19 @@ const BusinessesListingUI = (props: BusinessesListingParams) => {
|
|
|
148
172
|
// resetInactivityTimeout()
|
|
149
173
|
// }, [])
|
|
150
174
|
|
|
175
|
+
useEffect(() => {
|
|
176
|
+
Geolocation.getCurrentPosition((pos) => {
|
|
177
|
+
const crd = pos.coords
|
|
178
|
+
const distance = getDistance(crd.latitude, crd.longitude, orderState?.options?.address?.location?.lat, orderState?.options?.address?.location?.lng)
|
|
179
|
+
if (distance > 20) setIsFarAway(true)
|
|
180
|
+
else setIsFarAway(false)
|
|
181
|
+
}, (err) => {
|
|
182
|
+
console.log(`ERROR(${err.code}): ${err.message}`)
|
|
183
|
+
}, {
|
|
184
|
+
enableHighAccuracy: true, timeout: 15000, maximumAge: 10000
|
|
185
|
+
})
|
|
186
|
+
}, [orderState?.options?.address?.location])
|
|
187
|
+
|
|
151
188
|
return (
|
|
152
189
|
<ScrollView style={styles.container} onScroll={(e) => handleScroll(e)} showsVerticalScrollIndicator={false}>
|
|
153
190
|
<HeaderWrapper
|
|
@@ -180,6 +217,12 @@ const BusinessesListingUI = (props: BusinessesListingParams) => {
|
|
|
180
217
|
</OText>
|
|
181
218
|
</AddressInput>
|
|
182
219
|
</Search>
|
|
220
|
+
{isFarAway && (
|
|
221
|
+
<FarAwayMessage style={styles.farAwayMsg}>
|
|
222
|
+
<Ionicons name='md-warning-outline' style={styles.iconStyle} />
|
|
223
|
+
<OText size={12} numberOfLines={1} ellipsizeMode={'tail'} color={theme.colors.textNormal}>{t('YOU_ARE_FAR_FROM_ADDRESS', 'Your are far from this address')}</OText>
|
|
224
|
+
</FarAwayMessage>
|
|
225
|
+
)}
|
|
183
226
|
<OrderControlContainer>
|
|
184
227
|
<View style={styles.wrapperOrderOptions}>
|
|
185
228
|
<WrapMomentOption onPress={() => navigation.navigate('OrderTypes', { configTypes: configTypes })}>
|
|
@@ -73,4 +73,13 @@ export const OrderProgressWrapper = styled.View`
|
|
|
73
73
|
margin-top: 37px;
|
|
74
74
|
margin-bottom: 20px;
|
|
75
75
|
padding-horizontal: 40px;
|
|
76
|
-
`
|
|
76
|
+
`
|
|
77
|
+
|
|
78
|
+
export const FarAwayMessage = styled.View`
|
|
79
|
+
flex-direction: row;
|
|
80
|
+
align-items: center;
|
|
81
|
+
background-color: ${(props: any) => props.theme.colors.warning1};
|
|
82
|
+
margin-bottom: 25px;
|
|
83
|
+
border-radius: 7.6px;
|
|
84
|
+
border: 1px solid ${(props: any) => props.theme.colors.warning5};
|
|
85
|
+
`
|
|
@@ -168,4 +168,13 @@ export const transformCountryCode = (countryCode : number) => {
|
|
|
168
168
|
export const getTypesText = (value: number) => {
|
|
169
169
|
const ret = ORDER_TYPES.find((type: any) => type.value == value);
|
|
170
170
|
return ret?.content;
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
/**
|
|
174
|
+
* Function to transform degree to radian
|
|
175
|
+
* @param {number} value for transform
|
|
176
|
+
*
|
|
177
|
+
*/
|
|
178
|
+
export const convertToRadian = (value: number) => {
|
|
179
|
+
return value * Math.PI / 180
|
|
171
180
|
}
|