Skip to content

Commit 0c0f179

Browse files
evil159pjleonard37
andauthored
fix annotation interactions stop working after annotation update (#1063)
* fix annotation interactions stop working after annotation update * add changelog * Update CHANGELOG.md Co-authored-by: Patrick Leonard <[email protected]> --------- Co-authored-by: Patrick Leonard <[email protected]>
1 parent c8785f4 commit 0c0f179

File tree

5 files changed

+157
-136
lines changed

5 files changed

+157
-136
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
### 2.17.0-rc.1
22

3+
* [iOS] Fix annotation interaction handlers (tap, drag etc.) not working after annotation update.
34
* Add the ability to get all annotations from an annotation manager.
45
* Add `customData` field to annotations to be able to pass user data.
56

ios/mapbox_maps_flutter/Sources/mapbox_maps_flutter/Classes/Annotations/CircleAnnotationController.swift

Lines changed: 39 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -27,39 +27,7 @@ final class CircleAnnotationController: BaseAnnotationMessenger<CircleAnnotation
2727
do {
2828
let annotations = annotationOptions.map({ options in
2929
var annotation = options.toCircleAnnotation()
30-
annotation.tapHandler = { [weak self] (context) in
31-
guard let self else { return false }
32-
let context = CircleAnnotationInteractionContext(
33-
annotation: annotation.toFLTCircleAnnotation(),
34-
gestureState: .ended)
35-
return self.tap(context, managerId: managerId)
36-
}
37-
annotation.longPressHandler = { [weak self] (context) in
38-
guard let self else { return false }
39-
let context = CircleAnnotationInteractionContext(
40-
annotation: annotation.toFLTCircleAnnotation(),
41-
gestureState: .ended)
42-
return self.longPress(context, managerId: managerId)
43-
}
44-
annotation.dragBeginHandler = { [weak self] (annotation, context) in
45-
guard let self else { return false }
46-
let context = CircleAnnotationInteractionContext(
47-
annotation: annotation.toFLTCircleAnnotation(),
48-
gestureState: .started)
49-
return self.drag(context, managerId: managerId)
50-
}
51-
annotation.dragChangeHandler = { [weak self] (annotation, context) in
52-
let context = CircleAnnotationInteractionContext(
53-
annotation: annotation.toFLTCircleAnnotation(),
54-
gestureState: .changed)
55-
self?.drag(context, managerId: managerId)
56-
}
57-
annotation.dragEndHandler = { [weak self] (annotation, context) in
58-
let context = CircleAnnotationInteractionContext(
59-
annotation: annotation.toFLTCircleAnnotation(),
60-
gestureState: .ended)
61-
self?.drag(context, managerId: managerId)
62-
}
30+
annotation.configureHandlers(controller: self, managerId: managerId)
6331
return annotation
6432
})
6533
try append(annotations, managerId: managerId)
@@ -71,7 +39,8 @@ final class CircleAnnotationController: BaseAnnotationMessenger<CircleAnnotation
7139

7240
func update(managerId: String, annotation: CircleAnnotation, completion: @escaping (Result<Void, Error>) -> Void) {
7341
do {
74-
let updatedAnnotation = annotation.toCircleAnnotation()
42+
var updatedAnnotation = annotation.toCircleAnnotation()
43+
updatedAnnotation.configureHandlers(controller: self, managerId: managerId)
7544
try update(annotation: updatedAnnotation, managerId: managerId)
7645
completion(.success(()))
7746
} catch {
@@ -438,5 +407,41 @@ extension MapboxMaps.CircleAnnotation {
438407
)
439408
}
440409
}
410+
411+
extension MapboxMaps.CircleAnnotation {
412+
mutating func configureHandlers(controller: CircleAnnotationController, managerId: String) {
413+
var configured = self
414+
tapHandler = { [weak controller] _ in
415+
let context = CircleAnnotationInteractionContext(
416+
annotation: configured.toFLTCircleAnnotation(),
417+
gestureState: .ended)
418+
return controller?.tap(context, managerId: managerId) ?? false
419+
}
420+
longPressHandler = { [weak controller] _ in
421+
let context = CircleAnnotationInteractionContext(
422+
annotation: configured.toFLTCircleAnnotation(),
423+
gestureState: .ended)
424+
return controller?.longPress(context, managerId: managerId) ?? false
425+
}
426+
dragBeginHandler = { [weak controller] (annotation, _) in
427+
let context = CircleAnnotationInteractionContext(
428+
annotation: annotation.toFLTCircleAnnotation(),
429+
gestureState: .started)
430+
return controller?.drag(context, managerId: managerId) ?? false
431+
}
432+
dragChangeHandler = { [weak controller] (annotation, _) in
433+
let context = CircleAnnotationInteractionContext(
434+
annotation: annotation.toFLTCircleAnnotation(),
435+
gestureState: .changed)
436+
controller?.drag(context, managerId: managerId)
437+
}
438+
dragEndHandler = { [weak controller] (annotation, _) in
439+
let context = CircleAnnotationInteractionContext(
440+
annotation: annotation.toFLTCircleAnnotation(),
441+
gestureState: .ended)
442+
controller?.drag(context, managerId: managerId)
443+
}
444+
}
445+
}
441446
// End of generated file.
442447
// swiftlint:enable file_length

ios/mapbox_maps_flutter/Sources/mapbox_maps_flutter/Classes/Annotations/PointAnnotationController.swift

Lines changed: 39 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -27,39 +27,7 @@ final class PointAnnotationController: BaseAnnotationMessenger<PointAnnotationMa
2727
do {
2828
let annotations = annotationOptions.map({ options in
2929
var annotation = options.toPointAnnotation()
30-
annotation.tapHandler = { [weak self] (context) in
31-
guard let self else { return false }
32-
let context = PointAnnotationInteractionContext(
33-
annotation: annotation.toFLTPointAnnotation(),
34-
gestureState: .ended)
35-
return self.tap(context, managerId: managerId)
36-
}
37-
annotation.longPressHandler = { [weak self] (context) in
38-
guard let self else { return false }
39-
let context = PointAnnotationInteractionContext(
40-
annotation: annotation.toFLTPointAnnotation(),
41-
gestureState: .ended)
42-
return self.longPress(context, managerId: managerId)
43-
}
44-
annotation.dragBeginHandler = { [weak self] (annotation, context) in
45-
guard let self else { return false }
46-
let context = PointAnnotationInteractionContext(
47-
annotation: annotation.toFLTPointAnnotation(),
48-
gestureState: .started)
49-
return self.drag(context, managerId: managerId)
50-
}
51-
annotation.dragChangeHandler = { [weak self] (annotation, context) in
52-
let context = PointAnnotationInteractionContext(
53-
annotation: annotation.toFLTPointAnnotation(),
54-
gestureState: .changed)
55-
self?.drag(context, managerId: managerId)
56-
}
57-
annotation.dragEndHandler = { [weak self] (annotation, context) in
58-
let context = PointAnnotationInteractionContext(
59-
annotation: annotation.toFLTPointAnnotation(),
60-
gestureState: .ended)
61-
self?.drag(context, managerId: managerId)
62-
}
30+
annotation.configureHandlers(controller: self, managerId: managerId)
6331
return annotation
6432
})
6533
try append(annotations, managerId: managerId)
@@ -71,7 +39,8 @@ final class PointAnnotationController: BaseAnnotationMessenger<PointAnnotationMa
7139

7240
func update(managerId: String, annotation: PointAnnotation, completion: @escaping (Result<Void, Error>) -> Void) {
7341
do {
74-
let updatedAnnotation = annotation.toPointAnnotation()
42+
var updatedAnnotation = annotation.toPointAnnotation()
43+
updatedAnnotation.configureHandlers(controller: self, managerId: managerId)
7544
try update(annotation: updatedAnnotation, managerId: managerId)
7645
completion(.success(()))
7746
} catch {
@@ -1534,5 +1503,41 @@ extension MapboxMaps.PointAnnotation {
15341503
)
15351504
}
15361505
}
1506+
1507+
extension MapboxMaps.PointAnnotation {
1508+
mutating func configureHandlers(controller: PointAnnotationController, managerId: String) {
1509+
var configured = self
1510+
tapHandler = { [weak controller] _ in
1511+
let context = PointAnnotationInteractionContext(
1512+
annotation: configured.toFLTPointAnnotation(),
1513+
gestureState: .ended)
1514+
return controller?.tap(context, managerId: managerId) ?? false
1515+
}
1516+
longPressHandler = { [weak controller] _ in
1517+
let context = PointAnnotationInteractionContext(
1518+
annotation: configured.toFLTPointAnnotation(),
1519+
gestureState: .ended)
1520+
return controller?.longPress(context, managerId: managerId) ?? false
1521+
}
1522+
dragBeginHandler = { [weak controller] (annotation, _) in
1523+
let context = PointAnnotationInteractionContext(
1524+
annotation: annotation.toFLTPointAnnotation(),
1525+
gestureState: .started)
1526+
return controller?.drag(context, managerId: managerId) ?? false
1527+
}
1528+
dragChangeHandler = { [weak controller] (annotation, _) in
1529+
let context = PointAnnotationInteractionContext(
1530+
annotation: annotation.toFLTPointAnnotation(),
1531+
gestureState: .changed)
1532+
controller?.drag(context, managerId: managerId)
1533+
}
1534+
dragEndHandler = { [weak controller] (annotation, _) in
1535+
let context = PointAnnotationInteractionContext(
1536+
annotation: annotation.toFLTPointAnnotation(),
1537+
gestureState: .ended)
1538+
controller?.drag(context, managerId: managerId)
1539+
}
1540+
}
1541+
}
15371542
// End of generated file.
15381543
// swiftlint:enable file_length

ios/mapbox_maps_flutter/Sources/mapbox_maps_flutter/Classes/Annotations/PolygonAnnotationController.swift

Lines changed: 39 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -27,39 +27,7 @@ final class PolygonAnnotationController: BaseAnnotationMessenger<PolygonAnnotati
2727
do {
2828
let annotations = annotationOptions.map({ options in
2929
var annotation = options.toPolygonAnnotation()
30-
annotation.tapHandler = { [weak self] (context) in
31-
guard let self else { return false }
32-
let context = PolygonAnnotationInteractionContext(
33-
annotation: annotation.toFLTPolygonAnnotation(),
34-
gestureState: .ended)
35-
return self.tap(context, managerId: managerId)
36-
}
37-
annotation.longPressHandler = { [weak self] (context) in
38-
guard let self else { return false }
39-
let context = PolygonAnnotationInteractionContext(
40-
annotation: annotation.toFLTPolygonAnnotation(),
41-
gestureState: .ended)
42-
return self.longPress(context, managerId: managerId)
43-
}
44-
annotation.dragBeginHandler = { [weak self] (annotation, context) in
45-
guard let self else { return false }
46-
let context = PolygonAnnotationInteractionContext(
47-
annotation: annotation.toFLTPolygonAnnotation(),
48-
gestureState: .started)
49-
return self.drag(context, managerId: managerId)
50-
}
51-
annotation.dragChangeHandler = { [weak self] (annotation, context) in
52-
let context = PolygonAnnotationInteractionContext(
53-
annotation: annotation.toFLTPolygonAnnotation(),
54-
gestureState: .changed)
55-
self?.drag(context, managerId: managerId)
56-
}
57-
annotation.dragEndHandler = { [weak self] (annotation, context) in
58-
let context = PolygonAnnotationInteractionContext(
59-
annotation: annotation.toFLTPolygonAnnotation(),
60-
gestureState: .ended)
61-
self?.drag(context, managerId: managerId)
62-
}
30+
annotation.configureHandlers(controller: self, managerId: managerId)
6331
return annotation
6432
})
6533
try append(annotations, managerId: managerId)
@@ -71,7 +39,8 @@ final class PolygonAnnotationController: BaseAnnotationMessenger<PolygonAnnotati
7139

7240
func update(managerId: String, annotation: PolygonAnnotation, completion: @escaping (Result<Void, Error>) -> Void) {
7341
do {
74-
let updatedAnnotation = annotation.toPolygonAnnotation()
42+
var updatedAnnotation = annotation.toPolygonAnnotation()
43+
updatedAnnotation.configureHandlers(controller: self, managerId: managerId)
7544
try update(annotation: updatedAnnotation, managerId: managerId)
7645
completion(.success(()))
7746
} catch {
@@ -445,5 +414,41 @@ extension MapboxMaps.PolygonAnnotation {
445414
)
446415
}
447416
}
417+
418+
extension MapboxMaps.PolygonAnnotation {
419+
mutating func configureHandlers(controller: PolygonAnnotationController, managerId: String) {
420+
var configured = self
421+
tapHandler = { [weak controller] _ in
422+
let context = PolygonAnnotationInteractionContext(
423+
annotation: configured.toFLTPolygonAnnotation(),
424+
gestureState: .ended)
425+
return controller?.tap(context, managerId: managerId) ?? false
426+
}
427+
longPressHandler = { [weak controller] _ in
428+
let context = PolygonAnnotationInteractionContext(
429+
annotation: configured.toFLTPolygonAnnotation(),
430+
gestureState: .ended)
431+
return controller?.longPress(context, managerId: managerId) ?? false
432+
}
433+
dragBeginHandler = { [weak controller] (annotation, _) in
434+
let context = PolygonAnnotationInteractionContext(
435+
annotation: annotation.toFLTPolygonAnnotation(),
436+
gestureState: .started)
437+
return controller?.drag(context, managerId: managerId) ?? false
438+
}
439+
dragChangeHandler = { [weak controller] (annotation, _) in
440+
let context = PolygonAnnotationInteractionContext(
441+
annotation: annotation.toFLTPolygonAnnotation(),
442+
gestureState: .changed)
443+
controller?.drag(context, managerId: managerId)
444+
}
445+
dragEndHandler = { [weak controller] (annotation, _) in
446+
let context = PolygonAnnotationInteractionContext(
447+
annotation: annotation.toFLTPolygonAnnotation(),
448+
gestureState: .ended)
449+
controller?.drag(context, managerId: managerId)
450+
}
451+
}
452+
}
448453
// End of generated file.
449454
// swiftlint:enable file_length

ios/mapbox_maps_flutter/Sources/mapbox_maps_flutter/Classes/Annotations/PolylineAnnotationController.swift

Lines changed: 39 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -27,39 +27,7 @@ final class PolylineAnnotationController: BaseAnnotationMessenger<PolylineAnnota
2727
do {
2828
let annotations = annotationOptions.map({ options in
2929
var annotation = options.toPolylineAnnotation()
30-
annotation.tapHandler = { [weak self] (context) in
31-
guard let self else { return false }
32-
let context = PolylineAnnotationInteractionContext(
33-
annotation: annotation.toFLTPolylineAnnotation(),
34-
gestureState: .ended)
35-
return self.tap(context, managerId: managerId)
36-
}
37-
annotation.longPressHandler = { [weak self] (context) in
38-
guard let self else { return false }
39-
let context = PolylineAnnotationInteractionContext(
40-
annotation: annotation.toFLTPolylineAnnotation(),
41-
gestureState: .ended)
42-
return self.longPress(context, managerId: managerId)
43-
}
44-
annotation.dragBeginHandler = { [weak self] (annotation, context) in
45-
guard let self else { return false }
46-
let context = PolylineAnnotationInteractionContext(
47-
annotation: annotation.toFLTPolylineAnnotation(),
48-
gestureState: .started)
49-
return self.drag(context, managerId: managerId)
50-
}
51-
annotation.dragChangeHandler = { [weak self] (annotation, context) in
52-
let context = PolylineAnnotationInteractionContext(
53-
annotation: annotation.toFLTPolylineAnnotation(),
54-
gestureState: .changed)
55-
self?.drag(context, managerId: managerId)
56-
}
57-
annotation.dragEndHandler = { [weak self] (annotation, context) in
58-
let context = PolylineAnnotationInteractionContext(
59-
annotation: annotation.toFLTPolylineAnnotation(),
60-
gestureState: .ended)
61-
self?.drag(context, managerId: managerId)
62-
}
30+
annotation.configureHandlers(controller: self, managerId: managerId)
6331
return annotation
6432
})
6533
try append(annotations, managerId: managerId)
@@ -71,7 +39,8 @@ final class PolylineAnnotationController: BaseAnnotationMessenger<PolylineAnnota
7139

7240
func update(managerId: String, annotation: PolylineAnnotation, completion: @escaping (Result<Void, Error>) -> Void) {
7341
do {
74-
let updatedAnnotation = annotation.toPolylineAnnotation()
42+
var updatedAnnotation = annotation.toPolylineAnnotation()
43+
updatedAnnotation.configureHandlers(controller: self, managerId: managerId)
7544
try update(annotation: updatedAnnotation, managerId: managerId)
7645
completion(.success(()))
7746
} catch {
@@ -754,5 +723,41 @@ extension MapboxMaps.PolylineAnnotation {
754723
)
755724
}
756725
}
726+
727+
extension MapboxMaps.PolylineAnnotation {
728+
mutating func configureHandlers(controller: PolylineAnnotationController, managerId: String) {
729+
var configured = self
730+
tapHandler = { [weak controller] _ in
731+
let context = PolylineAnnotationInteractionContext(
732+
annotation: configured.toFLTPolylineAnnotation(),
733+
gestureState: .ended)
734+
return controller?.tap(context, managerId: managerId) ?? false
735+
}
736+
longPressHandler = { [weak controller] _ in
737+
let context = PolylineAnnotationInteractionContext(
738+
annotation: configured.toFLTPolylineAnnotation(),
739+
gestureState: .ended)
740+
return controller?.longPress(context, managerId: managerId) ?? false
741+
}
742+
dragBeginHandler = { [weak controller] (annotation, _) in
743+
let context = PolylineAnnotationInteractionContext(
744+
annotation: annotation.toFLTPolylineAnnotation(),
745+
gestureState: .started)
746+
return controller?.drag(context, managerId: managerId) ?? false
747+
}
748+
dragChangeHandler = { [weak controller] (annotation, _) in
749+
let context = PolylineAnnotationInteractionContext(
750+
annotation: annotation.toFLTPolylineAnnotation(),
751+
gestureState: .changed)
752+
controller?.drag(context, managerId: managerId)
753+
}
754+
dragEndHandler = { [weak controller] (annotation, _) in
755+
let context = PolylineAnnotationInteractionContext(
756+
annotation: annotation.toFLTPolylineAnnotation(),
757+
gestureState: .ended)
758+
controller?.drag(context, managerId: managerId)
759+
}
760+
}
761+
}
757762
// End of generated file.
758763
// swiftlint:enable file_length

0 commit comments

Comments
 (0)