[Android] mapPadding is lost when the native map is recreated on screen re-attach (onMapReady re-fires; value-equal prop is never re-sent)
Maintainer antworten meist innerhalb von 2 Tagen
Bewertung
- Schwierigkeit
- 4/5
- Geschätzter Aufwand
- 3-5 Tage
- Anfängerfreundlichkeit
- 52/100
- Issue-Typ
- Bug
- Klarheit
- Größtenteils klar
- Aktivitätsstatus
- Aktiv
- Tech-Stack
- android, react-native, typescript
- Bereich
- mobile
Rechercherichtung
Start at the Android native MapView handling for onMapReady and mapPadding, then trace how setPadding behaves when the native GoogleMap is recreated after screen re-attach under Fabric. Reproduce the tab-detach scenario and verify that the recreated map retains the current padding without requiring a value-changing workaround.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Beschreibung
Summary
On Android (New Architecture / Fabric), when a MapView sits inside a react-navigation screen and that screen is detached and re-attached (e.g. the surrounding bottom-tab set changes while the user is on another screen), the native GoogleMap is recreated - onMapReady fires a second time for the same component instance. The mapPadding that was in effect is not re-applied to the recreated map: the value applied during the new view's mount is swallowed by the still-initializing map, and because the JS mapPadding prop is value-equal across renders, Fabric never re-sends it. The map is left with zero padding indefinitely - visibly, the native My Location button jumps to the raw top-right corner under the system status bar.
This looks like a residual case of the padding-application family fixed by #5151 (#5150 / #5152 / #5153): those fixes (contained in 1.28.2) cover the initial mount, but not a native map recreated after a screen re-attach.
Reproducible sample code
// Map screen registered inside a react-navigation bottom-tabs navigator
// whose tab set changes while this screen is blurred (a conditional tab).
import React from 'react';
import MapView, { PROVIDER_GOOGLE } from 'react-native-maps';
export default function MapScreen() {
const [ready, setReady] = React.useState(false);
return (
<MapView
style={{ flex: 1 }}
provider={PROVIDER_GOOGLE}
showsUserLocation
showsMyLocationButton
onMapReady={() => {
console.log('onMapReady'); // fires AGAIN after the screen re-attaches
setReady(true);
}}
mapPadding={
ready ? { top: 120, right: 0, bottom: 0, left: 0 } : undefined
}
initialRegion={{
latitude: 42.7,
longitude: 25.3,
latitudeDelta: 1,
longitudeDelta: 1
}}
/>
);
}
Steps to reproduce
- Render the MapView above in a screen of a react-navigation bottom-tabs navigator, with the
mapPaddingtop offset applied. The native My Location button renders below the offset (correct). - Navigate away (push a screen over the tabs), and while the map screen is blurred change the tab set (add or remove a conditional tab), so the map screen goes through a detach/re-attach.
- Navigate back to the map screen.
- Watch the console:
onMapReadyfires a second time - the native map view was recreated. The My Location button now renders under the status bar; the previously appliedmapPaddingis gone and never comes back (the JS prop value did not change, so Fabric dedupes it and nothing reaches the native side).
Expected result
The recreated native map retains (or re-applies) the mapPadding currently set on the component - the My Location button stays below the padding offset.
Actual result
The recreated map has zero padding; the My Location button renders under the system status bar and stays there indefinitely.
Workaround we ship: nudge the padding value by 1px inside onMapReady, forcing a post-init prop update Fabric cannot dedupe. Note for anyone else affected: anchoring the nudge on a navigation focus event is NOT reliable - it races the native map recreation (we reproduced both orderings on different devices); onMapReady is the deterministic signal that the recreated map can accept setPadding.
React Native Maps Version
1.28.2
What platforms are you seeing the problem on?
Android
React Native Version
0.86.0
What version of Expo are you using?
Not using Expo
Device(s)
Pixel 9 emulator (Android 16) and physical Android device
Additional information
- Reproduced on react-native-maps 1.28.2, React Native 0.86.0, New Architecture (Fabric),
googleRendererLATEST. - Not fixed by upgrading: the 1.29.0 changelog contains no padding/restore-related changes.
- Related prior work already contained in 1.28.2: #5151 (fixes #5150/#5152/#5153, initial-mount padding), #5727 (state-restore double-initialization).
- The user-location dot (
showsUserLocation) survives the recreation, so the loss is specific to the padding state, not the whole prop set.
- Vorherrschende Sprache
- TypeScript
- Sterne
- 16k
- Forks
- 5k
- Ø Merge
- 1 T. 4 Std.
- Gemergte PRs (30 T.)
- 4
Entwicklungsumgebung
- Kein Dockerfile und keine Docker-Compose-Datei
- Hat eine Pull-Request-Vorlage
- Beitragsleitfaden lesen
Erste Schritte
- Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
- Forken Sie das Repository und arbeiten Sie in einem Branch.
- Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.
Mehr aus react-native-maps/react-native-maps
-
[Android] onMarkerClick calls showInfoWindow() on markers that have no info window, raising them above every zIndexEvtl. vergeben Ein verknüpfter Pull Request ist offen oder bereits gemergt. Offen
Schwierigkeit 1/5 1-3 Stunden Anfängerfreundlichkeit 88/100
react-native-maps/react-native-maps#6006 ·
Maintainer antworten meist innerhalb von 2 Tagen
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 88/100
react-native-maps/react-native-maps#6005 ·
Maintainer antworten meist innerhalb von 2 Tagen
-
Schwierigkeit 1/5 Unter einer Stunde Anfängerfreundlichkeit 90/100
react-native-maps/react-native-maps#6003 ·
Maintainer antworten meist innerhalb von 2 Tagen
-
onPress/onLongPress `position` is in device pixels on Android, points on iOSEvtl. vergeben @ivan-kolesov hat das vor 29 Tagen übernommen. Offen
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 78/100
react-native-maps/react-native-maps#5998 ·
Maintainer antworten meist innerhalb von 2 Tagen
-
Fabric: ReactViewGroup cannot be cast to MapMarker in MarkerManager.onLayoutChange (leaked layout listener on recycled views)Evtl. vergeben @huytdps13400 hat das vor 43 Tagen übernommen. Offen
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 84/100
react-native-maps/react-native-maps#5987 · 1 Kommentar ·
Maintainer antworten meist innerhalb von 2 Tagen
Alle Issues in react-native-maps/react-native-maps