Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
_onHandlerStateChange = ({ nativeEvent: event }) => {
// console.log("event", event);
switch (event.state) {
case State.BEGAN:
this._slowDownAnimation && this._slowDownAnimation.stop();
this._slowDownAnimation = null;
this._transformY.extractOffset();
break;
case State.CANCELLED:
case State.FAILED:
case State.END:
this._transformY.flattenOffset();
this._slowDownAnimation = Animated.sequence([
Animated.decay(this._transformY, {
velocity: event.velocityY / 1000,
deceleration: 0.95,
useNativeDriver: true
}),
Animated.timing(this._transformY, {
toValue: 0,
duration: 300,
easing: Easing.sin,
useNativeDriver: true
})
]);
this._slowDownAnimation.start();
onPanHandlerStateChange = ({nativeEvent}) => {
switch (nativeEvent.state) {
case GestureState.UNDETERMINED:
console.log('PAN undetermined', nativeEvent.state); // eslint-disable-line no-console
break;
case GestureState.FAILED:
console.log('PAN failed', nativeEvent.state); // eslint-disable-line no-console
break;
case GestureState.BEGAN:
console.log('PAN began', nativeEvent.state); // eslint-disable-line no-console
break;
case GestureState.CANCELLED:
console.log('PAN cancelled', nativeEvent.state); // eslint-disable-line no-console
break;
case GestureState.ACTIVE:
console.log('PAN active', nativeEvent.state); // eslint-disable-line no-console
break;
case GestureState.END:
console.log('PAN end', nativeEvent.state); // eslint-disable-line no-console
break;
}
};
})
}
return
}
// Released
if (e.nativeEvent.state === State.END) {
if (recordingState === RecordingState.RECORDING) {
setRecordingState(RecordingState.COMPLETE)
}
return
}
if (e.nativeEvent.state === State.CANCELLED || e.nativeEvent.state === State.FAILED) {
setRecordingState(RecordingState.PENDING_CANCEL)
return
}
},
[
duration: duration,
toValue: new Value(0),
easing: Easing.linear
};
return block([
cond(and(eq(gestureState, State.BEGAN), neq(config.toValue, 1)), [
set(state.finished, 0),
set(state.time, 0),
set(state.frameTime, 0),
set(config.toValue, 1),
startClock(clock)
]),
cond(
and(
or(eq(gestureState, State.END), eq(gestureState, State.FAILED)),
neq(config.toValue, 0)
),
[
set(state.finished, 0),
set(state.time, 0),
set(state.frameTime, 0),
set(config.toValue, 0),
startClock(clock)
]
),
timing(clock, state, config),
// cond(eq(state.finished, 1), stopClock(clock)),
interpolate(state.position, {
inputRange: [0, 1],
outputRange: [1, 1.3]
})
parseState = ({ nativeEvent: { state, oldState } }) => {
this.setState({
state: Object.keys(State).find(key => State[key] === state),
});
if (oldState === State.ACTIVE) {
Alert.alert('Yay!');
clearTimeout(this.timeout);
this.timeout = false;
}
if (state === State.FAILED || state === State.CANCELLED) {
this.setState({ level: 0 });
clearTimeout(this.timeout);
this.timeout = false;
}
};
_onHandlerStateChange = ({ nativeEvent: event }) => {
switch (event.state) {
case State.BEGAN:
this._onTouchBegin();
break;
case State.CANCELLED:
break;
case State.FAILED:
case State.END:
this._onTouchEnd(event.translationY, event.velocityY / 1000);
}
};
static isGestureStartedInsideCircle(
gestureState: Animated.Node,
startX: Animated.Node,
startY: Animated.Node,
thumbSize: number,
side: number
) {
const halfThumbSize = thumbSize / 2
const center = HueSaturationWheel.center(side, thumbSize)
const radius = center
return (
and(
neq(gestureState, GestureState.UNDETERMINED),
neq(gestureState, GestureState.FAILED),
lessOrEq(
sqrt(
add(
pow(sub(startX, center + halfThumbSize), 2),
pow(sub(startY, center + halfThumbSize), 2)
)
),
radius + thumbSize / 1.5
)
)
)
}
nativeEvent: ({ state }) => block([
cond(and(
neq(state, this.panGestureState),
not(this.disabled),
), [
set(this.panGestureState, state),
cond(or(
eq(state, GestureState.END),
eq(state, GestureState.CANCELLED),
eq(state, GestureState.FAILED),
), this.onGestureRelease),
]
),
])
}
state: state =>
cond(
or(eq(state, State.BEGAN), eq(state, State.END)),
set(this.gestureState, state),
delay(
cond(
or(
neq(state, State.FAILED),
neq(this.panGestureState, State.ACTIVE)
),
set(this.gestureState, state)
),
100
)
),
x: x =>
function gestureStateFromEnum(s) {
switch (s) {
case State.UNDETERMINED:
return 'UNDETERMINED';
case State.BEGAN:
return 'BEGAN';
case State.FAILED:
return 'FAILED';
case State.CANCELLED:
return 'CANCELLED';
case State.ACTIVE:
return 'ACTIVE';
case State.END:
return 'END';
default:
return `Invalid gesture state: ${s}`;
}
}