mapbox / mapbox/mapbox-maps-flutter

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

Open
#1,087 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug
Dominant language
Dart
Stars
380
Forks
204
PR merge metrics
No merged PRs in 30d

Description

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 https://github.com/mapbox/mapbox-maps-flutter/issues/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.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with CircleAnnotationManager.dragEvents and the supplied iOS reproduction, focusing on an update or create call made from onBegin or onChanged. Verify the drag continues to invoke onChanged and onEnd after the annotation is updated, and confirm the reproduced color change still works.

Written by the indexing model from the issue text.

Assessment

Tech stack
dart, flutter
Domain
mobile
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.