Skip to content

Instantly share code, notes, and snippets.

@likern
Created March 21, 2020 09:30
Show Gist options
  • Save likern/b3084df0c79822e29c996fe01675ae4f to your computer and use it in GitHub Desktop.
Save likern/b3084df0c79822e29c996fe01675ae4f to your computer and use it in GitHub Desktop.
Animation which never finishes
const { state, offsetY, translationY, velocityY } = useMemoOne(
() => ({
state: new Value(State.UNDETERMINED),
offsetY: new Value<number>(0),
translationY: new Value<number>(0),
velocityY: new Value<number>(0)
}),
[]
);
const gestureHandler = onGestureEvent({
state,
translationY,
velocityY
});
useCode(() => {
return set(taskPanelAnimation.endPosition, showChartWithOptions ? 0 : 256);
}, [showChartWithOptions, taskPanelAnimation]);
useCode(() => {
const clock = new Clock();
const animationState = {
finished: new Value(0),
position: new Value(0),
velocity: new Value(0),
time: new Value(0)
};
const config = {
damping: new Value(10),
mass: new Value(1),
stiffness: new Value(100),
overshootClamping: new Value(0),
restSpeedThreshold: new Value(0.001),
restDisplacementThreshold: new Value(0.001),
toValue: new Value(256)
};
return block([
// startClock(clock),
// spring(clock, animationState, config),
cond(
and(eq(state, State.END), not(clockRunning(clock))),
[startClock(clock), spring(clock, animationState, config)]
// [set(state.position, startPosition)]
),
// cond(or(eq(state.finished, 1), eq(state.position, config.toValue)), [
// stopClock(clock)
// // set(offset, add(offset, value))
// ]),
cond(eq(animationState.finished, 1), [
stopClock(clock)
// set(offset, add(offset, value))
]),
// debug('clock: ', clock),
debug('is clock running: ', clockRunning(clock)),
// debug('start position: ', startPosition),
// debug('end position: ', endPosition),
// debug('gesture state: ', state),
debug('[spring] finished: ', animationState.finished),
debug('[spring] position: ', animationState.position),
set(translationY, animationState.position)
// cond(eq(clockRunning(clock), 1), [state.position], [startPosition])
// state.position
]);
}, [state]);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment