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

No onRegionIsChanging callback when flinging position #2141

Closed
westnordost opened this issue Jan 31, 2020 · 5 comments
Closed

No onRegionIsChanging callback when flinging position #2141

westnordost opened this issue Jan 31, 2020 · 5 comments
Assignees

Comments

@westnordost
Copy link
Contributor

If one flings the map via the default fling gesture, no onRegionIsChanging is called on the MapChangeListener while the view is being animated to the new position.

Seen in tangram 0.12.
Related to #2129

@westnordost
Copy link
Contributor Author

westnordost commented Feb 1, 2020

This is why is stumbled across this, I am implementing this:

https://youtu.be/ss_-qWN4E4Y

Obviously, when one flings the position, the pointer pin should update too.

@westnordost
Copy link
Contributor Author

Can I help here? Is this fixable on the Java-side? I'd love to be able to release the feature I mentioned but with no callback on flinging it's not good.

@matteblair
Copy link
Member

Thanks for the offer to help ❤️ but unfortunately I don't think that this can be fixed on just the Java side. Movement after a fling gesture is handled in the C++ core and it currently doesn't invoke callbacks the way that it does for scripted camera animations. I do at least have an idea for how to fix this now: the movement of the camera after a fling can be calculated as a closed-form function, which means it could be implemented as a camera animation and treated mostly the same as 'updateCamera' and 'flyTo' animations. There are some subtleties to the exact series of events that should be emitted: for example if a fling is considered a camera animation should we call onRegionWillChange(animated) or is it a continuation of the preceding pan gesture?

I hope to get some time for this later in the week, or this upcoming weekend.

@matteblair
Copy link
Member

Ok it took me a while to re-acquaint myself with this code, thanks for your patience.

The events sent to the listener are a little different from what you expected but should still enable you to implement your feature. When a user moves the map with a gesture that ends with a fling, the callbacks look like:

OnRegionWillChange:animated=false    < Very beginning of the gesture (finger down)
OnRegionIsChanging                   < Repeats while the gesture is in progress (finger remains down)
...
OnRegionIsChanging
OnRegionDidChange:animated=false     < End of gesture (finger comes up)
OnRegionWillChange:animated=true     < Start of fling animation
OnRegionDidChange:animated=true      < End of fling animation

So the fling animation is treated a little separately from the gesture itself, but you still receive events for it. When you get a OnRegionWillChange your app can assume that the map will be moving in some way until you get a corresponding OnRegionDidChange. I should definitely add some more detailed documentation for this in MapChangeListener, both for other users and for myself 😅

This is a little different from the way callbacks work in the Google Maps API. It basically mimics the behavior of the equivalent callbacks in MapKit (https://developer.apple.com/documentation/mapkit/mkmapviewdelegate#topics). It was easier for us at the time to pick one callback pattern to implement, but it may be nicer for Android developers to stick closer to the "native" API patterns.

@westnordost
Copy link
Contributor Author

Ah I understand, yes that'd work. Thank you for the documentation update!

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

2 participants