Skip to content

Instantly share code, notes, and snippets.

@ederchrono
Created May 15, 2019 06:44
Show Gist options
  • Save ederchrono/a6e34dffb8ff1d372f3050dd1477f1db to your computer and use it in GitHub Desktop.
Save ederchrono/a6e34dffb8ff1d372f3050dd1477f1db to your computer and use it in GitHub Desktop.
// inside methods
createReleaseAnimation() {
if(this.swipingLeft) {
if(this.nextImagePosition > HALF_WIDTH) {
// next image should be animated back to be offscreen
this.nextImageAnimatedX = this.nextImagePosition
return {nextImageAnimatedX: DEVICE_WIDTH}
}
// current image "copies" the nextImage position
this.currentImageAnimatedX = this.nextImagePosition
// the nextImage is sent offscreen
this.nextImageAnimatedX = DEVICE_WIDTH
// Change the image index to become the next image in the array
// images src attribute will update accordingly
this.currentImageIndex = this.nextImageIndex
return {currentImageAnimatedX: 0}
}
// swipe right
if(this.currentImagePosition < HALF_WIDTH) {
// current image should be animated back to center position
this.currentImageAnimatedX = this.currentImagePosition
return {currentImageAnimatedX: 0}
}
// the nextImage "copies" the currentImage position
this.nextImageAnimatedX = this.currentImagePosition
// the currentImage gets centered to become the prevImage
this.currentImageAnimatedX = 0
// Change the image index to become the previous image in the array
this.currentImageIndex = this.previousImageIndex
return {nextImageAnimatedX: DEVICE_WIDTH}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment