Skip to content

Commit 9c00028

Browse files
authored
hotfix: live order route routing bug with custom origin (#38)
* hotfix: live order route routing bug with custom origin * added custom themes and more styling configurations
1 parent 474b6ca commit 9c00028

File tree

12 files changed

+341
-58
lines changed

12 files changed

+341
-58
lines changed

android/link-assets-manifest.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"migIndex": 1,
3+
"data": []
4+
}
89.3 KB
Loading

config/default.js

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@ import { mergeConfigs, config, toBoolean } from '../src/utils/config';
22
import { toArray } from '../src/utils';
33
import { faHome, faMagnifyingGlass, faMap, faShoppingCart, faUser } from '@fortawesome/free-solid-svg-icons';
44

5+
const backgroundImages = {
6+
storefront_photo_1: require('../assets/images/storefront-photo-1.jpg'),
7+
storefront_photo_2: require('../assets/images/storefront-photo-2.jpg'),
8+
};
9+
510
export const DefaultConfig = {
611
theme: config('APP_THEME', 'blue'),
712
storeNavigator: {
@@ -28,15 +33,28 @@ export const DefaultConfig = {
2833
storeCategoriesDisplay: config('STORE_CATEGORIES_DISPLAY', 'grid'), // `pills` or `grid`
2934
productCardStyle: config('PRODUCT_CARD_STYLE', 'bordered'), // `bordered`, `outlined`, `visio`
3035
backgroundImages: {
31-
LoginScreen: require('../assets/images/storefront-photo-1.jpg'),
36+
LoginScreen: backgroundImages[config('LOGIN_BG_IMAGE', 'storefront_photo_1')],
37+
BootScreen: backgroundImages[config('BOOTSCREEN_BG_IMAGE')] ?? null,
38+
},
39+
storeHeader: {
40+
showGradient: toBoolean(config('STORE_HEADER_SHOW_GRADIENT', 1)),
41+
showLocationPicker: toBoolean(config('STORE_HEADER_SHOW_LOCATION_PICKER', 1)),
42+
showTitle: toBoolean(config('STORE_HEADER_SHOW_TITLE', 1)),
43+
showDescription: toBoolean(config('STORE_HEADER_SHOW_DESCRIPTION', 1)),
44+
showLogo: toBoolean(config('STORE_HEADER_SHOW_LOGO', 1)),
45+
logoHeight: parseInt(config('STORE_HEADER_LOGO_HEIGHT', 45)),
46+
logoWidth: parseInt(config('STORE_HEADER_LOGO_WIDTH', 45)),
3247
},
3348
styles: {
3449
StoreHeader: {
35-
direction: 'column',
36-
alignItems: 'center',
37-
justifyContent: 'flex-end',
38-
space: '$1',
39-
padding: '$4',
50+
direction: config('STORE_HEADER_FLEX_DIRECTION', 'column'),
51+
alignItems: config('STORE_HEADER_ALIGN_ITEMS', 'center'),
52+
justifyContent: config('STORE_HEADER_JUSTIFY_CONTENT', 'flex-end'),
53+
space: config('STORE_HEADER_SPACING', '$1'),
54+
paddingTop: config('STORE_HEADER_PADDING_TOP', 0),
55+
paddingBottom: config('STORE_HEADER_PADDING_BOTTOM', 0),
56+
paddingLeft: config('STORE_HEADER_PADDING_LEFT', 0),
57+
paddingRight: config('STORE_HEADER_PADDING_RIGHT', 0),
4058
},
4159
},
4260
};

ios/link-assets-manifest.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"migIndex": 1,
3+
"data": []
4+
}

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@fleetbase/storefront-app",
3-
"version": "0.0.11",
3+
"version": "0.0.12",
44
"private": true,
55
"scripts": {
66
"android": "react-native run-android",

react-native.config.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
module.exports = {
2+
assets: ['./assets/fonts'],
3+
};

src/components/LiveOrderRoute.tsx

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ const LiveOrderRoute = ({ children, order, zoom = 1, width = '100%', height = '1
6464
longitudeDelta: initialDeltas,
6565
});
6666
const [zoomLevel, setZoomLevel] = useState(calculateZoomLevel(initialDeltas));
67-
const [findingOrigin, setFindingOrigin] = useState(false);
67+
const [findingOrigin, setFindingOrigin] = useState(true);
6868
const markerOffset = calculateOffset(zoomLevel);
6969
const driverAssigned = order.getAttribute('driver_assigned') ? new Driver(order.getAttribute('driver_assigned')) : null;
7070
const isOriginFoodTruck = start.resource === 'food-truck';
@@ -96,7 +96,10 @@ const LiveOrderRoute = ({ children, order, zoom = 1, width = '100%', height = '1
9696
};
9797

9898
const updateOriginFromCustomOrigin = useCallback(async () => {
99-
if (!customOrigin) return;
99+
if (!customOrigin) {
100+
setFindingOrigin(false);
101+
return;
102+
}
100103

101104
if (typeof customOrigin !== 'string') {
102105
// Assume customOrigin is already an origin object.
@@ -146,10 +149,13 @@ const LiveOrderRoute = ({ children, order, zoom = 1, width = '100%', height = '1
146149

147150
// Run the update when customOrigin changes.
148151
useEffect(() => {
149-
if (!storefront || !store) return;
152+
if (!storefront || !store) {
153+
setFindingOrigin(false);
154+
return;
155+
}
150156

151157
updateOriginFromCustomOrigin();
152-
}, [storefront, store]);
158+
}, [storefront, store, setFindingOrigin]);
153159

154160
return (
155161
<YStack flex={1} position='relative' overflow='hidden' width={width} height={height}>
@@ -235,14 +241,16 @@ const LiveOrderRoute = ({ children, order, zoom = 1, width = '100%', height = '1
235241
<LocationMarker size={markerSize} />
236242
</Marker>
237243

238-
<MapViewDirections
239-
origin={origin}
240-
destination={destination}
241-
apikey={config('GOOGLE_MAPS_API_KEY')}
242-
strokeWidth={4}
243-
strokeColor={theme['$blue-500'].val}
244-
onReady={fitToRoute}
245-
/>
244+
{origin && destination && findingOrigin === false && (
245+
<MapViewDirections
246+
origin={origin}
247+
destination={destination}
248+
apikey={config('GOOGLE_MAPS_API_KEY')}
249+
strokeWidth={4}
250+
strokeColor={theme['$blue-500'].val}
251+
onReady={fitToRoute}
252+
/>
253+
)}
246254
</MapView>
247255

248256
<YStack position='absolute' style={{ ...StyleSheet.absoluteFillObject }}>

src/components/StoreHeader.tsx

Lines changed: 44 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,10 @@ const StoreHeader = ({ storeName, description, logoUrl, backgroundUrl, height =
2424

2525
<Stack
2626
direction={storefrontConfig('styles.StoreHeader.direction', 'column')}
27-
px={storefrontConfig('styles.StoreHeader.padding', '$4')}
27+
pt={storefrontConfig('styles.StoreHeader.paddingTop', 0)}
28+
pb={storefrontConfig('styles.StoreHeader.paddingBottom', 0)}
29+
pl={storefrontConfig('styles.StoreHeader.paddingLeft', 0)}
30+
pr={storefrontConfig('styles.StoreHeader.paddingRight', 0)}
2831
space={storefrontConfig('styles.StoreHeader.space', '$1')}
2932
alignItems={storefrontConfig('styles.StoreHeader.alignItems', 'center')}
3033
justifyContent={storefrontConfig('styles.StoreHeader.justifyContent', 'flex-end')}
@@ -33,50 +36,58 @@ const StoreHeader = ({ storeName, description, logoUrl, backgroundUrl, height =
3336
zIndex={1}
3437
>
3538
<YStack alignItems={storefrontConfig('styles.StoreHeader.alignItems', 'center')} space='$1'>
36-
{logoUrl && (
39+
{storefrontConfig('storeHeader.showLogo') && logoUrl && (
3740
<YStack>
3841
<FastImage
3942
source={{ uri: logoUrl }}
4043
style={{
41-
height: 45,
42-
width: 45,
44+
height: storefrontConfig('storeHeader.logoHeight', 45),
45+
width: storefrontConfig('storeHeader.logoWidth', 45),
4346
}}
4447
/>
4548
</YStack>
4649
)}
47-
<Text color='white' fontSize='$8' fontWeight='bold' numberOfLines={1}>
48-
{storeName}
49-
</Text>
50-
<YStack>
51-
{description && (
52-
<YStack alignItems='center' justifyContent='center'>
53-
<Text color='white' fontSize='$5' opacity={0.9} numberOfLines={2} textAlign='center'>
54-
{description}
55-
</Text>
56-
</YStack>
57-
)}
58-
</YStack>
50+
{storefrontConfig('storeHeader.showTitle') && (
51+
<Text color='white' fontSize='$8' fontWeight='bold' numberOfLines={1}>
52+
{storeName}
53+
</Text>
54+
)}
55+
{storefrontConfig('storeHeader.showDescription') && (
56+
<YStack>
57+
{description && (
58+
<YStack alignItems='center' justifyContent='center'>
59+
<Text color='white' fontSize='$5' opacity={0.9} numberOfLines={2} textAlign='center'>
60+
{description}
61+
</Text>
62+
</YStack>
63+
)}
64+
</YStack>
65+
)}
5966
</YStack>
6067

61-
<YStack alignItems='center' justifyContent='center'>
62-
<StoreLocationPicker
63-
defaultStoreLocation={defaultStoreLocation}
64-
triggerStyle={{ borderWidth: 1, backgroundColor: theme['$gray-900'].val, borderRadius: 10, paddingHorizontal: 6, paddingVertical: 3 }}
65-
/>
66-
</YStack>
68+
{storefrontConfig('storeHeader.showLocationPicker') && (
69+
<YStack alignItems='center' justifyContent='center'>
70+
<StoreLocationPicker
71+
defaultStoreLocation={defaultStoreLocation}
72+
triggerStyle={{ borderWidth: 1, backgroundColor: theme['$gray-900'].val, borderRadius: 10, paddingHorizontal: 6, paddingVertical: 3 }}
73+
/>
74+
</YStack>
75+
)}
6776
</Stack>
6877

69-
<LinearGradient
70-
colors={['rgba(0,0,0,0.5)', 'rgba(0,0,0,0)', 'rgba(0,0,0,0.6)', 'rgba(0,0,0,0.8)']}
71-
start={{ x: 0, y: 0 }}
72-
end={{ x: 0, y: 1 }}
73-
style={{
74-
position: 'absolute',
75-
bottom: 0,
76-
height: '100%',
77-
width: '100%',
78-
}}
79-
/>
78+
{storefrontConfig('storeHeader.showGradient') && (
79+
<LinearGradient
80+
colors={['rgba(0,0,0,0.5)', 'rgba(0,0,0,0)', 'rgba(0,0,0,0.6)', 'rgba(0,0,0,0.8)']}
81+
start={{ x: 0, y: 0 }}
82+
end={{ x: 0, y: 1 }}
83+
style={{
84+
position: 'absolute',
85+
bottom: 0,
86+
height: '100%',
87+
width: '100%',
88+
}}
89+
/>
90+
)}
8091
</Animated.View>
8192
);
8293
};

src/components/VehicleMarker.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ const VehicleMarker = ({ vehicle, onPositionChange, onHeadingChange, onMovement,
6767
const latitude = vehicle.getAttribute('location.coordinates.1');
6868
const longitude = vehicle.getAttribute('location.coordinates.0');
6969

70-
// console.log(`${vehicle.id} coordinates: ${latitude} ${longitude}`);
70+
console.log(`${vehicle.id} coordinates: ${latitude} ${longitude}`);
7171
return (
7272
<TrackingMarker
7373
ref={markerRef}

src/screens/BootScreen.tsx

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,33 @@
11
import React, { useEffect, useState } from 'react';
22
import { useNavigation } from '@react-navigation/native';
33
import { useSafeAreaInsets } from 'react-native-safe-area-context';
4-
import { Platform } from 'react-native';
4+
import { Platform, ImageBackground } from 'react-native';
55
import { check, request, PERMISSIONS, RESULTS } from 'react-native-permissions';
66
import { Image, Spinner, XStack, Text, YStack, useTheme } from 'tamagui';
77
import { LinearGradient } from 'react-native-linear-gradient';
8-
import { config, toArray, isArray } from '../utils';
8+
import { config, toArray, isArray, storefrontConfig } from '../utils';
99
import { getCurrentLocationFromStorage, requestWebGeolocationPermission } from '../utils/location';
1010
import BootSplash from 'react-native-bootsplash';
1111
import SetupWarningScreen from './SetupWarningScreen';
1212
import useStorefront from '../hooks/use-storefront';
1313
import useStorage from '../hooks/use-storage';
1414
import { useLanguage } from '../contexts/LanguageContext';
1515

16+
const BootScreenWrapper = ({ children, backgroundImage, backgroundColor, theme }) => {
17+
const bg = (isArray(backgroundColor) ? backgroundColor[0] : backgroundColor) ?? theme.background.val;
18+
const source = backgroundImage ?? null;
19+
20+
return source ? (
21+
<ImageBackground style={[{ flex: 1, width: '100%', height: '100%' }, { backgroundColor: bg }]} source={source} resizeMode='cover'>
22+
{children}
23+
</ImageBackground>
24+
) : (
25+
<YStack f={1} w='100%' h='100%' bg={bg}>
26+
{children}
27+
</YStack>
28+
);
29+
};
30+
1631
const APP_NAME = config('APP_NAME');
1732
const BootScreen = () => {
1833
const theme = useTheme();
@@ -24,7 +39,9 @@ const BootScreen = () => {
2439
const [info, setInfo] = useStorage('info', {});
2540
const [error, setError] = useState<Error | null>(null);
2641
const backgroundColor = toArray(config('BOOTSCREEN_BACKGROUND_COLOR', '$background'));
42+
const backgroundImage = storefrontConfig('backgroundImages.BootScreen');
2743
const isGradientBackground = isArray(backgroundColor) && backgroundColor.length > 1;
44+
const hasBgImage = !!backgroundImage;
2845

2946
useEffect(() => {
3047
const checkLocationPermission = async () => {
@@ -88,8 +105,8 @@ const BootScreen = () => {
88105
}
89106

90107
return (
91-
<YStack style={{ flex: 1, width: '100%', height: '100%' }}>
92-
<YStack flex={1} bg={backgroundColor[0]} alignItems='center' justifyContent='center' width='100%' height='100%' pt={insets.top} pb={insets.bottom}>
108+
<BootScreenWrapper backgroundImage={backgroundImage} backgroundColor={backgroundColor} theme={theme}>
109+
<YStack flex={1} bg={hasBgImage ? 'transparent' : backgroundColor[0]} alignItems='center' justifyContent='center' width='100%' height='100%' pt={insets.top} pb={insets.bottom}>
93110
{isGradientBackground && (
94111
<LinearGradient
95112
colors={backgroundColor}
@@ -110,7 +127,7 @@ const BootScreen = () => {
110127
</XStack>
111128
</YStack>
112129
</YStack>
113-
</YStack>
130+
</BootScreenWrapper>
114131
);
115132
};
116133

0 commit comments

Comments
 (0)