Skip to content

Instantly share code, notes, and snippets.

@likern
Created March 22, 2020 14:40
Show Gist options
  • Save likern/7d37661b6cb2bec873c8b37e485c7271 to your computer and use it in GitHub Desktop.
Save likern/7d37661b6cb2bec873c8b37e485c7271 to your computer and use it in GitHub Desktop.
Animation not working
const animateTranslation = (
clock: Animated.Clock,
position: Animated.Value<number>,
translation: Animated.Value<number>,
velocity: Animated.Value<number>,
offset: Animated.Value<number>,
min: Animated.Value<number>,
max: Animated.Value<number>,
gestureState: Animated.Value<State>
) => {
const state = {
finished: new Value(0),
frameTime: new Value(0),
time: new Value(0),
position: new Value(0)
};
const config = {
toValue: new Value(600),
duration: new Value(2000),
easing: Easing.linear
};
// const position = diffClamp(
// calculateOffset(translationY, offset, state),
// min,
// max
// );
// const position = new Value(0);
const snapPoint = new Value(0);
// cond(
// eq(gestureState, State.END),
// [set(offset, add(offset, value))],
// [debug('offset is', add(offset, value)), add(offset, value)]
// );
// const config = {
// damping: new Value(10),
// mass: new Value(1),
// stiffness: new Value(100),
// overshootClamping: new Value(1),
// restSpeedThreshold: new Value(0.001),
// restDisplacementThreshold: new Value(0.001),
// toValue: new Value(0)
// };
// const minDif = abs(sub(position, min));
// const maxDif = abs(sub(position, max));
// const test = cond(not(clockRunning(clock)), []);
// const myclock = new Clock();
// return cond(clockRunning(myclock), snapPoint, snapPoint);
return block([
cond(eq(gestureState, State.BEGAN), [
// cond(clockRunning(clock), stopClock(clock))
]),
cond(eq(gestureState, State.ACTIVE), [
// cond(clockRunning(clock), stopClock(clock)),
set(position, diffClamp(add(offset, translation), min, max)),
set(
snapPoint,
cond(
lessOrEq(abs(sub(position, min)), abs(sub(position, max))),
min,
max
)
),
debug('[active] position is', position)
// set(state.position, position),
// set(config.toValue, snapPoint)
]),
cond(or(eq(gestureState, State.END), eq(gestureState, State.CANCELLED)), [
set(offset, add(offset, translation)),
// debug('released task, gesture is ', gestureState),
// debug('[end] position is', position),
debug('[end] snap point is', snapPoint),
cond(
not(clockRunning(clock)),
[debug('clock is not running', clock), startClock(clock)],
debug('clock running', clock)
)
// debug('gesture end or cancelled: ', gestureState),
// set(config.toValue, snapPoint),
// set(state.position, position),
// debug('[end] state.position is', state.position),
// debug('[end] to value is ', config.toValue),
// debug('before is clock running? ', clockRunning(clock)),
// cond(not(clockRunning(clock)), [startClock(clock)])
// debug('after is clock running? ', clockRunning(clock))
// set(position, state.position),
// cond(or(eq(state.finished, 1), eq(state.position, config.toValue)), [
// stopClock(clock)
// // set(offset, add(offset, value))
// ]),
]),
// debug('clock before timing? ', clockRunning(clock)),
// debug('state.position', state.position),
// set(state.position, position),
// timing(clock, state, config),
// set(position, state.position),
// set(position, state.position),
// debug('state.position is', state.position),
// debug('to value is ', config.toValue),
// set(position, state.position),
// cond(eq(state.finished, 1), [
// stopClock(clock),
// set(state.frameTime, 0),
// set(state.time, 0),
// set(state.finished, 0)
// ]),
// debug('gesture state', gestureState),
// debug('position', position),
// debug('veloctity', velocity),
// debug('is clock running?', clock),
position
// cond(not(eq(gestureState, State.END)), [
// set(position, diffClamp(add(offset, translation), min, max)),
// set(
// snapPoint,
// cond(
// lessOrEq(abs(sub(position, min)), abs(sub(position, max))),
// min,
// max
// )
// )
// ])
// [position]
// cond(and(not(eq(gestureState, State.END)), eq(clockRunning(clock), 0)) , [add(offset, translation)], []),
// cond(and(eq(gestureState, State.BEGAN), eq(clockRunning(clock), 1)), [
// stopClock(clock)
// ]),
// // set(state.position, position),
// // cond(eq(gestureState, State.BEGAN), [set(state.position, position)]),
// cond(and(eq(gestureState, State.END), not(clockRunning(clock))), [
// cond(
// lessOrEq(minDif, maxDif),
// [set(config.toValue, min)],
// [set(config.toValue, max)]
// ),
// debug('set toValue to ', config.toValue),
// // set(position, state.position),
// startClock(clock)
// ]),
// timing(clock, state, config),
// // set(position, state.position),
// // cond(or(eq(state.finished, 1), eq(state.position, config.toValue)), [
// // stopClock(clock)
// // // set(offset, add(offset, value))
// // ]),
// cond(eq(state.finished, 1), [
// stopClock(clock),
// set(state.time, 0),
// set(state.frameTime, 0),
// set(state.finished, 0)
// ]),
// debug('state:', gestureState),
// debug('minDif: ', minDif),
// debug('maxDif: ', maxDif),
// debug('position:', position),
// debug('to value: ', config.toValue),
// debug('position: ', position),
// debug('[timing] position: ', state.position),
// debug('[timing] to value: ', config.toValue),
// debug('[timing] finished: ', state.finished),
// position
// cond(eq(clockRunning(clock), 1), [state.position], [position])
]);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment