Skip to content

CircleAnnotationManager's change inside dragEvents(onBegin: ) terminates drag action silently in iOS #1087

@IkueWatanabe-Aidea

Description

@IkueWatanabe-Aidea

When calling CircleAnnotationManager.create() or CircleAnnotationManager.update() inside dragEnvets' onBegin or onChanged event handler, the following onChanged and onEnd events are never triggered.
This issue is similar to #1026 but the problem occurs inside the event handler.

Environment:

Flutter version: 3.32.0
mapbox_maps_flutter version: 2.17.0
Platform: iOS

Steps to Reproduce:

  1. Create a CircleAnnotationManager
  2. Set dragEvents on the CircleAnnotationManager. Inside onBegin event handler, update CircleAnnotation using the manager.
  3. Create a CircleAnnotation using the CircleAnnotationManager
  4. Long press the CircleAnnotation and start drag
  5. The CircleAnnotation never moves
final _dragAnnotationManager = await _mapboxMap.annotations.createCircleAnnotationManager();

// register drag event
_dragAnnotationManager.dragEvents(
      onBegin: (annotation) async {
        // Change the color when the drag starts
       annotation.circleColor = Colors.red.toARGB32();
       _dragAnnotationManager.update(annotation);
      },
      onChanged: (annotation) {
        // This code is never called
        print('onChanged');
      },
      onEnd: (annotation) async {
        // This code is never called either
        print('onEnd');
        // Change back the color
       annotation.circleColor = Colors.black.toARGB32();
       _dragAnnotationManager.update(annotation);
      },
    );

// create annotation to drag
_dragAnnotationManager.create(
        CircleAnnotationOptions(
          geometry: Point(
            coordinates: Position(coordinate.lng, coordinate.lat),
          ),
          circleRadius: 8.0,
          circleColor: Colors.black.toARGB32(),
          isDraggable: true,
        ),
      );

Additional context:
I'd like to change the annotation appearance once drag starts. However, updating the annotation inside onBegin clause is not allowed currently.
The only workaround I could take was to

  1. Create another CircleAnnotationManager
  2. In side onBegin clause, create another CircleAnnotation to overlay with the desired color
  3. Update overlay CircleAnnotation's geometry inside onChanged clause

However, the above solution doesn't work perfectly because the overlay annotation can delay when the dragging annotation moves fast.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions