Coder Social home page Coder Social logo

Comments (7)

wcandillon avatar wcandillon commented on August 25, 2024 2

@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.

from react-native-reanimated.

nstfkc avatar nstfkc commented on August 25, 2024

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.

from react-native-reanimated.

wcandillon avatar wcandillon commented on August 25, 2024

@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? πŸ€”).

from react-native-reanimated.

futuun avatar futuun commented on August 25, 2024

@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.

from react-native-reanimated.

wcandillon avatar wcandillon commented on August 25, 2024

from react-native-reanimated.

JonnyBurger avatar JonnyBurger commented on August 25, 2024

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.

from react-native-reanimated.

hoffmannjan avatar hoffmannjan commented on August 25, 2024

@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?

from react-native-reanimated.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.