aboutsummaryrefslogtreecommitdiff
path: root/src/components
diff options
context:
space:
mode:
authorTusooa Zhu <tusooa@kazv.moe>2021-08-01 19:46:27 -0400
committerTusooa Zhu <tusooa@kazv.moe>2022-03-13 11:56:34 -0400
commita7570f5eb2b8bc576edbcc8e212b2c873ac99e7e (patch)
treec26d7ba9d1243cf00d977415910cbfe25a3c3b25 /src/components
parentf96e5882d16a8662ceb7b8cc6aa36fe131a2682f (diff)
Preview swipe action
Diffstat (limited to 'src/components')
-rw-r--r--src/components/media_modal/media_modal.js26
-rw-r--r--src/components/media_modal/media_modal.vue1
2 files changed, 27 insertions, 0 deletions
diff --git a/src/components/media_modal/media_modal.js b/src/components/media_modal/media_modal.js
index f3d381ee..8f67db2b 100644
--- a/src/components/media_modal/media_modal.js
+++ b/src/components/media_modal/media_modal.js
@@ -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()
diff --git a/src/components/media_modal/media_modal.vue b/src/components/media_modal/media_modal.vue
index b5a65d50..728c3035 100644
--- a/src/components/media_modal/media_modal.vue
+++ b/src/components/media_modal/media_modal.vue
@@ -11,6 +11,7 @@
:src="currentMedia.url"
:alt="currentMedia.description"
:title="currentMedia.description"
+ :style="{ transform }"
@touchstart.stop="mediaTouchStart"
@touchmove.stop="mediaTouchMove"
@touchend.stop="mediaTouchEnd"