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

Fling animation can be more fluid #271

Closed
aytunch opened this issue Apr 27, 2019 · 19 comments
Closed

Fling animation can be more fluid #271

aytunch opened this issue Apr 27, 2019 · 19 comments

Comments

@aytunch
Copy link
Contributor

aytunch commented Apr 27, 2019

I am not talking about dragging(pan). While dragging, the map is fluid. However while swiping(pan), like a fast flicker of finger, the map moves in an unnatural way. Seems too much acceleration. We can do it like Apple Maps or Google maps swipe gesture. If I am not wrong, this could be solved by altering the swipe gesture. Damping and Curves.

@johnpryan
Copy link
Collaborator

Yep, I think I agree that this is slightly unnatural, at least on iOS. (Android users might feel differently). The fling animation is here: https://github.com/johnpryan/flutter_map/blob/1d048608ab0ab6daf716b3c4b20db7a62cc44536/lib/src/gestures/gestures.dart#L20 and is using the AnimationController.fling() function from the flutter framework.

@johnpryan johnpryan changed the title Swipe gesture for Panning can be more fluid Fling animation can be more fluid May 9, 2019
@aytunch
Copy link
Contributor Author

aytunch commented Jun 8, 2019

@johnpryan @lpongetti There has been some great contributions in the past days to flutter_map by you two. I really think that the Fling gesture is very un natural at the moment. It is as if the animation accelerates instead of decelerating. I use Google maps, Apple maps, yandex maps on iOS and all of them behave the same way when it comes to fling(swipe/throw) gesture animation. But Flutter map behaves differently. Thanks

@lpongetti
Copy link
Contributor

I'll see when i'll have some time

@lpongetti
Copy link
Contributor

I read the code and at first look i think that can be the duration... its never setted. It have to be proportioned by velocity. but i have to try.. monday

@aytunch
Copy link
Contributor Author

aytunch commented Jun 8, 2019

@lpongetti Sounds great, thanks. Now that you pointed out a hint about duration, I looked at the code and it seems the author records the magnitude of the fling gesture and calculates the new center according to it. And then makes a linear tween to that new center. In other gestures like double tap author used Curves.fastOutSlowIn. But I couldn't see something like that for fling animation. Maybe that is what causes the unnatural animation along with no duration. Good luck since it seems too much math:D What I realized after looking at other map apps, Their fling animations decelerate much quicker, and don't go too far away unless it is a very big fling. Ours moves a lot even when a small fling distance is made by the finger

@lpongetti
Copy link
Contributor

Surely the distance and duration are wrong. Fling animation sounds good.. but i dont know... Monday i will look for a solution

@lpongetti
Copy link
Contributor

lpongetti commented Jun 10, 2019

i tried to remove fling animation and i added CurvedAnimation with Curves.decelerate.
i have pixel per seconds and i have to calculate the duration and end offset.
with the right duration and offset the animation will have at the start the same speed of touch.

unfortunately I'm not a mathematician and i don't know how to compute them.

if you want you can try

var magnitude = details.velocity.pixelsPerSecond.distance;
    if (magnitude < _kMinFlingVelocity) {
      return;
    }

    Animation<double> animation =
        CurvedAnimation(parent: _controller, curve: Curves.decelerate);

    _flingAnimation = Tween<Offset>(
      begin: _flingOffset,
      end: _flingOffset - (details.velocity.pixelsPerSecond / xxx),
    ).animate(animation);

    _controller
      ..value = 0.0
      ..duration = Duration(milliseconds: xxx)
      ..forward();

@aytunch
Copy link
Contributor Author

aytunch commented Aug 29, 2019

I just found out about a great library named Flutter-Flick: https://github.com/aliyigitbireroglu/flutter-flick

I believe This package takes away the need of math calculations and results in a natural Fling gesture. Do you guys think we can implement this inside Flutter_Map? @johnpryan @lpongetti @aliyigitbireroglu

@johnpryan
Copy link
Collaborator

I think a simpler solution might be to use AnimationController.animateWith and use a physics simulation: https://github.com/flutter/samples/blob/master/animations/lib/src/misc/physics_card_drag.dart#L70

@aliyigitbireroglu
Copy link

The Flick library has a very simple logic: First, of course, it moves the widget according to the drag gestures. When these gestures end, it calculates the imminent displacement based on the velocity of the DragEndDetails. Then, it creates a CurvedAnimation tween based on the calculated displacement using Curves.decelerate. Finally, it moves the widget with this animation.

I haven't had the chance of looking at the code of Flutter_Map yet but I hope you can implement Flick directly. If not, I would be glad to contribute:) I will see the code as soon as I can.

@RyanRamchandar
Copy link

Any updates on this?

@github-actions
Copy link

This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 5 days.

@github-actions github-actions bot added the Stale label Mar 28, 2021
@github-actions
Copy link

github-actions bot commented Apr 2, 2021

This issue was closed because it has been stalled for 5 days with no activity.

@github-actions github-actions bot closed this as completed Apr 2, 2021
@FloLecoeuche
Copy link

Any updates on this ?

@aytunch
Copy link
Contributor Author

aytunch commented Apr 17, 2021

@FloLecoeuche unfortunately it has been 2 years since I opened this but it has not been addressed yet. Do you know of a way to re-open the issue? The bot closed it automatically.
Google maps and Apple Maps have a much more natural fling/swipe gesture.

@johnpryan johnpryan reopened this Apr 19, 2021
@github-actions github-actions bot removed the Stale label Apr 20, 2021
@joeldsparks
Copy link
Contributor

joeldsparks commented Apr 24, 2021

The initial rapid acceleration appears to be due to the spring physics being critically dampened. I changed the default to be over damped and tweaked it by manually comparing it to google and apple maps and now it's smoother.

    _flingController
      ..value = 0.0
      ..fling(
          velocity: magnitude / 1000.0,
          springDescription: SpringDescription.withDampingRatio(
            mass: 1.0,
            stiffness: 1000.0,
            ratio: 5.0,
          ));

The default values are:

    _flingController
      ..value = 0.0
      ..fling(
          velocity: magnitude / 1000.0,
          springDescription: SpringDescription.withDampingRatio(
            mass: 1.0,
            stiffness: 500.0,
            ratio: 1.0,
          ));

@aytunch
Copy link
Contributor Author

aytunch commented Apr 24, 2021

@joeldsparks These values are better imo. Will you be opening a PR and merging these to main?

@github-actions
Copy link

This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 5 days.

@github-actions github-actions bot added the Stale label May 25, 2021
@github-actions
Copy link

This issue was closed because it has been stalled for 5 days with no activity.

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

7 participants