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

Spring animations are "slow" to end #132

Closed
wcandillon opened this issue Nov 19, 2018 · 7 comments
Closed

Spring animations are "slow" to end #132

wcandillon opened this issue Nov 19, 2018 · 7 comments

Comments

@wcandillon
Copy link
Contributor

Thank you so much for making this great module. I started to build some video tutorial on how to use it:

I've built a couple of animations using the runSpring function that we can find in the examples of the repo. You can find one here: https://snack.expo.io/@git/github.com/wcandillon/can-it-be-done-in-react-native:tinder-swiping (components/Profiles.js).
I have a condition on when the clock is stopped by the spring animation, this condition always evalutes much later (few seconds) after the animation is seemingly done. Is that a behavior that sound famillar or I would need to provide a smaller example?

@nstfkc
Copy link

nstfkc commented Nov 19, 2018

Hey @wcandillon, idk its the convenient way but maybe you can try to put a condition which checks the clock value is lessThan something then you can call the function? Thanks a lot for those great videos btw.

@wcandillon
Copy link
Contributor Author

@enestufekci Does that mean that even though we don't see the object animate anymore, it still does? (but so slightly that we cannot see it? 🤔).

@futuun
Copy link

futuun commented Nov 20, 2018

@enestufekci Does that mean that even though we don't see the object animate anymore, it still does? (but so slightly that we cannot see it? 🤔).

Yes, and that’s quite common thing with spring based animations.
There are two properties (restSpeedThreshold & restDisplacementThreshold) that allow you to define when your spring should be considered at rest.
Check this for description of those two.

@wcandillon
Copy link
Contributor Author

wcandillon commented Nov 20, 2018 via email

@JonnyBurger
Copy link
Contributor

I found that because of this behavior, if you have many interactions and the users does them in rapid succession, it can cause some flickery / unwanted behavior.

For example if you have a modal-like functionality and use springs to make the animation to open / close the modal, and you trigger the close action before the open animation has finished, there can be some weird bugs.

I have tweaked my runSpring function that fixes the issues, although I might not fully understand why it's working.

function runSpring(clock, value, dest, otherClocks) {
	const state = {
		finished: new Value(0),
		position: new Value(0),
		time: new Value(0),
		velocity: new Value(0)
	};

	const config = {
		damping: 800,
		mass: 0.5,
		stiffness: 200,
		overshootClamping: true,
		restSpeedThreshold: 0.01,
		restDisplacementThreshold: 0.01,
		toValue: new Value(0)
	};

	return block([
		cond(
			or(...otherClocks.map(c => clockRunning(c))),
			otherClocks.map(c => stopClock(c))
		),
		cond(clockRunning(clock), 0, [
			set(state.finished, 0),
			set(state.time, 0),
			set(state.position, value),
			set(config.toValue, dest),
			startClock(clock)
		]),
		spring(clock, state, config),
		set(value, state.position),
		cond(state.finished, [
			stopClock(clock),
			set(state.finished, 0),
			set(value, dest)
		])
	]);
}

What it does differently is

(1) as soon as the spring is considered at rest, set the value to the destination value (so from 0 -> 1, as soon as it reaches 0.999 and is considered resting, it changes to 1)

(2) it allows to pass an array of clocks that should be stopped before the animation is started. you can use it like this:

const clock1 = new Clock()
const clock2 = new Clock()

runSpring(clock1, value, dest, [clock2])

This ensures that only 1 spring animation is run at the time which solves the above mentioned flickering problem for me.

@wcandillon
Copy link
Contributor Author

wcandillon commented Dec 15, 2018

@JonnyBurger Thank for sharing this solution. I will likely try it.

I noticed the exact same "issue" and fixed it outside the spring function. You can find an example at https://github.com/wcandillon/can-it-be-done-in-react-native/blob/master/tinder-swiping/components/Profiles.js.

I'm glad that we can share/improve these use cases together.

@hoffmannjan
Copy link

@JonnyBurger Thank for sharing this solution. I will likely try it.

I noticed the exact same "issue" and fixed it outside the spring function. You can find an example at https://github.com/wcandillon/can-it-be-done-in-react-native/blob/master/tinder-swiping/components/Profiles.js.

I'm glad that we can share/improve these use cases together.

Could you share which line fixes this issue?

tjzel added a commit that referenced this issue Mar 28, 2023
## Summary

Fixes
[#132](https://github.com/release-it/release-it/blob/main/docs/dry-runs.md)
from Dependabot

## Test plan

It wasn't used anyway.
fluiddot pushed a commit to wordpress-mobile/react-native-reanimated that referenced this issue Jun 5, 2023
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

5 participants