MapAnnotation button action not working (SwiftUI 2.0 Map)
Asked Answered
G

0

6

I'm just trying to touch on the map annotations, but the button's action is not working. I've tried to figure how to solve it but nothing so far. I'm wanting to use the Map without make de UIKit bridge.

Here is my map:

Map(coordinateRegion: $locationManager.currentLocation,
    interactionModes: .all,
    showsUserLocation: true,
    userTrackingMode: $trackingMode,
    annotationItems: $locationManager.annotations.wrappedValue) { location in
        MapAnnotation(coordinate: location.coordinate, anchorPoint: CGPoint(x: 0.5, y: 0.5)) {
            MapAnnotationView(name: location.title, image: Image("dog"))
        }
    }

And here is my MapAnnotationView:

import SwiftUI

struct MapAnnotationView: View {
    var name: String
    var image: Image
    @State var size: CGFloat = 20

    var body: some View {
        VStack {
            Button(action: {
                size = $size.wrappedValue == 20 ? 60 : 20
                print("TAPPED =====>")
            }, label: {
                image
                    .resizable(capInsets: EdgeInsets(), resizingMode: .stretch)
                    .frame(width: $size.wrappedValue, height: $size.wrappedValue, alignment: .center)
                    .clipShape(Circle())
                    .overlay(Circle().stroke(Color.white, lineWidth: 2))
                Text(name)
                    .font(.caption)
                    .fontWeight(.semibold)
                    .foregroundColor(.primary)
            })

        }
        .shadow(radius: 5)
    }
}
Guyer answered 7/9, 2020 at 3:54 Comment(5)
Same issue here. I'll let you know if I find sth.Hirschfeld
Same... any clues?Wodge
nothing yet.... I've just made the Bridge to use the UIKit map... but this answer would save a lot of time.Guyer
any update guys? I got same issueSeersucker
Another approach could be applying an onTapGesture { ... } modifier on your map annotation view - unfortunately from my testing, this also doesn't seem to work as things stand.Protestant

© 2022 - 2024 — McMap. All rights reserved.