@@ -19,9 +19,10 @@ import utils from './utils';
19
19
const MapView = forwardRef < MapViewHandle , MapViewProps > (
20
20
( { style, styleURL, waypoints, mapPadding, accessToken, directionCoordinates, initialState = { location : CONST . MAPBOX . DEFAULT_COORDINATE , zoom : CONST . MAPBOX . DEFAULT_ZOOM } } , ref ) => {
21
21
const [ mapRef , setMapRef ] = useState < MapRef | null > ( null ) ;
22
+ const [ shouldResetBoundaries , setShouldResetBoundaries ] = useState < boolean > ( false ) ;
22
23
const setRef = useCallback ( ( newRef : MapRef | null ) => setMapRef ( newRef ) , [ ] ) ;
23
24
24
- useEffect ( ( ) => {
25
+ const resetBoundaries = useCallback ( ( ) => {
25
26
if ( ! waypoints || waypoints . length === 0 ) {
26
27
return ;
27
28
}
@@ -47,13 +48,26 @@ const MapView = forwardRef<MapViewHandle, MapViewProps>(
47
48
map . fitBounds ( [ northEast , southWest ] , { padding : mapPadding } ) ;
48
49
} , [ waypoints , mapRef , mapPadding , directionCoordinates ] ) ;
49
50
51
+ useEffect ( resetBoundaries , [ resetBoundaries ] ) ;
52
+
53
+ useEffect ( ( ) => {
54
+ if ( ! shouldResetBoundaries ) {
55
+ return ;
56
+ }
57
+
58
+ resetBoundaries ( ) ;
59
+ setShouldResetBoundaries ( false ) ;
60
+ // eslint-disable-next-line react-hooks/exhaustive-deps -- this effect only needs to run when the boundaries reset is forced
61
+ } , [ shouldResetBoundaries ] ) ;
62
+
50
63
useEffect ( ( ) => {
51
64
if ( ! mapRef ) {
52
65
return ;
53
66
}
54
67
55
68
const resizeObserver = new ResizeObserver ( ( ) => {
56
69
mapRef . resize ( ) ;
70
+ setShouldResetBoundaries ( true ) ;
57
71
} ) ;
58
72
resizeObserver . observe ( mapRef . getContainer ( ) ) ;
59
73
0 commit comments