react-native-redash
Version:
Utility library for React Native Reanimated
2 lines • 2.75 kB
JavaScript
import Animated from"react-native-reanimated";import{State as GestureState}from"react-native-gesture-handler";import{runDecay,runSpring}from"./AnimationRunners";var Clock=Animated.Clock,Value=Animated.Value,event=Animated.event,add=Animated.add,block=Animated.block,cond=Animated.cond,divide=Animated.divide,eq=Animated.eq,greaterThan=Animated.greaterThan,lessThan=Animated.lessThan,multiply=Animated.multiply,set=Animated.set,stopClock=Animated.stopClock,sub=Animated.sub;export var preserveOffset=function preserveOffset(value,state){var previous=new Value(0);var offset=new Value(0);return block([cond(eq(state,GestureState.BEGAN),[set(previous,0)],[set(offset,add(offset,sub(value,previous))),set(previous,value)]),offset]);};export var decay=function decay(value,state,velocity){var decayedValue=new Value(0);var offset=new Value(0);var clock=new Clock();var rerunDecaying=new Value(0);return block([cond(eq(state,GestureState.END),[set(decayedValue,runDecay(clock,add(value,offset),velocity,rerunDecaying))],[stopClock(clock),cond(eq(state,GestureState.BEGAN),[set(rerunDecaying,0),set(offset,sub(decayedValue,value))]),set(decayedValue,add(value,offset))]),decayedValue]);};export var spring=function spring(translation,state,snapPoint){var defaultOffset=arguments.length>3&&arguments[3]!==undefined?arguments[3]:0;var springedValue=new Value(0);var offset=new Value(defaultOffset);var clock=new Clock();var rerunSpring=new Value(0);var springConfig={toValue:new Value(0),damping:15,mass:1,stiffness:150,overshootClamping:false,restSpeedThreshold:0.001,restDisplacementThreshold:0.001};return block([cond(eq(state,GestureState.END),[set(springedValue,runSpring(clock,add(translation,offset),snapPoint,springConfig))],[stopClock(clock),cond(eq(state,GestureState.BEGAN),[set(rerunSpring,0),set(offset,sub(springedValue,translation))]),set(springedValue,add(translation,offset))]),springedValue]);};export var limit=function limit(value,state,min,max){var offset=new Animated.Value(0);var offsetValue=add(offset,value);return block([cond(eq(state,GestureState.BEGAN),[cond(lessThan(offsetValue,min),set(offset,sub(min,value))),cond(greaterThan(offsetValue,max),set(offset,sub(max,value)))]),cond(lessThan(offsetValue,min),min,cond(greaterThan(offsetValue,max),max,offsetValue))]);};export var preserveMultiplicativeOffset=function preserveMultiplicativeOffset(value,state){var previous=new Animated.Value(1);var offset=new Animated.Value(1);return block([cond(eq(state,GestureState.BEGAN),[set(previous,1)],[set(offset,multiply(offset,divide(value,previous))),set(previous,value)]),offset]);};export var onScroll=function onScroll(contentOffset){return event([{nativeEvent:{contentOffset:contentOffset}}]);};
//# sourceMappingURL=Gesture.js.map