enhance gestures

1. disable swipe action-bar when editing
2. resolve conflicts between selection and swipe when editing
3. Remove indent/outdent button on mobile toolbar
This commit is contained in:
llcc
2022-06-05 14:02:21 +08:00
committed by Tienson Qin
parent a70cdd4c52
commit 328fda29a9
4 changed files with 38 additions and 45 deletions

View File

@@ -150,15 +150,18 @@
(defn on-touch-start
[event]
(when-let [touches (.-targetTouches event)]
(when (= (.-length touches) 1)
(let [touch (aget touches 0)
x (.-clientX touch)
y (.-clientY touch)]
(reset! *swipe {:x0 x :y0 y :xi x :yi y :tx x :ty y :direction nil})))))
(let [input (state/get-input)]
(when (= (util/get-selection-start input)
(util/get-selection-end input))
(when-let [touches (.-targetTouches event)]
(when (= (.-length touches) 1)
(let [touch (aget touches 0)
x (.-clientX touch)
y (.-clientY touch)]
(reset! *swipe {:x0 x :y0 y :xi x :yi y :tx x :ty y :direction nil})))))))
(defn on-touch-move
[event block uuid *show-left-menu? *show-right-menu?]
[event block uuid edit? *show-left-menu? *show-right-menu?]
(when-let [touches (.-targetTouches event)]
(when (and (= (.-length touches) 1) @*swipe)
(let [{:keys [x0 xi direction]} @*swipe
@@ -196,11 +199,11 @@
(when (>= dx 0)
(set! (.. left -style -width) (str dx "px")))
(when (< dx 0)
(set! (.. left -style -width) (str (max (+ 50 dx) 0) "px")))
(set! (.. left -style -width) (str (max (+ 40 dx) 0) "px")))
(let [indent (gdom/getFirstElementChild left)]
(when (indentable? block)
(if (>= (.-clientWidth left) 50)
(if (>= (.-clientWidth left) 40)
(set! (.. indent -style -opacity) "100%")
(set! (.. indent -style -opacity) "30%"))))))
@@ -214,19 +217,18 @@
(set! (.. right -style -width) (str (max (- 80 dx) 0) "px")))
(let [outdent (gdom/getFirstElementChild right)
more (gdom/getLastElementChild right)]
(if (and (>= (.-clientWidth right) 40)
(< (.-clientWidth right) 80))
(set! (.. outdent -style -opacity) "100%")
(set! (.. outdent -style -opacity) "30%"))
more (when-not edit?
(gdom/getLastElementChild right))]
(when (and outdent (outdentable? block))
(if (and (>= (.-clientWidth right) 40)
(< (.-clientWidth right) 80))
(set! (.. outdent -style -opacity) "100%")
(set! (.. outdent -style -opacity) "30%")))
(when (outdentable? block)
(when more
(if (>= (.-clientWidth right) 80)
(set! (.. more -style -opacity) "100%")
(set! (.. more -style -opacity) "30%")
;; (set! (.. outdent -style -opacity) "100%")
;; (set! (.. outdent -style -opacity) "30%")
)))))
(set! (.. more -style -opacity) "30%"))))))
:else
nil))))))))
@@ -240,25 +242,25 @@
(try
(when (> (. js/Math abs dx) 10)
(cond
(and left-menu (>= (.-clientWidth left-menu) 50))
(and left-menu (>= (.-clientWidth left-menu) 40))
(when (indentable? block)
(haptics/with-haptics-impact
(indent-outdent-block! block :right)
:light))
(and right-menu (< 40 (.-clientWidth right-menu) 80))
(and right-menu (<= 40 (.-clientWidth right-menu) 79))
(when (outdentable? block)
(haptics/with-haptics-impact
(indent-outdent-block! block :left)
:light))
(and right-menu (>= (.-clientWidth right-menu) 80))
(haptics/with-haptics-impact
(do (state/set-state! :mobile/show-action-bar? true)
(state/set-state! :mobile/actioned-block block)
(select-block! uuid))
:light)
(and right-menu (>= (.-clientWidth right-menu) 80))
(when (outdentable? block)
(haptics/with-haptics-impact
(indent-outdent-block! block :left)
:light))
:else
nil))
(catch js/Error e