mapbox / mapbox-maps-ios

Interactive, thoroughly customizable maps for iOS powered by vector tiles and Metal
https://www.mapbox.com/mapbox-mobile-sdk
Other
464 stars 150 forks source link

Question on SwiftUI #2235

Open warmachinesocial opened 1 week ago

warmachinesocial commented 1 week ago

Hey folks, I have been coding in swift and swiftui past a year I was looking to mapbox's library but in swiftui which wasn't there at the time. I love swiftui, but don't know the internals of it so question was why we using UIViewRepresentable? that's what I had to use last year when apple didn't support mapkit for swiftui.

Could someone explain me? It feels more like wrapper(not entirely but I have no clue on UIkit)

https://github.com/mapbox/mapbox-maps-ios/blob/e68d2e7beebed7aab1a67f4ffaf48b19ab05fc9c/Sources/MapboxMaps/SwiftUI/Map.swift#L47

aleksproger commented 5 days ago

Hey @warmachinesocial, our SwiftUI Map is UIViewControllerRepresentable because indeed internally it wraps a MapView that was built with UIKit, so we reuse most of the internals between our UIKit and SwiftUI API. And we add new interfaces and mechanisms to make the SwiftUI Map feel and behave in a way similar to SwiftUI views.