diff options
| author | Marie <marie@kaifa.ch> | 2024-02-07 21:52:27 +0100 |
|---|---|---|
| committer | Marie <marie@kaifa.ch> | 2024-02-07 21:52:27 +0100 |
| commit | af5ebdfcedd763c236ea3718f06827040d24c458 (patch) | |
| tree | aea3469f76fadde61f7514af9324e31c9b6898e0 /packages/frontend/src/components | |
| parent | fix: add missing diff between SkNote* and MkNote* (diff) | |
| parent | typo (diff) | |
| download | sharkey-af5ebdfcedd763c236ea3718f06827040d24c458.tar.gz sharkey-af5ebdfcedd763c236ea3718f06827040d24c458.tar.bz2 sharkey-af5ebdfcedd763c236ea3718f06827040d24c458.zip | |
merge: more upstream changes
Diffstat (limited to 'packages/frontend/src/components')
| -rw-r--r-- | packages/frontend/src/components/MkCode.core.vue | 1 | ||||
| -rw-r--r-- | packages/frontend/src/components/MkHorizontalSwipe.vue | 34 | ||||
| -rw-r--r-- | packages/frontend/src/components/MkPullToRefresh.vue | 7 |
3 files changed, 36 insertions, 6 deletions
diff --git a/packages/frontend/src/components/MkCode.core.vue b/packages/frontend/src/components/MkCode.core.vue index 0da256866e..5ad5892b7c 100644 --- a/packages/frontend/src/components/MkCode.core.vue +++ b/packages/frontend/src/components/MkCode.core.vue @@ -93,6 +93,7 @@ watch(() => props.lang, (to) => { overflow: auto; border-radius: var(--radius-sm); border: 1px solid var(--divider); + font-family: Consolas, Monaco, Andale Mono, Ubuntu Mono, monospace; color: var(--shiki-fallback); background-color: var(--shiki-fallback-bg); diff --git a/packages/frontend/src/components/MkHorizontalSwipe.vue b/packages/frontend/src/components/MkHorizontalSwipe.vue index 67d32c505a..bf7d43fd43 100644 --- a/packages/frontend/src/components/MkHorizontalSwipe.vue +++ b/packages/frontend/src/components/MkHorizontalSwipe.vue @@ -25,11 +25,11 @@ SPDX-License-Identifier: AGPL-3.0-only </Transition> </div> </template> - <script lang="ts" setup> import { ref, shallowRef, computed, nextTick, watch } from 'vue'; import type { Tab } from '@/components/global/MkPageHeader.tabs.vue'; import { defaultStore } from '@/store.js'; +import { isHorizontalSwipeSwiping as isSwiping } from '@/scripts/touch.js'; const rootEl = shallowRef<HTMLDivElement>(); @@ -49,16 +49,16 @@ const shouldAnimate = computed(() => defaultStore.reactiveState.enableHorizontal // ▼ しきい値 ▼ // // スワイプと判定される最小の距離 -const MIN_SWIPE_DISTANCE = 50; +const MIN_SWIPE_DISTANCE = 20; // スワイプ時の動作を発火する最小の距離 -const SWIPE_DISTANCE_THRESHOLD = 125; +const SWIPE_DISTANCE_THRESHOLD = 70; // スワイプを中断するY方向の移動距離 const SWIPE_ABORT_Y_THRESHOLD = 75; // スワイプできる最大の距離 -const MAX_SWIPE_DISTANCE = 150; +const MAX_SWIPE_DISTANCE = 120; // ▲ しきい値 ▲ // @@ -68,7 +68,6 @@ let startScreenY: number | null = null; const currentTabIndex = computed(() => props.tabs.findIndex(tab => tab.key === tabModel.value)); const pullDistance = ref(0); -const isSwiping = ref(false); const isSwipingForClass = ref(false); let swipeAborted = false; @@ -77,6 +76,8 @@ function touchStart(event: TouchEvent) { if (event.touches.length !== 1) return; + if (hasSomethingToDoWithXSwipe(event.target as HTMLElement)) return; + startScreenX = event.touches[0].screenX; startScreenY = event.touches[0].screenY; } @@ -90,6 +91,8 @@ function touchMove(event: TouchEvent) { if (swipeAborted) return; + if (hasSomethingToDoWithXSwipe(event.target as HTMLElement)) return; + let distanceX = event.touches[0].screenX - startScreenX; let distanceY = event.touches[0].screenY - startScreenY; @@ -139,6 +142,8 @@ function touchEnd(event: TouchEvent) { if (!isSwiping.value) return; + if (hasSomethingToDoWithXSwipe(event.target as HTMLElement)) return; + const distance = event.changedTouches[0].screenX - startScreenX; if (Math.abs(distance) > SWIPE_DISTANCE_THRESHOLD) { @@ -162,6 +167,24 @@ function touchEnd(event: TouchEvent) { }, 400); } +/** 横スワイプに関与する可能性のある要素を調べる */ +function hasSomethingToDoWithXSwipe(el: HTMLElement) { + if (['INPUT', 'TEXTAREA'].includes(el.tagName)) return true; + if (el.isContentEditable) return true; + if (el.scrollWidth > el.clientWidth) return true; + + const style = window.getComputedStyle(el); + if (['absolute', 'fixed', 'sticky'].includes(style.position)) return true; + if (['scroll', 'auto'].includes(style.overflowX)) return true; + if (style.touchAction === 'pan-x') return true; + + if (el.parentElement && el.parentElement !== rootEl.value) { + return hasSomethingToDoWithXSwipe(el.parentElement); + } else { + return false; + } +} + const transitionName = ref<'swipeAnimationLeft' | 'swipeAnimationRight' | undefined>(undefined); watch(tabModel, (newTab, oldTab) => { @@ -182,6 +205,7 @@ watch(tabModel, (newTab, oldTab) => { <style lang="scss" module> .transitionRoot { + touch-action: pan-y pinch-zoom; display: grid; grid-template-columns: 100%; overflow: clip; diff --git a/packages/frontend/src/components/MkPullToRefresh.vue b/packages/frontend/src/components/MkPullToRefresh.vue index e963697997..3898f40ca6 100644 --- a/packages/frontend/src/components/MkPullToRefresh.vue +++ b/packages/frontend/src/components/MkPullToRefresh.vue @@ -26,6 +26,7 @@ SPDX-License-Identifier: AGPL-3.0-only import { onMounted, onUnmounted, ref, shallowRef } from 'vue'; import { i18n } from '@/i18n.js'; import { getScrollContainer } from '@/scripts/scroll.js'; +import { isHorizontalSwipeSwiping } from '@/scripts/touch.js'; const SCROLL_STOP = 10; const MAX_PULL_DISTANCE = Infinity; @@ -129,7 +130,7 @@ function moveEnd() { function moving(event: TouchEvent | PointerEvent) { if (!isPullStart.value || isRefreshing.value || disabled) return; - if ((scrollEl?.scrollTop ?? 0) > (supportPointerDesktop ? SCROLL_STOP : SCROLL_STOP + pullDistance.value)) { + if ((scrollEl?.scrollTop ?? 0) > (supportPointerDesktop ? SCROLL_STOP : SCROLL_STOP + pullDistance.value) || isHorizontalSwipeSwiping.value) { pullDistance.value = 0; isPullEnd.value = false; moveEnd(); @@ -148,6 +149,10 @@ function moving(event: TouchEvent | PointerEvent) { if (event.cancelable) event.preventDefault(); } + if (pullDistance.value > SCROLL_STOP) { + event.stopPropagation(); + } + isPullEnd.value = pullDistance.value >= FIRE_THRESHOLD; } |