From 60d8c67be70617334a9b4af5d0e344e63d09f876 Mon Sep 17 00:00:00 2001 From: "google-labs-jules[bot]" <161369871+google-labs-jules[bot]@users.noreply.github.com> Date: Sat, 22 Aug 2026 14:23:55 +0000 Subject: [PATCH 1/2] Simplify annotation drag lifecycle function Co-locate annotation drag delegate callback in AnnotationController.swift with other annotation delegate methods and break down drag handling into dedicated helper functions. Co-authored-by: esenmx <43244505+esenmx@users.noreply.github.com> --- .../Annotations/AnnotationController.swift | 29 +++++++++++++++++++ .../MapView/MapKitViewHost.swift | 21 -------------- 2 files changed, 29 insertions(+), 21 deletions(-) diff --git a/darwin/mapkit_flutter/Sources/mapkit_flutter/Annotations/AnnotationController.swift b/darwin/mapkit_flutter/Sources/mapkit_flutter/Annotations/AnnotationController.swift index a1663d3..0761c7a 100644 --- a/darwin/mapkit_flutter/Sources/mapkit_flutter/Annotations/AnnotationController.swift +++ b/darwin/mapkit_flutter/Sources/mapkit_flutter/Annotations/AnnotationController.swift @@ -44,6 +44,35 @@ extension MapKitViewHost { return nil } + // Annotation drag lifecycle. + public func mapView(_ mapView: MKMapView, + annotationView view: MKAnnotationView, + didChange newState: MKAnnotationView.DragState, + fromOldState oldState: MKAnnotationView.DragState) { + guard let annotation = view.annotation as? FlutterAnnotation else { return } + self.handleAnnotationDragChange(annotation: annotation, newState: newState) + } + + private func handleAnnotationDragChange(annotation: FlutterAnnotation, newState: MKAnnotationView.DragState) { + let id = annotation.id + let coordinate = PlatformCoordinate.from(annotation.coordinate) + switch newState { + case .starting: + self.flutterApi.onAnnotationDragStart(annotationId: id, coordinate: coordinate) { _ in } + case .dragging: + self.flutterApi.onAnnotationDrag(annotationId: id, coordinate: coordinate) { _ in } + case .ending, .canceling: + self.handleAnnotationDragEnd(annotation: annotation, id: id, coordinate: coordinate) + default: + break + } + } + + private func handleAnnotationDragEnd(annotation: FlutterAnnotation, id: String, coordinate: PlatformCoordinate) { + annotation.wasDragged = true + self.flutterApi.onAnnotationDragEnd(annotationId: id, coordinate: coordinate) { _ in } + } + private func getClusterAnnotationView(cluster: MKClusterAnnotation) -> MKAnnotationView { let id = "mapkit.cluster" self.mapView.register(MKMarkerAnnotationView.self, forAnnotationViewWithReuseIdentifier: id) diff --git a/darwin/mapkit_flutter/Sources/mapkit_flutter/MapView/MapKitViewHost.swift b/darwin/mapkit_flutter/Sources/mapkit_flutter/MapView/MapKitViewHost.swift index f6cebcf..67a73b3 100644 --- a/darwin/mapkit_flutter/Sources/mapkit_flutter/MapView/MapKitViewHost.swift +++ b/darwin/mapkit_flutter/Sources/mapkit_flutter/MapView/MapKitViewHost.swift @@ -262,27 +262,6 @@ extension MapKitViewHost: MKMapViewDelegate { self.flutterApi.onCameraMoveStarted { _ in } } - // Annotation drag lifecycle. - public func mapView(_ mapView: MKMapView, - annotationView view: MKAnnotationView, - didChange newState: MKAnnotationView.DragState, - fromOldState oldState: MKAnnotationView.DragState) { - guard let annotation = view.annotation as? FlutterAnnotation else { return } - let id = annotation.id - let coordinate = PlatformCoordinate.from(annotation.coordinate) - switch newState { - case .starting: - self.flutterApi.onAnnotationDragStart(annotationId: id, coordinate: coordinate) { _ in } - case .dragging: - self.flutterApi.onAnnotationDrag(annotationId: id, coordinate: coordinate) { _ in } - case .ending, .canceling: - annotation.wasDragged = true - self.flutterApi.onAnnotationDragEnd(annotationId: id, coordinate: coordinate) { _ in } - default: - break - } - } - public func mapViewDidFailLoadingMap(_ mapView: MKMapView, withError error: Error) { self.flutterApi.onDidFailLoadingMap(error: error.localizedDescription) { _ in } } From 75f6dd4bb288877ccb2e61ddcda19a944342e8d3 Mon Sep 17 00:00:00 2001 From: Mehmet Esen Date: Sun, 23 Aug 2026 19:08:14 +0300 Subject: [PATCH 2/2] refactor(darwin): keep drag delegate body verbatim in AnnotationController Drop the handleAnnotationDragChange/handleAnnotationDragEnd helper split so the relocation reads as a pure move (+21/-21, added block byte-identical to the removed one). Keeps `annotation.wasDragged = true` ordered before onAnnotationDragEnd, which annotationsToChange relies on. Co-Authored-By: Claude Fable 5 --- .../Annotations/AnnotationController.swift | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) diff --git a/darwin/mapkit_flutter/Sources/mapkit_flutter/Annotations/AnnotationController.swift b/darwin/mapkit_flutter/Sources/mapkit_flutter/Annotations/AnnotationController.swift index 0761c7a..7710a04 100644 --- a/darwin/mapkit_flutter/Sources/mapkit_flutter/Annotations/AnnotationController.swift +++ b/darwin/mapkit_flutter/Sources/mapkit_flutter/Annotations/AnnotationController.swift @@ -50,10 +50,6 @@ extension MapKitViewHost { didChange newState: MKAnnotationView.DragState, fromOldState oldState: MKAnnotationView.DragState) { guard let annotation = view.annotation as? FlutterAnnotation else { return } - self.handleAnnotationDragChange(annotation: annotation, newState: newState) - } - - private func handleAnnotationDragChange(annotation: FlutterAnnotation, newState: MKAnnotationView.DragState) { let id = annotation.id let coordinate = PlatformCoordinate.from(annotation.coordinate) switch newState { @@ -62,17 +58,13 @@ extension MapKitViewHost { case .dragging: self.flutterApi.onAnnotationDrag(annotationId: id, coordinate: coordinate) { _ in } case .ending, .canceling: - self.handleAnnotationDragEnd(annotation: annotation, id: id, coordinate: coordinate) + annotation.wasDragged = true + self.flutterApi.onAnnotationDragEnd(annotationId: id, coordinate: coordinate) { _ in } default: break } } - private func handleAnnotationDragEnd(annotation: FlutterAnnotation, id: String, coordinate: PlatformCoordinate) { - annotation.wasDragged = true - self.flutterApi.onAnnotationDragEnd(annotationId: id, coordinate: coordinate) { _ in } - } - private func getClusterAnnotationView(cluster: MKClusterAnnotation) -> MKAnnotationView { let id = "mapkit.cluster" self.mapView.register(MKMarkerAnnotationView.self, forAnnotationViewWithReuseIdentifier: id)