Did not get the Map Scroll End event in SwiftUI

207 Views Asked by At

We are using the Map functionality with annotations.

Functionality:- We have 2000 records in the array but we need to filter 150 records according to the region changed in the Map in SwiftUI. But there is no scroll end event of the Map in SwiftUI.

We used the below code

 Map(coordinateRegion: self.$viewModel.region, interactionModes: [.all], annotationItems:  self.viewModel.mapLocations), annotationContent: { pin in

 }

We got the latest updated region in .onChange(of: viewModel.region) }. But we did not get the map scroll end event. We put the code in onChange(of) but it's lagging while scrolling. So, It's not worked for us.

Also. We tried Drag-Gesture but won't worked.


.gesture(DragGesture()
        .onEnded { value in
          //Did not getting this event while map scroll end
         })

1

There are 1 best solutions below

0
On BEST ANSWER

SwiftUI does not usually work as expected when trying to override gestures for built-in views especially with Map

Combine with .debounce is usually a better solution when it comes to filtering based on rapid changing @Published like a region