Skip to content

Commit 6c6d79c

Browse files
authored
Merge pull request Expensify#87103 from software-mansion-labs/@GCyganek/gps/add-map-to-gps-screen
2 parents 8b25111 + 9a460f3 commit 6c6d79c

14 files changed

Lines changed: 308 additions & 190 deletions

File tree

src/CONST/index.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9597,6 +9597,13 @@ const CONST = {
95979597
},
95989598

95999599
MODAL_MAX_HEIGHT_TO_WINDOW_HEIGHT_RATIO_LANDSCAPE_MODE: 0.75,
9600+
9601+
MAP_VIEW_LAYERS: {
9602+
USER_LOCATION_SOURCE: 'user-location-source',
9603+
USER_LOCATION: 'user-location',
9604+
ROUTE_SOURCE: 'route-source',
9605+
ROUTE_FILL: 'route-fill',
9606+
},
96009607
} as const;
96019608

96029609
const CONTINUATION_DETECTION_SEARCH_FILTER_KEYS = [

src/components/MapView/Direction.tsx

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,17 @@
11
import Mapbox from '@rnmapbox/maps';
22
import useThemeStyles from '@hooks/useThemeStyles';
3+
import CONST from '@src/CONST';
34
import type {DirectionProps} from './MapViewTypes';
45

5-
function Direction({coordinates}: DirectionProps) {
6+
function Direction({coordinates, belowLayerID}: DirectionProps) {
67
const styles = useThemeStyles();
78
if (coordinates.length < 1) {
89
return null;
910
}
1011

1112
return (
1213
<Mapbox.ShapeSource
13-
id="routeSource"
14+
id={CONST.MAP_VIEW_LAYERS.ROUTE_SOURCE}
1415
shape={{
1516
type: 'Feature',
1617
properties: {},
@@ -21,7 +22,8 @@ function Direction({coordinates}: DirectionProps) {
2122
}}
2223
>
2324
<Mapbox.LineLayer
24-
id="routeFill"
25+
belowLayerID={belowLayerID}
26+
id={CONST.MAP_VIEW_LAYERS.ROUTE_FILL}
2527
style={styles.mapDirection}
2628
/>
2729
</Mapbox.ShapeSource>

src/components/MapView/Direction.website.tsx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import React from 'react';
66
import {Layer, Source} from 'react-map-gl';
77
import {View} from 'react-native';
88
import useThemeStyles from '@hooks/useThemeStyles';
9+
import CONST from '@src/CONST';
910
import type {DirectionProps} from './MapViewTypes';
1011

1112
function Direction({coordinates}: DirectionProps) {
@@ -20,7 +21,7 @@ function Direction({coordinates}: DirectionProps) {
2021
<View>
2122
{!!coordinates && (
2223
<Source
23-
id="route"
24+
id={CONST.MAP_VIEW_LAYERS.ROUTE_SOURCE}
2425
type="geojson"
2526
data={{
2627
type: 'Feature',
@@ -32,9 +33,9 @@ function Direction({coordinates}: DirectionProps) {
3233
}}
3334
>
3435
<Layer
35-
id="route"
36+
id={CONST.MAP_VIEW_LAYERS.ROUTE_FILL}
3637
type="line"
37-
source="route"
38+
source={CONST.MAP_VIEW_LAYERS.ROUTE_SOURCE}
3839
paint={layerPointStyle}
3940
layout={layerLayoutStyle}
4041
/>

src/components/MapView/MapView.tsx

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,7 @@ function MapView({
278278
/>
279279
{interactive && (
280280
<Mapbox.ShapeSource
281-
id="user-location"
281+
id={CONST.MAP_VIEW_LAYERS.USER_LOCATION_SOURCE}
282282
shape={{
283283
type: 'FeatureCollection',
284284
features: [
@@ -294,8 +294,8 @@ function MapView({
294294
}}
295295
>
296296
<Mapbox.CircleLayer
297-
id="user-location-layer"
298-
sourceID="user-location"
297+
id={CONST.MAP_VIEW_LAYERS.USER_LOCATION}
298+
sourceID={CONST.MAP_VIEW_LAYERS.USER_LOCATION_SOURCE}
299299
style={{
300300
circleColor: colors.blue400,
301301
circleRadius: 8,
@@ -319,7 +319,12 @@ function MapView({
319319
);
320320
})}
321321

322-
{!!directionCoordinates && <Direction coordinates={directionCoordinates} />}
322+
{!!directionCoordinates && (
323+
<Direction
324+
coordinates={directionCoordinates}
325+
belowLayerID={interactive ? CONST.MAP_VIEW_LAYERS.USER_LOCATION : undefined}
326+
/>
327+
)}
323328
{!!distanceSymbolCoordinate && !!distanceInMeters && !!distanceUnit && (
324329
<MarkerView
325330
coordinate={distanceSymbolCoordinate}

src/components/MapView/MapViewTypes.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,9 @@ type MapViewProps = {
3939
type DirectionProps = {
4040
// Coordinates of points that constitute the direction
4141
coordinates: Coordinate[];
42+
43+
// ID of the layer to place the line layer below
44+
belowLayerID?: string;
4245
};
4346

4447
type PendingMapViewProps = {

src/libs/GPSDraftDetailsUtils.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,4 +139,8 @@ async function stopGpsTrip(isOffline: boolean, skipLastPointAddressFetching = fa
139139
setEndAddress({value: formattedCoordinates, type: 'coordinates'});
140140
}
141141

142-
export {getGPSRoutes, getGPSWaypoints, stopGpsTrip, getGPSConvertedDistance, getGPSCoordinates, addressFromGpsPoint, coordinatesToString, calculateGPSDistance};
142+
function isTripCaptured(gpsDraftDetails: GpsDraftDetails | undefined): boolean {
143+
return !gpsDraftDetails?.isTracking && (gpsDraftDetails?.gpsPoints?.length ?? 0) > 0;
144+
}
145+
146+
export {getGPSRoutes, getGPSWaypoints, stopGpsTrip, getGPSConvertedDistance, getGPSCoordinates, addressFromGpsPoint, coordinatesToString, calculateGPSDistance, isTripCaptured};

src/libs/actions/GPSDraftDetails.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import ONYXKEYS from '@src/ONYXKEYS';
66
import type {GpsDraftDetails} from '@src/types/onyx';
77
import type {Unit} from '@src/types/onyx/Policy';
88
import geodesicDistance from '@src/utils/geodesicDistance';
9+
import {setUserLocation} from './UserLocation';
910

1011
function resetGPSDraftDetails() {
1112
Onyx.merge(ONYXKEYS.GPS_DRAFT_DETAILS, null);
@@ -72,6 +73,12 @@ function addGpsPoints(gpsDraftDetails: OnyxEntry<GpsDraftDetails>, newGpsPoints:
7273

7374
const updatedGpsPoints = [...capturedPoints, ...gpsPointsToAdd];
7475

76+
const latestPoint = updatedGpsPoints.at(-1);
77+
78+
if (latestPoint) {
79+
setUserLocation({longitude: latestPoint.long, latitude: latestPoint.lat});
80+
}
81+
7582
if (updatedDistance > 0) {
7683
updateGpsTripNotificationDistance(updatedDistance);
7784
}

src/pages/iou/request/step/IOURequestStepDistanceGPS/DistanceCounter/TripStatusIndicator/index.tsx

Lines changed: 0 additions & 33 deletions
This file was deleted.

src/pages/iou/request/step/IOURequestStepDistanceGPS/DistanceCounter/index.tsx

Lines changed: 0 additions & 43 deletions
This file was deleted.
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import React from 'react';
2+
import {useProductTrainingContext} from '@components/ProductTrainingContext';
3+
import EducationalTooltip from '@components/Tooltip/EducationalTooltip';
4+
import useOnyx from '@hooks/useOnyx';
5+
import useThemeStyles from '@hooks/useThemeStyles';
6+
import useWindowDimensions from '@hooks/useWindowDimensions';
7+
import CONST from '@src/CONST';
8+
import ONYXKEYS from '@src/ONYXKEYS';
9+
import {isTrackingSelector} from '@src/selectors/GPSDraftDetails';
10+
11+
const GPS_TOOLTIP_HORIZONTAL_PADDING = 40;
12+
13+
function GPSTooltip({children}: React.PropsWithChildren) {
14+
const [isTracking = false] = useOnyx(ONYXKEYS.GPS_DRAFT_DETAILS, {selector: isTrackingSelector});
15+
16+
const styles = useThemeStyles();
17+
const {windowWidth} = useWindowDimensions();
18+
19+
const {renderProductTrainingTooltip, shouldShowProductTrainingTooltip} = useProductTrainingContext(CONST.PRODUCT_TRAINING_TOOLTIP_NAMES.GPS_TOOLTIP, !!isTracking);
20+
21+
return (
22+
<EducationalTooltip
23+
wrapperStyle={styles.productTrainingTooltipWrapper}
24+
shiftVertical={-12}
25+
maxWidth={windowWidth - GPS_TOOLTIP_HORIZONTAL_PADDING}
26+
renderTooltipContent={renderProductTrainingTooltip}
27+
shouldRender={shouldShowProductTrainingTooltip}
28+
>
29+
{children}
30+
</EducationalTooltip>
31+
);
32+
}
33+
34+
export default GPSTooltip;

0 commit comments

Comments
 (0)