Skip to content

Commit

Permalink
Handle long press in main thread
Browse files Browse the repository at this point in the history
  • Loading branch information
Ferossgp committed Jun 28, 2020
1 parent 2f86bee commit f1e9608
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 33 deletions.
35 changes: 17 additions & 18 deletions src/quo/components/animated/pressable.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,8 @@
(bean/bean props)
long-press-ref (react/create-ref)
state (animated/use-value (:undetermined gesture-handler/states))
long-state (animated/use-value (:undetermined gesture-handler/states))
active (animated/eq state (:began gesture-handler/states))
gesture-handler (animated/use-gesture {:state state})
long-gesture-handler (animated/use-gesture {:state long-state})
animation (react/use-memo
(fn []
(animated/with-timing-transition active
Expand All @@ -87,30 +85,31 @@
[type])
handle-press (fn [] (when on-press (on-press)))
handle-press-start (fn [] (when on-press-start (on-press-start)))
handle-long-press (fn [] (when on-long-press (on-long-press)))]
long-gesture-handler (fn [^js evt]
(when (and on-long-press
(= (-> evt .-nativeEvent .-state)
(:active gesture-handler/states)))
(on-long-press)
(animated/set-value state (:undetermined gesture-handler/states))))]
(animated/code!
(fn []
(when on-long-press
(animated/cond* (animated/eq long-state (:active gesture-handler/states))
[(animated/call* [] handle-long-press)
(animated/set state (:undetermined gesture-handler/states))])))
[on-long-press])
(when on-press-start
(animated/cond* (animated/eq state (:began gesture-handler/states))
(animated/call* [] handle-press-start))))
[on-press-start])
(animated/code!
(fn []
(prn :wtf)
(animated/block
[(animated/cond* (animated/eq state (:began gesture-handler/states))
(animated/call* [] handle-press-start))
(when on-press
(animated/cond* (animated/eq state (:end gesture-handler/states))
[(animated/set state (:undetermined gesture-handler/states))
(animated/call* [] handle-press)])]))
[on-press on-long-press on-press-start])
(animated/call* [] handle-press)])))
[on-press])
(reagent/as-element
[gesture-handler/long-press-gesture-handler
(merge long-gesture-handler
{:enabled (boolean (and on-long-press (not disabled)))
:min-duration-ms long-press-duration
:ref long-press-ref})
{:enabled (boolean (and on-long-press (not disabled)))
:on-handler-state-change long-gesture-handler
:min-duration-ms long-press-duration
:ref long-press-ref}
[animated/view {:accessible true
:accessibility-label accessibility-label}
[gesture-handler/tap-gesture-handler
Expand Down
30 changes: 15 additions & 15 deletions src/quo/components/list/item.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -130,21 +130,21 @@
[rn/view {:style {:align-items :center
:flex-direction :row}}
[rn/view {:style (:tiny spacing/padding-horizontal)}
(case accessory
:radio [controls/radio {:value active}]
:checkbox [controls/checkbox {:value active}]
:switch [controls/switch {:value active}]
:text [text/text {:color :secondary
:number-of-lines 1}
accessory-text]
accessory)]
(when (and chevron platform/ios?)
[rn/view {:style {:padding-right (:tiny spacing/spacing)}}
[icons/icon :main-icons/next {:container-style {:opacity 0.4
:align-items :center
:justify-content :center}
:resize-mode :center
:color (:icon-02 @colors/theme)}]])]))
(case accessory
:radio [controls/radio {:value active}]
:checkbox [controls/checkbox {:value active}]
:switch [controls/switch {:value active}]
:text [text/text {:color :secondary
:number-of-lines 1}
accessory-text]
accessory)]
(when (and chevron platform/ios?)
[rn/view {:style {:padding-right (:tiny spacing/spacing)}}
[icons/icon :main-icons/next {:container-style {:opacity 0.4
:align-items :center
:justify-content :center}
:resize-mode :center
:color (:icon-02 @colors/theme)}]])]))

(defn list-item
[{:keys [theme accessory disabled subtitle-max-lines icon title
Expand Down

0 comments on commit f1e9608

Please sign in to comment.