admin管理员组文章数量:1434960
I update the map view by scrolling, which fires the handleRegionChange
callback.
For some reason, if I don't add if (!data.length) return null
, first render won't render the markers (understandable because there's no data yet). When the data does resolve, it doesn't trigger a rerender of the markers. If I scroll on the map it also crashes Expo
Unfortunately, if I add this, the whole map rerenders every time I want to I get quite a janky experience with the MapMarkers rendering on the map, and the whole map rerenders.
I think I'm missing something, but not quite sure what it is. I've tried creating a <MapMarkers mapViewRegion={mapViewRegion} />
component where the data fetching is isolated to the MapMarkers, to no avail.
function MapViewWithMarkers({ location }: { location: LocationObject }) {
const mapRef = useRef<MapView>(null);
const [mapViewRegion, setMapViewRegion] = useState<Region>({
latitude: location.coords.latitude,
longitude: location.coords.longitude,
latitudeDelta: 0.015,
longitudeDelta: 0.015,
});
const handleRegionChange = (region: Region) => {
setMapViewRegion(region);
};
const { data, isLoading } = trpc.venues.useQuery({ lat: mapViewRegion.latitude, lon: mapViewRegion.longitude, limit: 10 });
// if (!data?.length) return null;
return (
<View style={{ flex: 1 }}>
<MapView
ref={mapRef}
showsUserLocation={true}
region={mapViewRegion}
showsPointsOfInterest={false}
onRegionChangeComplete={handleRegionChange}
style={{ width: "100%", height: "100%", flex: 1 }}
loadingEnabled={true}
showsMyLocationButton={true}
>
{data?.map((venue) => (
<MapMarker
key={venue.id}
identifier={venue.id.toString()}
coordinate={{ latitude: Number(venue.latitude), longitude: Number(venue.longitude) }}
title={venue.name}
description={`${venue.address}`}
/>
))}
</MapView>
</View>
);
}
本文标签: expoReact Native Maps crashing when data is refetched onRegionChangeCompleteStack Overflow
版权声明:本文标题:expo - React Native Maps crashing when data is refetched onRegionChangeComplete - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745633204a2667396.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论