Preview swipe action

This commit is contained in:
Tusooa Zhu 2021-08-01 19:46:27 -04:00
parent f96e5882d1
commit a7570f5eb2
No known key found for this signature in database
GPG key ID: 7B467EDE43A08224
4 changed files with 136 additions and 24 deletions

View file

@ -4,6 +4,7 @@ import Modal from '../modal/modal.vue'
import fileTypeService from '../../services/file_type/file_type.service.js'
import GestureService from '../../services/gesture_service/gesture_service'
import Flash from 'src/components/flash/flash.vue'
import Vuex from 'vuex'
import { library } from '@fortawesome/fontawesome-svg-core'
import {
faChevronLeft,
@ -17,6 +18,8 @@ library.add(
faCircleNotch
)
const onlyXAxis = ([x, y]) => [x, 0]
const MediaModal = {
components: {
StillImage,
@ -50,6 +53,15 @@ const MediaModal = {
},
type () {
return this.currentMedia ? this.getType(this.currentMedia) : null
},
scaling () {
return this.$store.state.mediaViewer.swipeScaler.scaling
},
offsets () {
return this.$store.state.mediaViewer.swipeScaler.offsets
},
transform () {
return `scale(${this.scaling}, ${this.scaling}) translate(${this.offsets[0]}px, ${this.offsets[1]}px)`
}
},
created () {
@ -57,6 +69,8 @@ const MediaModal = {
direction: GestureService.DIRECTION_LEFT,
callbackPositive: this.goNext,
callbackNegative: this.goPrev,
swipePreviewCallback: this.handleSwipePreview,
swipeEndCallback: this.handleSwipeEnd,
threshold: 50
})
},
@ -99,6 +113,18 @@ const MediaModal = {
onImageLoaded () {
this.loading = false
},
handleSwipePreview (offsets) {
this.$store.dispatch('swipeScaler/apply', { offsets: onlyXAxis(offsets) })
},
handleSwipeEnd (sign) {
if (sign === 0) {
this.$store.dispatch('swipeScaler/revert')
} else if (sign > 0) {
this.goNext()
} else {
this.goPrev()
}
},
handleKeyupEvent (e) {
if (this.showing && e.keyCode === 27) { // escape
this.hide()

View file

@ -11,6 +11,7 @@
:src="currentMedia.url"
:alt="currentMedia.description"
:title="currentMedia.description"
:style="{ transform }"
@touchstart.stop="mediaTouchStart"
@touchmove.stop="mediaTouchMove"
@touchend.stop="mediaTouchEnd"