From 5256c5ae20482699b7bf4a349f8da6f729075d50 Mon Sep 17 00:00:00 2001 From: Alfonso Grillo Date: Fri, 11 Aug 2023 14:31:56 +0200 Subject: [PATCH] Fix MapLibreStaticMapView referesh (#1481) --- .../Sources/Other/MapLibre/MapLibreStaticMapView.swift | 8 ++++++-- .../View/Timeline/LocationRoomTimelineView.swift | 5 +++-- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/ElementX/Sources/Other/MapLibre/MapLibreStaticMapView.swift b/ElementX/Sources/Other/MapLibre/MapLibreStaticMapView.swift index 151cb5232..f88260a86 100644 --- a/ElementX/Sources/Other/MapLibre/MapLibreStaticMapView.swift +++ b/ElementX/Sources/Other/MapLibre/MapLibreStaticMapView.swift @@ -22,7 +22,9 @@ struct MapLibreStaticMapView: View { private let zoomLevel: Double private let mapTilerStatic: MapTilerStaticMapProtocol private let mapTilerAttributionPlacement: MapTilerAttributionPlacement + private let mapSize: CGSize private let pinAnnotationView: PinAnnotation + @Environment(\.colorScheme) private var colorScheme @State private var fetchAttempt = 0 @@ -30,11 +32,13 @@ struct MapLibreStaticMapView: View { zoomLevel: Double, attributionPlacement: MapTilerAttributionPlacement, mapTilerStatic: MapTilerStaticMapProtocol, + mapSize: CGSize, @ViewBuilder pinAnnotationView: () -> PinAnnotation) { self.coordinates = coordinates self.zoomLevel = zoomLevel self.mapTilerStatic = mapTilerStatic mapTilerAttributionPlacement = attributionPlacement + self.mapSize = mapSize self.pinAnnotationView = pinAnnotationView() } @@ -43,7 +47,7 @@ struct MapLibreStaticMapView: View { if let url = mapTilerStatic.staticMapURL(for: colorScheme.mapStyle, coordinates: coordinates, zoomLevel: zoomLevel, - size: geometry.size, + size: mapSize, // temporary using a fixed size since the refresh doesn't work properly on the UITableView based timeline attribution: mapTilerAttributionPlacement) { AsyncImage(url: url) { phase in switch phase { @@ -109,7 +113,7 @@ struct MapLibreStaticMapView_Previews: PreviewProvider { MapLibreStaticMapView(coordinates: CLLocationCoordinate2D(), zoomLevel: 15, attributionPlacement: .bottomLeft, - mapTilerStatic: MapTilerStaticMapMock()) { + mapTilerStatic: MapTilerStaticMapMock(), mapSize: .init(width: 300, height: 200)) { Image(systemName: "mappin.circle.fill") .padding(.bottom, 35) } diff --git a/ElementX/Sources/Screens/RoomScreen/View/Timeline/LocationRoomTimelineView.swift b/ElementX/Sources/Screens/RoomScreen/View/Timeline/LocationRoomTimelineView.swift index 10105f6e8..b8797f58e 100644 --- a/ElementX/Sources/Screens/RoomScreen/View/Timeline/LocationRoomTimelineView.swift +++ b/ElementX/Sources/Screens/RoomScreen/View/Timeline/LocationRoomTimelineView.swift @@ -27,7 +27,7 @@ struct LocationRoomTimelineView: View { descriptionView .frame(maxWidth: mapAspectRatio * mapMaxHeight, alignment: .leading) - MapLibreStaticMapView(geoURI: geoURI) { + MapLibreStaticMapView(geoURI: geoURI, mapSize: .init(width: mapAspectRatio * mapMaxHeight, height: mapMaxHeight)) { LocationMarkerView() } .frame(maxHeight: mapMaxHeight) @@ -56,12 +56,13 @@ struct LocationRoomTimelineView: View { } private extension MapLibreStaticMapView { - init(geoURI: GeoURI, @ViewBuilder pinAnnotationView: () -> PinAnnotation) { + init(geoURI: GeoURI, mapSize: CGSize, @ViewBuilder pinAnnotationView: () -> PinAnnotation) { self.init(coordinates: .init(latitude: geoURI.latitude, longitude: geoURI.longitude), zoomLevel: 15, attributionPlacement: .bottomLeft, mapTilerStatic: MapTilerStaticMap(baseURL: ServiceLocator.shared.settings.mapTilerBaseURL, key: ServiceLocator.shared.settings.mapTilerApiKey), + mapSize: mapSize, pinAnnotationView: pinAnnotationView) } }