Open sebqq opened 5 years ago
Have you try diffClamp
when the gesture is active and no clamp at all when the gesture is not active (so the spring will be natural).
state.setValue(State.BEGAN);
I strongly recommend not updating these manually. Sometimes it can solves a particular problem but then it might cause issues later down the road. Try to create a new animation value that you can update so you don't need to update the state animation value.
I have the same problem when clamp work pretty well but has some issues. I will let you know as soon as I found a good solution for this problem.
I was just trying to implement your suggestion without any success 😸bad for my that I have no experience with Java/Objective C.
It looks to me like clamp is waiting for animation to complete its "path" behind min/max boundaries to be able to get new values and during this time animted object is stucked at defined min/max.
Thanks for following up on this issue!
I noticed that setting the clamp on the translationY work pretty well: https://github.com/wcandillon/can-it-be-done-in-react-native/pull/63/files#diff-2a38087cb2be36de78068efd49fd3136R69
This has two tiny issues:
Result within my Switch Component:
const translateX = withSpring({
value: clamp(
translationX,
snapPoints[0],
snapPoints[snapPoints.length - 1]
),
velocity: velocityX,
state,
config: {
damping: 15,
mass: 1,
stiffness: 150,
overshootClamping: false,
restSpeedThreshold: 0.1,
restDisplacementThreshold: 0.1
},
snapPoints: snapPoints
});
Doesn't animation look exactly same as if there wasn't any clamp at all? I mean I've tried both,, without clamp and with clamp on withSpirng's value and it looks same to me 😺
Hello! I have two questions:
I've encountered one problem with using clamp() method in spring-based animation. Enclosing a gif:
It seems like Animated object is always stucked while reaching min/max boundary which makes animation not so smooth. Is there anything I can do with it please? It seems like the more velocity i provide while gesture the longer stuck duration is.
Second question is more specific. I have this switch component which can be seen on gif preview above. Besides swipe gesture I would like to also achieve to start spring(?) animation whenever one of the options is pressed. I've found that there is nothing like
snapTo
callback within withSpring() function. Do I need to implement custom timing based animation next to spring animation?In case it would be helpfull I'm enclosing my current spring animation setup:
For onPress behaviour I've implemented something like this:
Thank you so much!