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

Enhance Viewport State Transition to Idle for Various Camera Interactions #2520

Open
Copatych opened this issue Nov 19, 2024 · 0 comments
Open

Comments

@Copatych
Copy link

We are using FollowPuckViewportState with bearing(FollowPuckViewportStateBearing.SyncWithLocationPuck). However, this viewport state should switch to Idle when the user interacts with the map, presses the compass, or interacts with application functionality that changes the camera position.

In ViewportPluginImpl, there is the following code:

private val cameraAnimationsLifecycleListener = object : CameraAnimationsLifecycleListener {
    override fun onAnimatorStarting(
      type: CameraAnimatorType,
      animator: ValueAnimator,
      owner: String?
    ) {
      when (owner) {
        VIEWPORT_CAMERA_OWNER -> Unit
        MapAnimationOwnerRegistry.GESTURES -> {
          if (options.transitionsToIdleUponUserInteraction) {
            currentCancelable?.cancel()
            currentCancelable = null
            updateStatus(
              ViewportStatus.Idle,
              ViewportStatusChangeReason.USER_INTERACTION
            )
          }
        }
      }
    }

This code allows switching to the Idle state when moving the camera with gestures. However, besides gestures, there are also actions like pressing the compass to rotate the camera or programmatic camera changes using methods like flyTo. We would like these camera changes to also trigger the transition to the Idle state.

Currently, we've implemented the desired behavior as follows:


camera.addCameraAnimationsLifecycleListener(object : CameraAnimationsLifecycleListener {
    override fun onAnimatorCancelling(type: CameraAnimatorType, animator: ValueAnimator, owner: String?) = Unit

    override fun onAnimatorEnding(type: CameraAnimatorType, animator: ValueAnimator, owner: String?) = Unit

    override fun onAnimatorInterrupting(
        type: CameraAnimatorType,
        runningAnimator: ValueAnimator,
        runningAnimatorOwner: String?,
        newAnimator: ValueAnimator,
        newAnimatorOwner: String?
    ) = Unit
    override fun onAnimatorStarting(type: CameraAnimatorType, animator: ValueAnimator, owner: String?) {
        if (owner != "VIEWPORT_CAMERA_OWNER")
            viewport.idle()
    }
})

In this implementation, we use the hardcoded constant "VIEWPORT_CAMERA_OWNER". To start, it would be helpful to at least have access to this constant:
const val VIEWPORT_CAMERA_OWNER = "VIEWPORT_CAMERA_OWNER"
Currently, it is declared as internal in the Mapbox code.

Ideally, we would like to have an API that allows configuring which actions should cause the state to switch to Idle.

Could you also clarify if the current code:

if (owner != "VIEWPORT_CAMERA_OWNER")
    viewport.idle()

could lead to any errors?

The exact same issue exists on iOS as well, where this constant is also inaccessible, and there is no API for configuring which camera actions should switch the viewport to the Idle state.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant