react-native-redash
Version:
Utility library for React Native Reanimated
2 lines • 1.93 kB
JavaScript
import{defineAnimation}from"react-native-reanimated";export var withPause=function withPause(_nextAnimation,paused){"worklet";return defineAnimation(_nextAnimation,function(){"worklet";var nextAnimation=typeof _nextAnimation==="function"?_nextAnimation():_nextAnimation;var onFrame=function onFrame(state,now){var lastTimestamp=state.lastTimestamp,elapsed=state.elapsed;if(paused.value){state.elapsed=now-lastTimestamp;return false;}var dt=now-elapsed;var finished=nextAnimation.onFrame(nextAnimation,dt);state.current=nextAnimation.current;state.lastTimestamp=dt;return finished;};var onStart=function onStart(state,value,now,previousState){state.lastTimestamp=now;state.elapsed=0;state.current=0;nextAnimation.onStart(nextAnimation,value,now,previousState);};var callback=function callback(finished){if(nextAnimation.callback){nextAnimation.callback(finished);}};return{onFrame:onFrame,onStart:onStart,isHigherOrder:true,current:nextAnimation.current,callback:callback,previousAnimation:null,startTime:0,started:false,lastTimestamp:0,elapsed:0};});};export var withBouncing=function withBouncing(_nextAnimation,lowerBound,upperBound){"worklet";return defineAnimation(_nextAnimation,function(){"worklet";var nextAnimation=typeof _nextAnimation==="function"?_nextAnimation():_nextAnimation;var onFrame=function onFrame(state,now){var finished=nextAnimation.onFrame(nextAnimation,now);var velocity=nextAnimation.velocity,current=nextAnimation.current;state.current=current;if(velocity<0&&state.current<=lowerBound||velocity>0&&state.current>=upperBound){state.current=velocity<0?lowerBound:upperBound;nextAnimation.velocity*=-0.5;}return finished;};var onStart=function onStart(_state,value,now,previousState){nextAnimation.onStart(nextAnimation,value,now,previousState);};return{onFrame:onFrame,onStart:onStart,current:nextAnimation.current,callback:nextAnimation.callback,velocity:0};});};
//# sourceMappingURL=Animations.js.map