diff --git a/CHANGELOG.md b/CHANGELOG.md index 21bba640..c2ac7cf5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,6 @@ ### 2.17.0-rc.1 +* [iOS] Fix annotation interaction handlers (tap, drag etc.) not working after annotation update. * Add the ability to get all annotations from an annotation manager. * Add `customData` field to annotations to be able to pass user data. diff --git a/ios/mapbox_maps_flutter/Sources/mapbox_maps_flutter/Classes/Annotations/CircleAnnotationController.swift b/ios/mapbox_maps_flutter/Sources/mapbox_maps_flutter/Classes/Annotations/CircleAnnotationController.swift index a8d04d20..c39daf1f 100644 --- a/ios/mapbox_maps_flutter/Sources/mapbox_maps_flutter/Classes/Annotations/CircleAnnotationController.swift +++ b/ios/mapbox_maps_flutter/Sources/mapbox_maps_flutter/Classes/Annotations/CircleAnnotationController.swift @@ -27,39 +27,7 @@ final class CircleAnnotationController: BaseAnnotationMessenger) -> Void) { do { - let updatedAnnotation = annotation.toCircleAnnotation() + var updatedAnnotation = annotation.toCircleAnnotation() + updatedAnnotation.configureHandlers(controller: self, managerId: managerId) try update(annotation: updatedAnnotation, managerId: managerId) completion(.success(())) } catch { @@ -438,5 +407,41 @@ extension MapboxMaps.CircleAnnotation { ) } } + +extension MapboxMaps.CircleAnnotation { + mutating func configureHandlers(controller: CircleAnnotationController, managerId: String) { + var configured = self + tapHandler = { [weak controller] _ in + let context = CircleAnnotationInteractionContext( + annotation: configured.toFLTCircleAnnotation(), + gestureState: .ended) + return controller?.tap(context, managerId: managerId) ?? false + } + longPressHandler = { [weak controller] _ in + let context = CircleAnnotationInteractionContext( + annotation: configured.toFLTCircleAnnotation(), + gestureState: .ended) + return controller?.longPress(context, managerId: managerId) ?? false + } + dragBeginHandler = { [weak controller] (annotation, _) in + let context = CircleAnnotationInteractionContext( + annotation: annotation.toFLTCircleAnnotation(), + gestureState: .started) + return controller?.drag(context, managerId: managerId) ?? false + } + dragChangeHandler = { [weak controller] (annotation, _) in + let context = CircleAnnotationInteractionContext( + annotation: annotation.toFLTCircleAnnotation(), + gestureState: .changed) + controller?.drag(context, managerId: managerId) + } + dragEndHandler = { [weak controller] (annotation, _) in + let context = CircleAnnotationInteractionContext( + annotation: annotation.toFLTCircleAnnotation(), + gestureState: .ended) + controller?.drag(context, managerId: managerId) + } + } +} // End of generated file. // swiftlint:enable file_length diff --git a/ios/mapbox_maps_flutter/Sources/mapbox_maps_flutter/Classes/Annotations/PointAnnotationController.swift b/ios/mapbox_maps_flutter/Sources/mapbox_maps_flutter/Classes/Annotations/PointAnnotationController.swift index 8a4f7517..134ab8af 100644 --- a/ios/mapbox_maps_flutter/Sources/mapbox_maps_flutter/Classes/Annotations/PointAnnotationController.swift +++ b/ios/mapbox_maps_flutter/Sources/mapbox_maps_flutter/Classes/Annotations/PointAnnotationController.swift @@ -27,39 +27,7 @@ final class PointAnnotationController: BaseAnnotationMessenger) -> Void) { do { - let updatedAnnotation = annotation.toPointAnnotation() + var updatedAnnotation = annotation.toPointAnnotation() + updatedAnnotation.configureHandlers(controller: self, managerId: managerId) try update(annotation: updatedAnnotation, managerId: managerId) completion(.success(())) } catch { @@ -1534,5 +1503,41 @@ extension MapboxMaps.PointAnnotation { ) } } + +extension MapboxMaps.PointAnnotation { + mutating func configureHandlers(controller: PointAnnotationController, managerId: String) { + var configured = self + tapHandler = { [weak controller] _ in + let context = PointAnnotationInteractionContext( + annotation: configured.toFLTPointAnnotation(), + gestureState: .ended) + return controller?.tap(context, managerId: managerId) ?? false + } + longPressHandler = { [weak controller] _ in + let context = PointAnnotationInteractionContext( + annotation: configured.toFLTPointAnnotation(), + gestureState: .ended) + return controller?.longPress(context, managerId: managerId) ?? false + } + dragBeginHandler = { [weak controller] (annotation, _) in + let context = PointAnnotationInteractionContext( + annotation: annotation.toFLTPointAnnotation(), + gestureState: .started) + return controller?.drag(context, managerId: managerId) ?? false + } + dragChangeHandler = { [weak controller] (annotation, _) in + let context = PointAnnotationInteractionContext( + annotation: annotation.toFLTPointAnnotation(), + gestureState: .changed) + controller?.drag(context, managerId: managerId) + } + dragEndHandler = { [weak controller] (annotation, _) in + let context = PointAnnotationInteractionContext( + annotation: annotation.toFLTPointAnnotation(), + gestureState: .ended) + controller?.drag(context, managerId: managerId) + } + } +} // End of generated file. // swiftlint:enable file_length diff --git a/ios/mapbox_maps_flutter/Sources/mapbox_maps_flutter/Classes/Annotations/PolygonAnnotationController.swift b/ios/mapbox_maps_flutter/Sources/mapbox_maps_flutter/Classes/Annotations/PolygonAnnotationController.swift index 713865b5..939cb706 100644 --- a/ios/mapbox_maps_flutter/Sources/mapbox_maps_flutter/Classes/Annotations/PolygonAnnotationController.swift +++ b/ios/mapbox_maps_flutter/Sources/mapbox_maps_flutter/Classes/Annotations/PolygonAnnotationController.swift @@ -27,39 +27,7 @@ final class PolygonAnnotationController: BaseAnnotationMessenger) -> Void) { do { - let updatedAnnotation = annotation.toPolygonAnnotation() + var updatedAnnotation = annotation.toPolygonAnnotation() + updatedAnnotation.configureHandlers(controller: self, managerId: managerId) try update(annotation: updatedAnnotation, managerId: managerId) completion(.success(())) } catch { @@ -445,5 +414,41 @@ extension MapboxMaps.PolygonAnnotation { ) } } + +extension MapboxMaps.PolygonAnnotation { + mutating func configureHandlers(controller: PolygonAnnotationController, managerId: String) { + var configured = self + tapHandler = { [weak controller] _ in + let context = PolygonAnnotationInteractionContext( + annotation: configured.toFLTPolygonAnnotation(), + gestureState: .ended) + return controller?.tap(context, managerId: managerId) ?? false + } + longPressHandler = { [weak controller] _ in + let context = PolygonAnnotationInteractionContext( + annotation: configured.toFLTPolygonAnnotation(), + gestureState: .ended) + return controller?.longPress(context, managerId: managerId) ?? false + } + dragBeginHandler = { [weak controller] (annotation, _) in + let context = PolygonAnnotationInteractionContext( + annotation: annotation.toFLTPolygonAnnotation(), + gestureState: .started) + return controller?.drag(context, managerId: managerId) ?? false + } + dragChangeHandler = { [weak controller] (annotation, _) in + let context = PolygonAnnotationInteractionContext( + annotation: annotation.toFLTPolygonAnnotation(), + gestureState: .changed) + controller?.drag(context, managerId: managerId) + } + dragEndHandler = { [weak controller] (annotation, _) in + let context = PolygonAnnotationInteractionContext( + annotation: annotation.toFLTPolygonAnnotation(), + gestureState: .ended) + controller?.drag(context, managerId: managerId) + } + } +} // End of generated file. // swiftlint:enable file_length diff --git a/ios/mapbox_maps_flutter/Sources/mapbox_maps_flutter/Classes/Annotations/PolylineAnnotationController.swift b/ios/mapbox_maps_flutter/Sources/mapbox_maps_flutter/Classes/Annotations/PolylineAnnotationController.swift index af028ef7..6b7b3c44 100644 --- a/ios/mapbox_maps_flutter/Sources/mapbox_maps_flutter/Classes/Annotations/PolylineAnnotationController.swift +++ b/ios/mapbox_maps_flutter/Sources/mapbox_maps_flutter/Classes/Annotations/PolylineAnnotationController.swift @@ -27,39 +27,7 @@ final class PolylineAnnotationController: BaseAnnotationMessenger) -> Void) { do { - let updatedAnnotation = annotation.toPolylineAnnotation() + var updatedAnnotation = annotation.toPolylineAnnotation() + updatedAnnotation.configureHandlers(controller: self, managerId: managerId) try update(annotation: updatedAnnotation, managerId: managerId) completion(.success(())) } catch { @@ -754,5 +723,41 @@ extension MapboxMaps.PolylineAnnotation { ) } } + +extension MapboxMaps.PolylineAnnotation { + mutating func configureHandlers(controller: PolylineAnnotationController, managerId: String) { + var configured = self + tapHandler = { [weak controller] _ in + let context = PolylineAnnotationInteractionContext( + annotation: configured.toFLTPolylineAnnotation(), + gestureState: .ended) + return controller?.tap(context, managerId: managerId) ?? false + } + longPressHandler = { [weak controller] _ in + let context = PolylineAnnotationInteractionContext( + annotation: configured.toFLTPolylineAnnotation(), + gestureState: .ended) + return controller?.longPress(context, managerId: managerId) ?? false + } + dragBeginHandler = { [weak controller] (annotation, _) in + let context = PolylineAnnotationInteractionContext( + annotation: annotation.toFLTPolylineAnnotation(), + gestureState: .started) + return controller?.drag(context, managerId: managerId) ?? false + } + dragChangeHandler = { [weak controller] (annotation, _) in + let context = PolylineAnnotationInteractionContext( + annotation: annotation.toFLTPolylineAnnotation(), + gestureState: .changed) + controller?.drag(context, managerId: managerId) + } + dragEndHandler = { [weak controller] (annotation, _) in + let context = PolylineAnnotationInteractionContext( + annotation: annotation.toFLTPolylineAnnotation(), + gestureState: .ended) + controller?.drag(context, managerId: managerId) + } + } +} // End of generated file. // swiftlint:enable file_length