-
Notifications
You must be signed in to change notification settings - Fork 3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix add center button and blue dot #40759
Changes from 38 commits
be55619
0a4b847
6093f69
e7420da
b7b9fbb
a5ea387
a218054
b7a31bc
f29e65b
f975e08
9754dce
ee0584b
50208b8
ee76e2e
3acd03f
757865a
f1de15d
d179015
1ff830a
eadb32a
ee8cef6
ee451b3
273741e
b253ae1
b12c374
aa487e7
6ee0862
6c90e66
b38b19f
0688a0e
e30eb90
76679ed
55f6535
0f09d6f
1732367
cc42428
2d79bd8
95591d9
3fe0372
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,12 +4,18 @@ import Mapbox, {MarkerView, setAccessToken} from '@rnmapbox/maps'; | |
import {forwardRef, memo, useCallback, useEffect, useImperativeHandle, useRef, useState} from 'react'; | ||
import {View} from 'react-native'; | ||
import {withOnyx} from 'react-native-onyx'; | ||
import Icon from '@components/Icon'; | ||
import * as Expensicons from '@components/Icon/Expensicons'; | ||
import {PressableWithoutFeedback} from '@components/Pressable'; | ||
import useTheme from '@hooks/useTheme'; | ||
import useThemeStyles from '@hooks/useThemeStyles'; | ||
import * as UserLocation from '@libs/actions/UserLocation'; | ||
import compose from '@libs/compose'; | ||
import getCurrentPosition from '@libs/getCurrentPosition'; | ||
import type {GeolocationErrorCallback} from '@libs/getCurrentPosition/getCurrentPosition.types'; | ||
import {GeolocationErrorCode} from '@libs/getCurrentPosition/getCurrentPosition.types'; | ||
import colors from '@styles/theme/colors'; | ||
import variables from '@styles/variables'; | ||
import CONST from '@src/CONST'; | ||
import useLocalize from '@src/hooks/useLocalize'; | ||
import useNetwork from '@src/hooks/useNetwork'; | ||
|
@@ -27,7 +33,7 @@ const MapView = forwardRef<MapViewHandle, ComponentProps>( | |
const {isOffline} = useNetwork(); | ||
const {translate} = useLocalize(); | ||
const styles = useThemeStyles(); | ||
|
||
const theme = useTheme(); | ||
const cameraRef = useRef<Mapbox.Camera>(null); | ||
const [isIdle, setIsIdle] = useState(false); | ||
const [currentPosition, setCurrentPosition] = useState(cachedUserLocation); | ||
|
@@ -148,6 +154,19 @@ const MapView = forwardRef<MapViewHandle, ComponentProps>( | |
onMapReady(); | ||
} | ||
}; | ||
const centerMap = useCallback(() => { | ||
if (directionCoordinates && directionCoordinates.length > 1) { | ||
const {southWest, northEast} = utils.getBounds(waypoints?.map((waypoint) => waypoint.coordinate) ?? [], directionCoordinates); | ||
cameraRef.current?.fitBounds(southWest, northEast, mapPadding, CONST.MAPBOX.ANIMATION_DURATION_ON_CENTER_ME); | ||
return; | ||
} | ||
cameraRef?.current?.setCamera({ | ||
heading: 0, | ||
centerCoordinate: [currentPosition?.longitude ?? 0, currentPosition?.latitude ?? 0], | ||
animationDuration: CONST.MAPBOX.ANIMATION_DURATION_ON_CENTER_ME, | ||
zoomLevel: CONST.MAPBOX.SINGLE_MARKER_ZOOM, | ||
}); | ||
}, [directionCoordinates, currentPosition, mapPadding, waypoints]); | ||
|
||
const centerCoordinate = currentPosition ? [currentPosition.longitude, currentPosition.latitude] : initialState?.location; | ||
return !isOffline && Boolean(accessToken) && Boolean(currentPosition) ? ( | ||
|
@@ -174,9 +193,37 @@ const MapView = forwardRef<MapViewHandle, ComponentProps>( | |
// displayed after the first render when the app's storage is cleared. | ||
centerCoordinate={centerCoordinate} | ||
/> | ||
<Mapbox.ShapeSource | ||
id="user-location" | ||
shape={{ | ||
type: 'FeatureCollection', | ||
features: [ | ||
{ | ||
type: 'Feature', | ||
geometry: { | ||
type: 'Point', | ||
coordinates: [currentPosition?.longitude ?? 0, currentPosition?.latitude ?? 0], | ||
}, | ||
properties: {}, | ||
}, | ||
], | ||
}} | ||
> | ||
<Mapbox.CircleLayer | ||
id="user-location-layer" | ||
sourceID="user-location" | ||
style={{ | ||
circleColor: colors.blue400, | ||
circleRadius: 8, | ||
}} | ||
/> | ||
</Mapbox.ShapeSource> | ||
|
||
{waypoints?.map(({coordinate, markerComponent, id}) => { | ||
const MarkerComponent = markerComponent; | ||
if (utils.areSameCoordinate([coordinate[0], coordinate[1]], [currentPosition?.longitude ?? 0, currentPosition?.latitude ?? 0])) { | ||
return null; | ||
} | ||
return ( | ||
<MarkerView | ||
id={id} | ||
|
@@ -190,6 +237,22 @@ const MapView = forwardRef<MapViewHandle, ComponentProps>( | |
|
||
{directionCoordinates && <Direction coordinates={directionCoordinates} />} | ||
</Mapbox.MapView> | ||
<View style={[styles.pAbsolute, styles.p5, styles.t0, styles.r0, {zIndex: 1}]}> | ||
<PressableWithoutFeedback | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Coming from #43058. We missed adding hover and press effect on this button. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is wrong. It was not part of the requirement. Design team approved this PR. So the mentioned issued is a new feature/change. @jjcoffee Could you please update the bug list to remove this PR? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We might have missed this but the @Expensify/design explicitly stated several times that we wanted this button behavior to match all of our other default buttons. Don't our default buttons all have a hover and press style? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ok. I see. We were pushed to merge this quickly so it might be missed. |
||
accessibilityRole={CONST.ROLE.BUTTON} | ||
onPress={centerMap} | ||
accessibilityLabel={translate('common.center')} | ||
> | ||
<View style={styles.primaryMediumIcon}> | ||
<Icon | ||
width={variables.iconSizeNormal} | ||
height={variables.iconSizeNormal} | ||
src={Expensicons.Crosshair} | ||
fill={theme.icon} | ||
/> | ||
</View> | ||
</PressableWithoutFeedback> | ||
</View> | ||
</View> | ||
) : ( | ||
<PendingMapView | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this duration can be shortened.