Skip to content

Commit 2de7f31

Browse files
committed
do not handle annotation tap if there is no subscription (#1017)
add test case for interaction events cancel
1 parent cfc9666 commit 2de7f31

19 files changed

+938
-606
lines changed

android/src/main/kotlin/com/mapbox/maps/mapbox_maps/annotation/AnnotationController.kt

Lines changed: 36 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -44,13 +44,11 @@ class AnnotationController(
4444
this.addClickListener(
4545
com.mapbox.maps.plugin.annotation.generated.OnCircleAnnotationClickListener { annotation ->
4646
sendTapEvent(id, annotation)
47-
false
4847
}
4948
)
5049
this.addLongClickListener(
5150
OnCircleAnnotationLongClickListener { annotation ->
5251
sendLongPressEvent(id, annotation)
53-
false
5452
}
5553
)
5654
this.addDragListener(object :
@@ -74,13 +72,11 @@ class AnnotationController(
7472
this.addClickListener(
7573
com.mapbox.maps.plugin.annotation.generated.OnPointAnnotationClickListener { annotation ->
7674
sendTapEvent(id, annotation)
77-
false
7875
}
7976
)
8077
this.addLongClickListener(
8178
OnPointAnnotationLongClickListener { annotation ->
8279
sendLongPressEvent(id, annotation)
83-
false
8480
}
8581
)
8682
this.addDragListener(object :
@@ -104,13 +100,11 @@ class AnnotationController(
104100
this.addClickListener(
105101
com.mapbox.maps.plugin.annotation.generated.OnPolygonAnnotationClickListener { annotation ->
106102
sendTapEvent(id, annotation)
107-
false
108103
}
109104
)
110105
this.addLongClickListener(
111106
OnPolygonAnnotationLongClickListener { annotation ->
112107
sendLongPressEvent(id, annotation)
113-
false
114108
}
115109
)
116110
this.addDragListener(object :
@@ -134,13 +128,11 @@ class AnnotationController(
134128
this.addClickListener(
135129
com.mapbox.maps.plugin.annotation.generated.OnPolylineAnnotationClickListener { annotation ->
136130
sendTapEvent(id, annotation)
137-
false
138131
}
139132
)
140133
this.addLongClickListener(
141134
OnPolylineAnnotationLongClickListener { annotation ->
142135
sendLongPressEvent(id, annotation)
143-
false
144136
}
145137
)
146138
this.addDragListener(object :
@@ -221,36 +213,47 @@ class AnnotationController(
221213
streamSinkMap[managerId]?.dragEventsSink?.success(context)
222214
}
223215

224-
fun sendTapEvent(managerId: String, annotation: Annotation<*>) {
225-
val context: AnnotationInteractionContext = when (annotation) {
226-
is com.mapbox.maps.plugin.annotation.generated.PointAnnotation ->
227-
PointAnnotationInteractionContext(annotation.toFLTPointAnnotation(), GestureState.ENDED)
228-
is CircleAnnotation ->
229-
CircleAnnotationInteractionContext(annotation.toFLTCircleAnnotation(), GestureState.ENDED)
230-
is PolygonAnnotation ->
231-
PolygonAnnotationInteractionContext(annotation.toFLTPolygonAnnotation(), GestureState.ENDED)
232-
is PolylineAnnotation ->
233-
PolylineAnnotationInteractionContext(annotation.toFLTPolylineAnnotation(), GestureState.ENDED)
216+
fun sendTapEvent(managerId: String, annotation: Annotation<*>): Boolean {
234217

235-
else -> throw IllegalArgumentException("$annotation is unsupported")
218+
val sink = streamSinkMap[managerId]?.tapEventsSink
219+
return if (sink != null) {
220+
val context: AnnotationInteractionContext = when (annotation) {
221+
is com.mapbox.maps.plugin.annotation.generated.PointAnnotation ->
222+
PointAnnotationInteractionContext(annotation.toFLTPointAnnotation(), GestureState.ENDED)
223+
is CircleAnnotation ->
224+
CircleAnnotationInteractionContext(annotation.toFLTCircleAnnotation(), GestureState.ENDED)
225+
is PolygonAnnotation ->
226+
PolygonAnnotationInteractionContext(annotation.toFLTPolygonAnnotation(), GestureState.ENDED)
227+
is PolylineAnnotation ->
228+
PolylineAnnotationInteractionContext(annotation.toFLTPolylineAnnotation(), GestureState.ENDED)
229+
else -> throw IllegalArgumentException("$annotation is unsupported")
230+
}
231+
sink.success(context)
232+
true
233+
} else {
234+
false
236235
}
237-
streamSinkMap[managerId]?.tapEventsSink?.success(context)
238236
}
239237

240-
fun sendLongPressEvent(managerId: String, annotation: Annotation<*>) {
241-
val context: AnnotationInteractionContext = when (annotation) {
242-
is com.mapbox.maps.plugin.annotation.generated.PointAnnotation ->
243-
PointAnnotationInteractionContext(annotation.toFLTPointAnnotation(), GestureState.ENDED)
244-
is CircleAnnotation ->
245-
CircleAnnotationInteractionContext(annotation.toFLTCircleAnnotation(), GestureState.ENDED)
246-
is PolygonAnnotation ->
247-
PolygonAnnotationInteractionContext(annotation.toFLTPolygonAnnotation(), GestureState.ENDED)
248-
is PolylineAnnotation ->
249-
PolylineAnnotationInteractionContext(annotation.toFLTPolylineAnnotation(), GestureState.ENDED)
250-
251-
else -> throw IllegalArgumentException("$annotation is unsupported")
238+
fun sendLongPressEvent(managerId: String, annotation: Annotation<*>): Boolean {
239+
val sink = streamSinkMap[managerId]?.longPressEventsSink
240+
return if (sink != null) {
241+
val context: AnnotationInteractionContext = when (annotation) {
242+
is com.mapbox.maps.plugin.annotation.generated.PointAnnotation ->
243+
PointAnnotationInteractionContext(annotation.toFLTPointAnnotation(), GestureState.ENDED)
244+
is CircleAnnotation ->
245+
CircleAnnotationInteractionContext(annotation.toFLTCircleAnnotation(), GestureState.ENDED)
246+
is PolygonAnnotation ->
247+
PolygonAnnotationInteractionContext(annotation.toFLTPolygonAnnotation(), GestureState.ENDED)
248+
is PolylineAnnotation ->
249+
PolylineAnnotationInteractionContext(annotation.toFLTPolylineAnnotation(), GestureState.ENDED)
250+
else -> throw IllegalArgumentException("$annotation is unsupported")
251+
}
252+
sink.success(context)
253+
true
254+
} else {
255+
false
252256
}
253-
streamSinkMap[managerId]?.longPressEventsSink?.success(context)
254257
}
255258

256259
override fun getManager(managerId: String): AnnotationManager<*, *, *, *, *, *, *> {

0 commit comments

Comments
 (0)