Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SPEC] Overhaul event system #1779

Open
josxha opened this issue Dec 19, 2023 · 0 comments
Open

[SPEC] Overhaul event system #1779

josxha opened this issue Dec 19, 2023 · 0 comments
Labels
feature This issue requests a new feature P: 2 (soon™?) S: core Scoped to the core flutter_map functionality
Milestone

Comments

@josxha
Copy link
Contributor

josxha commented Dec 19, 2023

Work in progress, feedback and additions are welcome, event names are not final

Motivation

Current state

  • Own event class for every event type
  • EventSource for the origin of the event
  • boolean hasGesture, false if gesture has been caused programmatically by the MapController

Needed additions

Class hierarchy

  • abstract MapEvent
    • MapEventTap, MapEventSecondaryTap, MapEventTertiaryTap, MapEventLongPress, MapEventSecondaryLongPress,
      MapEventTertiaryLongPress
    • MapEventMoveStart, MapEventMoveEnd
    • MapEventFlingAnimationNotStarted, MapEventFlingAnimationStart, MapEventFlingAnimationEnd
    • MapEventDoubleTapZoomStart, MapEventDoubleTapZoomEnd
    • MapEventDoubleTapDragZoomStart, MapEventDoubleTapDragZoomEnd
    • MapEventRotateStart, MapEventRotateEnd
    • abstract MapEventWithMove
      • MapEventMove
      • MapEventFlingAnimation
      • MapEventDoubleTapZoom
      • MapEventScrollWheelZoom
      • MapEventNonRotatedSizeChange

Usage in onMapEvent callback

build() {
  return FlutterMap(
    options: MapOptions(
      onMapEvent: (event) {
        switch (event) {
          case final MapEventDoubleTapZoom event:
            print('double tap zoom');
            break;
          case final MapEventFlingAnimationNotStarted event:
            print('fling animation not started');
            break;
        }
      },
    ),
  );
}

Proposals

Proposal 1: Minimal class approach

Class hierarchy

  • sealed MapEvent
    • MapCameraEvent(enum CameraEventType)
    • MapInteractionEvent(enum InteractionType)
    • MapStartEvent(enum CameraEventType)
    • MapEndEvent(enum CameraEventType)
    • MapEventFlingAnimationNotStarted()

Usage in onMapEvent callback

build() {
  return FlutterMap(
    options: MapOptions(
      onMapEvent: (event) {
        switch (event) {
          case MapCameraEvent():
            switch (event) {
              case CameraEventType.doubleTapZoom:
                print('double tap zoom');
                break;
            }
            break;
          case MapEventFlingAnimationNotStarted():
            print('fling animation not started');
            break;
        }
      },
    ),
  );
}
Proposal 2: Further embrace class subtyping

Class hierarchy

  • sealed MapEvent
    • sealed MapInteractionEvent
      • MapEventTap, MapEventSecondaryTap, MapEventTertiaryTap, MapEventLongPress, MapEventSecondaryLongPress,
        MapEventTertiaryLongPress
    • MapEventFlingAnimationNotStarted
    • sealed MapStartEvent
      • MapMoveEventStart, MapFlingAnimationEventStart, MapDoubleTapZoomEventStart, MapDoubleTapDragZoomEventStart,
        MapEventRotateStart
    • sealed MapEndEvent
      • MapMoveEventEnd, MapEventFlingAnimationEnd, MapDoubleTapZoomEventEnd, MapDoubleTapDragZoomEventEnd,
        MapRotateEventEnd
    • sealed MapCameraEvent
      • MapMoveEvent
      • MapFlingEvent
      • MapDoubleTapZoomEvent
      • MapScrollWheelZoomEvent
      • MapWidgetSizeChangedEvent

Usage in onMapEvent callback

build() {
  return FlutterMap(
    options: MapOptions(
      onMapEvent: (event) {
        switch (event) {
          case MapDoubleTapZoomEvent():
            print('fling animation not started');
            break;
          case MapEventFlingAnimationNotStarted():
            print('fling animation not started');
            break;
          default:
            break;
        }
      },
    ),
  );
}

TODO: add more proposals

Challenges

@josxha josxha added this to the v7.0 milestone Dec 19, 2023
@josxha josxha added the general This issue is not a bug nor feature request, and is better suited for Discussions or Discord label Dec 19, 2023
@JaffaKetchup JaffaKetchup added the S: core Scoped to the core flutter_map functionality label Dec 22, 2023
@JaffaKetchup JaffaKetchup changed the title [SPEC] overhaul event system [SPEC] Overhaul event system Jan 15, 2024
@JaffaKetchup JaffaKetchup added feature This issue requests a new feature P: 2 (soon™?) and removed general This issue is not a bug nor feature request, and is better suited for Discussions or Discord labels Jan 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature This issue requests a new feature P: 2 (soon™?) S: core Scoped to the core flutter_map functionality
Projects
Status: In progress
Development

No branches or pull requests

2 participants