mirror of
https://github.com/status-im/status-react.git
synced 2025-02-17 05:16:46 +00:00
Disable multiple button presses (#18478)
This commit is contained in:
parent
a6565b52ce
commit
b6ce60eccf
@ -63,6 +63,6 @@
|
|||||||
[quo/button
|
[quo/button
|
||||||
{:theme :positive
|
{:theme :positive
|
||||||
:style {:margin-horizontal 8}
|
:style {:margin-horizontal 8}
|
||||||
:on-press #(debounce/dispatch-and-chill [::network/connect-network-pressed target-network-id]
|
:on-press #(debounce/throttle-and-dispatch [::network/connect-network-pressed target-network-id]
|
||||||
1000)}
|
1000)}
|
||||||
(i18n/label :t/allow)]]]]))
|
(i18n/label :t/allow)]]]]))
|
||||||
|
@ -84,7 +84,7 @@
|
|||||||
(zero? (count selected)))
|
(zero? (count selected)))
|
||||||
:accessibility-label :share-community-link
|
:accessibility-label :share-community-link
|
||||||
:type :secondary
|
:type :secondary
|
||||||
:on-press #(debounce/dispatch-and-chill
|
:on-press #(debounce/throttle-and-dispatch
|
||||||
[(if can-invite?
|
[(if can-invite?
|
||||||
::communities/invite-people-confirmation-pressed
|
::communities/invite-people-confirmation-pressed
|
||||||
::communities/share-community-confirmation-pressed) @user-pk
|
::communities/share-community-confirmation-pressed) @user-pk
|
||||||
|
@ -111,7 +111,7 @@
|
|||||||
|
|
||||||
(:available :connected :connected-with-different-key :owned)
|
(:available :connected :connected-with-different-key :owned)
|
||||||
[react/touchable-highlight
|
[react/touchable-highlight
|
||||||
{:on-press #(debounce/dispatch-and-chill [::ens/input-submitted] 3000)}
|
{:on-press #(debounce/throttle-and-dispatch [::ens/input-submitted] 3000)}
|
||||||
[icon-wrapper colors/blue
|
[icon-wrapper colors/blue
|
||||||
[icons/icon :main-icons/arrow-right {:color colors/white-persist}]]]
|
[icons/icon :main-icons/arrow-right {:color colors/white-persist}]]]
|
||||||
|
|
||||||
@ -365,8 +365,9 @@
|
|||||||
:right [react/view {:padding-horizontal 8}
|
:right [react/view {:padding-horizontal 8}
|
||||||
[quo/button
|
[quo/button
|
||||||
{:disabled (or (not @checked?) (not sufficient-funds?))
|
{:disabled (or (not @checked?) (not sufficient-funds?))
|
||||||
:on-press #(debounce/dispatch-and-chill [::ens/register-name-pressed address]
|
:on-press #(debounce/throttle-and-dispatch [::ens/register-name-pressed
|
||||||
2000)}
|
address]
|
||||||
|
2000)}
|
||||||
(if sufficient-funds?
|
(if sufficient-funds?
|
||||||
(i18n/label :t/ens-register)
|
(i18n/label :t/ens-register)
|
||||||
(i18n/label :t/not-enough-snt))]]}]]))))
|
(i18n/label :t/not-enough-snt))]]}]]))))
|
||||||
|
@ -139,9 +139,9 @@
|
|||||||
{:type :secondary
|
{:type :secondary
|
||||||
:accessibility-label :create-group-chat-button
|
:accessibility-label :create-group-chat-button
|
||||||
:disabled group-name-empty?
|
:disabled group-name-empty?
|
||||||
:on-press #(debounce/dispatch-and-chill [:group-chats.ui/create-pressed
|
:on-press #(debounce/throttle-and-dispatch [:group-chats.ui/create-pressed
|
||||||
group-name]
|
group-name]
|
||||||
300)}
|
300)}
|
||||||
(i18n/label :t/create-group-chat)]}]]])))
|
(i18n/label :t/create-group-chat)]}]]])))
|
||||||
|
|
||||||
(defn searchable-contact-list
|
(defn searchable-contact-list
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
[legacy.status-im.ui.screens.network.styles :as st]
|
[legacy.status-im.ui.screens.network.styles :as st]
|
||||||
[legacy.status-im.ui.screens.network.views :as network-settings]
|
[legacy.status-im.ui.screens.network.views :as network-settings]
|
||||||
[re-frame.core :as re-frame]
|
[re-frame.core :as re-frame]
|
||||||
[utils.debounce :refer [dispatch-and-chill]]
|
[utils.debounce :refer [throttle-and-dispatch]]
|
||||||
[utils.i18n :as i18n])
|
[utils.i18n :as i18n])
|
||||||
(:require-macros [legacy.status-im.utils.views :as views]))
|
(:require-macros [legacy.status-im.utils.views :as views]))
|
||||||
|
|
||||||
@ -25,7 +25,7 @@
|
|||||||
:connected? connected?}]
|
:connected? connected?}]
|
||||||
(when-not connected?
|
(when-not connected?
|
||||||
[react/touchable-highlight
|
[react/touchable-highlight
|
||||||
{:on-press #(dispatch-and-chill [::network/connect-network-pressed id] 1000)}
|
{:on-press #(throttle-and-dispatch [::network/connect-network-pressed id] 1000)}
|
||||||
[react/view st/connect-button-container
|
[react/view st/connect-button-container
|
||||||
[react/view
|
[react/view
|
||||||
{:style st/connect-button
|
{:style st/connect-button
|
||||||
|
@ -109,7 +109,7 @@
|
|||||||
(defn hide-sheet-and-dispatch-old
|
(defn hide-sheet-and-dispatch-old
|
||||||
[event]
|
[event]
|
||||||
(re-frame/dispatch [:bottom-sheet/hide-old])
|
(re-frame/dispatch [:bottom-sheet/hide-old])
|
||||||
(debounce/dispatch-and-chill event 2000))
|
(debounce/throttle-and-dispatch event 2000))
|
||||||
|
|
||||||
(defn invitation-sheet
|
(defn invitation-sheet
|
||||||
[{:keys [id]} contact]
|
[{:keys [id]} contact]
|
||||||
|
@ -34,7 +34,7 @@
|
|||||||
(fn
|
(fn
|
||||||
[{:keys [on-press on-long-press disabled? type background size icon-left icon-right icon-top
|
[{:keys [on-press on-long-press disabled? type background size icon-left icon-right icon-top
|
||||||
customization-color theme accessibility-label icon-only? container-style inner-style
|
customization-color theme accessibility-label icon-only? container-style inner-style
|
||||||
pressed? on-press-in on-press-out]
|
pressed? on-press-in on-press-out allow-multiple-presses?]
|
||||||
:or {type :primary
|
:or {type :primary
|
||||||
size 40
|
size 40
|
||||||
customization-color (cond (= type :primary) :blue
|
customization-color (cond (= type :primary) :blue
|
||||||
@ -52,16 +52,17 @@
|
|||||||
:icon-only? icon-only?})
|
:icon-only? icon-only?})
|
||||||
icon-size (when (= 24 size) 12)]
|
icon-size (when (= 24 size) 12)]
|
||||||
[rn/touchable-without-feedback
|
[rn/touchable-without-feedback
|
||||||
{:disabled disabled?
|
{:disabled disabled?
|
||||||
:accessibility-label accessibility-label
|
:accessibility-label accessibility-label
|
||||||
:on-press-in (fn []
|
:on-press-in (fn []
|
||||||
(reset! pressed-state? true)
|
(reset! pressed-state? true)
|
||||||
(when on-press-in (on-press-in)))
|
(when on-press-in (on-press-in)))
|
||||||
:on-press-out (fn []
|
:on-press-out (fn []
|
||||||
(reset! pressed-state? nil)
|
(reset! pressed-state? nil)
|
||||||
(when on-press-out (on-press-out)))
|
(when on-press-out (on-press-out)))
|
||||||
:on-press on-press
|
:on-press on-press
|
||||||
:on-long-press on-long-press}
|
:allow-multiple-presses? allow-multiple-presses?
|
||||||
|
:on-long-press on-long-press}
|
||||||
[rn/view
|
[rn/view
|
||||||
{:style (merge
|
{:style (merge
|
||||||
(style/shape-style-container size border-radius)
|
(style/shape-style-container size border-radius)
|
||||||
|
@ -15,11 +15,12 @@
|
|||||||
[rn/view
|
[rn/view
|
||||||
{:style style/container}
|
{:style style/container}
|
||||||
[button/button
|
[button/button
|
||||||
{:icon true
|
{:icon true
|
||||||
:type :outline
|
:type :outline
|
||||||
:accessibility-label :previous-month-button
|
:accessibility-label :previous-month-button
|
||||||
:size 24
|
:allow-multiple-presses? true
|
||||||
:on-press #(on-change (utils/previous-month year month))}
|
:size 24
|
||||||
|
:on-press #(on-change (utils/previous-month year month))}
|
||||||
:i/chevron-left]
|
:i/chevron-left]
|
||||||
[text/text
|
[text/text
|
||||||
{:weight :semi-bold
|
{:weight :semi-bold
|
||||||
@ -27,11 +28,12 @@
|
|||||||
:style (style/text theme)}
|
:style (style/text theme)}
|
||||||
(utils/format-month-year year month)]
|
(utils/format-month-year year month)]
|
||||||
[button/button
|
[button/button
|
||||||
{:icon true
|
{:icon true
|
||||||
:accessibility-label :next-month-button
|
:accessibility-label :next-month-button
|
||||||
:size 24
|
:allow-multiple-presses? true
|
||||||
:type :outline
|
:size 24
|
||||||
:on-press #(on-change (utils/next-month year month))}
|
:type :outline
|
||||||
|
:on-press #(on-change (utils/next-month year month))}
|
||||||
:i/chevron-right]]))
|
:i/chevron-right]]))
|
||||||
|
|
||||||
(def view (theme/with-theme view-internal))
|
(def view (theme/with-theme view-internal))
|
||||||
|
@ -31,9 +31,10 @@
|
|||||||
theme))]
|
theme))]
|
||||||
|
|
||||||
[rn/pressable
|
[rn/pressable
|
||||||
{:style (style/color-button hex-color selected? idx window-width)
|
{:style (style/color-button hex-color selected? idx window-width)
|
||||||
:accessibility-label :color-picker-item
|
:accessibility-label :color-picker-item
|
||||||
:on-press #(on-press color)}
|
:allow-multiple-presses? true
|
||||||
|
:on-press #(on-press color)}
|
||||||
(if (and (= :feng-shui color) (not selected?))
|
(if (and (= :feng-shui color) (not selected?))
|
||||||
[feng-shui
|
[feng-shui
|
||||||
(assoc props
|
(assoc props
|
||||||
|
@ -39,13 +39,15 @@
|
|||||||
|
|
||||||
(defn user
|
(defn user
|
||||||
[{:keys [short-chat-key primary-name secondary-name photo-path online? contact? verified?
|
[{:keys [short-chat-key primary-name secondary-name photo-path online? contact? verified?
|
||||||
untrustworthy? on-press on-long-press accessory customization-color theme]}]
|
untrustworthy? on-press on-long-press accessory customization-color theme
|
||||||
|
allow-multiple-presses?]}]
|
||||||
[rn/touchable-highlight
|
[rn/touchable-highlight
|
||||||
{:style container-style
|
{:style container-style
|
||||||
:underlay-color (colors/resolve-color customization-color theme 5)
|
:underlay-color (colors/resolve-color customization-color theme 5)
|
||||||
:accessibility-label :user-list
|
:allow-multiple-presses? allow-multiple-presses?
|
||||||
:on-press (when on-press on-press)
|
:accessibility-label :user-list
|
||||||
:on-long-press (when on-long-press on-long-press)}
|
:on-press (when on-press on-press)
|
||||||
|
:on-long-press (when on-long-press on-long-press)}
|
||||||
[:<>
|
[:<>
|
||||||
[user-avatar/user-avatar
|
[user-avatar/user-avatar
|
||||||
{:full-name primary-name
|
{:full-name primary-name
|
||||||
|
@ -47,12 +47,13 @@
|
|||||||
:height 40
|
:height 40
|
||||||
:border-radius 10})]
|
:border-radius 10})]
|
||||||
[rn/touchable-without-feedback
|
[rn/touchable-without-feedback
|
||||||
{:test-ID test-ID
|
{:test-ID test-ID
|
||||||
:on-long-press on-long-press ;;NOTE - this is temporary while supporting old wallet
|
:on-long-press on-long-press ;;NOTE - this is temporary while supporting old wallet
|
||||||
:on-press on-press
|
:allow-multiple-presses? true
|
||||||
:on-press-in #(toggle-background-color background-color false pass-through?)
|
:on-press on-press
|
||||||
:on-press-out #(toggle-background-color background-color true pass-through?)
|
:on-press-in #(toggle-background-color background-color false pass-through?)
|
||||||
:accessibility-label accessibility-label}
|
:on-press-out #(toggle-background-color background-color true pass-through?)
|
||||||
|
:accessibility-label accessibility-label}
|
||||||
[reanimated/view {:style background-animated-style}
|
[reanimated/view {:style background-animated-style}
|
||||||
;; In android animations are not working for the animated components which are nested by
|
;; In android animations are not working for the animated components which are nested by
|
||||||
;; hole-view,
|
;; hole-view,
|
||||||
|
@ -19,15 +19,16 @@
|
|||||||
(let [label-color (style/get-label-color disabled? theme blur?)
|
(let [label-color (style/get-label-color disabled? theme blur?)
|
||||||
background-color (style/toggle-background-color @pressed? blur? theme)]
|
background-color (style/toggle-background-color @pressed? blur? theme)]
|
||||||
[rn/pressable
|
[rn/pressable
|
||||||
{:accessibility-label (label->accessibility-label label)
|
{:accessibility-label (label->accessibility-label label)
|
||||||
:disabled (or disabled? (not label))
|
:disabled (or disabled? (not label))
|
||||||
:on-press (fn []
|
:on-press (fn []
|
||||||
(when on-press
|
(when on-press
|
||||||
(on-press label)))
|
(on-press label)))
|
||||||
:on-press-in #(reset! pressed? true)
|
:allow-multiple-presses? true
|
||||||
:on-press-out #(reset! pressed? false)
|
:on-press-in #(reset! pressed? true)
|
||||||
:hit-slop {:top 8 :bottom 8 :left 25 :right 25}
|
:on-press-out #(reset! pressed? false)
|
||||||
:style (style/container background-color)}
|
:hit-slop {:top 8 :bottom 8 :left 25 :right 25}
|
||||||
|
:style (style/container background-color)}
|
||||||
(case type
|
(case type
|
||||||
:key [icons/icon
|
:key [icons/icon
|
||||||
label
|
label
|
||||||
|
@ -12,12 +12,13 @@
|
|||||||
accessibility-label]
|
accessibility-label]
|
||||||
:or {accessibility-label :reaction}}]
|
:or {accessibility-label :reaction}}]
|
||||||
[rn/pressable
|
[rn/pressable
|
||||||
{:accessibility-label accessibility-label
|
{:accessibility-label accessibility-label
|
||||||
:style (merge (style/container @pressed?)
|
:allow-multiple-presses? true
|
||||||
container-style)
|
:style (merge (style/container @pressed?)
|
||||||
:on-press (fn [e]
|
container-style)
|
||||||
(swap! pressed? not)
|
:on-press (fn [e]
|
||||||
(when on-press
|
(swap! pressed? not)
|
||||||
(on-press e)))}
|
(when on-press
|
||||||
|
(on-press e)))}
|
||||||
[rn/text
|
[rn/text
|
||||||
(reactions.resource/system-emojis emoji)]])))
|
(reactions.resource/system-emojis emoji)]])))
|
||||||
|
@ -30,7 +30,8 @@
|
|||||||
:theme theme})]
|
:theme theme})]
|
||||||
[rn/pressable
|
[rn/pressable
|
||||||
(when-not disabled?
|
(when-not disabled?
|
||||||
{:on-press #(handle-press on-change internal-checked? actual-checked?)})
|
{:on-press #(handle-press on-change internal-checked? actual-checked?)
|
||||||
|
:allow-multiple-presses? true})
|
||||||
[rn/view
|
[rn/view
|
||||||
{:style outer-styles
|
{:style outer-styles
|
||||||
:needs-offscreen-alpha-compositing true
|
:needs-offscreen-alpha-compositing true
|
||||||
|
@ -7,6 +7,7 @@
|
|||||||
[react-native.flat-list :as flat-list]
|
[react-native.flat-list :as flat-list]
|
||||||
[react-native.platform :as platform]
|
[react-native.platform :as platform]
|
||||||
[react-native.section-list :as section-list]
|
[react-native.section-list :as section-list]
|
||||||
|
[react-native.utils :as utils]
|
||||||
[reagent.core :as reagent]))
|
[reagent.core :as reagent]))
|
||||||
|
|
||||||
(def app-state ^js (.-AppState ^js react-native))
|
(def app-state ^js (.-AppState ^js react-native))
|
||||||
@ -33,12 +34,28 @@
|
|||||||
(def text (reagent/adapt-react-class (.-Text ^js react-native)))
|
(def text (reagent/adapt-react-class (.-Text ^js react-native)))
|
||||||
(def text-input (reagent/adapt-react-class (.-TextInput ^js react-native)))
|
(def text-input (reagent/adapt-react-class (.-TextInput ^js react-native)))
|
||||||
|
|
||||||
(def pressable (reagent/adapt-react-class (.-Pressable ^js react-native)))
|
(def pressable-class (reagent/adapt-react-class (.-Pressable ^js react-native)))
|
||||||
(def touchable-opacity (reagent/adapt-react-class (.-TouchableOpacity ^js react-native)))
|
(def touchable-opacity-class (reagent/adapt-react-class (.-TouchableOpacity ^js react-native)))
|
||||||
(def touchable-highlight (reagent/adapt-react-class (.-TouchableHighlight ^js react-native)))
|
(def touchable-highlight-class (reagent/adapt-react-class (.-TouchableHighlight ^js react-native)))
|
||||||
(def touchable-without-feedback
|
(def touchable-without-feedback-class
|
||||||
(reagent/adapt-react-class (.-TouchableWithoutFeedback ^js react-native)))
|
(reagent/adapt-react-class (.-TouchableWithoutFeedback ^js react-native)))
|
||||||
|
|
||||||
|
(defn pressable
|
||||||
|
[props & children]
|
||||||
|
(into [pressable-class (utils/custom-pressable-props props)] children))
|
||||||
|
|
||||||
|
(defn touchable-opacity
|
||||||
|
[props & children]
|
||||||
|
(into [touchable-opacity-class (utils/custom-pressable-props props)] children))
|
||||||
|
|
||||||
|
(defn touchable-highlight
|
||||||
|
[props & children]
|
||||||
|
(into [touchable-highlight-class (utils/custom-pressable-props props)] children))
|
||||||
|
|
||||||
|
(defn touchable-without-feedback
|
||||||
|
[props & children]
|
||||||
|
(into [touchable-without-feedback-class (utils/custom-pressable-props props)] children))
|
||||||
|
|
||||||
(def flat-list flat-list/flat-list)
|
(def flat-list flat-list/flat-list)
|
||||||
|
|
||||||
(def section-list section-list/section-list)
|
(def section-list section-list/section-list)
|
||||||
|
32
src/react_native/utils.cljs
Normal file
32
src/react_native/utils.cljs
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
(ns react-native.utils)
|
||||||
|
|
||||||
|
(defonce ^:private throttle (atom {}))
|
||||||
|
|
||||||
|
(defn- wrapped-ref
|
||||||
|
[{:keys [ref]} throttle-id]
|
||||||
|
(fn [ref-value]
|
||||||
|
(when ref-value
|
||||||
|
(when ref
|
||||||
|
(ref ref-value))
|
||||||
|
(reset! throttle-id ref-value))))
|
||||||
|
|
||||||
|
(defn- throttled-on-press
|
||||||
|
[{:keys [on-press allow-multiple-presses? throttle-duration]} throttle-id]
|
||||||
|
(if allow-multiple-presses?
|
||||||
|
on-press
|
||||||
|
(fn []
|
||||||
|
(let [id @throttle-id]
|
||||||
|
(when (and id (not (get @throttle id)))
|
||||||
|
(swap! throttle assoc id true)
|
||||||
|
(on-press)
|
||||||
|
(js/setTimeout
|
||||||
|
#(swap! throttle dissoc id)
|
||||||
|
(or throttle-duration 500)))))))
|
||||||
|
|
||||||
|
(defn custom-pressable-props
|
||||||
|
[{:keys [on-press] :as props}]
|
||||||
|
(let [throttle-id (atom nil)]
|
||||||
|
(cond-> props
|
||||||
|
on-press
|
||||||
|
(assoc :on-press (throttled-on-press props throttle-id)
|
||||||
|
:ref (wrapped-ref props throttle-id)))))
|
@ -5,22 +5,23 @@
|
|||||||
[utils.re-frame :as rf]))
|
[utils.re-frame :as rf]))
|
||||||
|
|
||||||
(defn contact-list-item
|
(defn contact-list-item
|
||||||
[{:keys [on-press on-long-press accessory]}
|
[{:keys [on-press on-long-press accessory allow-multiple-presses?]}
|
||||||
{:keys [primary-name secondary-name public-key compressed-key ens-verified added?]}
|
{:keys [primary-name secondary-name public-key compressed-key ens-verified added?]}
|
||||||
theme]
|
theme]
|
||||||
(let [photo-path (rf/sub [:chats/photo-path public-key])
|
(let [photo-path (rf/sub [:chats/photo-path public-key])
|
||||||
online? (rf/sub [:visibility-status-updates/online? public-key])
|
online? (rf/sub [:visibility-status-updates/online? public-key])
|
||||||
customization-color (rf/sub [:profile/customization-color])]
|
customization-color (rf/sub [:profile/customization-color])]
|
||||||
[quo/user
|
[quo/user
|
||||||
{:customization-color customization-color
|
{:customization-color customization-color
|
||||||
:theme theme
|
:allow-multiple-presses? allow-multiple-presses?
|
||||||
:short-chat-key (address/get-shortened-compressed-key (or compressed-key public-key))
|
:theme theme
|
||||||
:primary-name primary-name
|
:short-chat-key (address/get-shortened-compressed-key (or compressed-key public-key))
|
||||||
:secondary-name secondary-name
|
:primary-name primary-name
|
||||||
:photo-path photo-path
|
:secondary-name secondary-name
|
||||||
:online? online?
|
:photo-path photo-path
|
||||||
:verified? ens-verified
|
:online? online?
|
||||||
:contact? added?
|
:verified? ens-verified
|
||||||
:on-press on-press
|
:contact? added?
|
||||||
:on-long-press on-long-press
|
:on-press on-press
|
||||||
:accessory accessory}]))
|
:on-long-press on-long-press
|
||||||
|
:accessory accessory}]))
|
||||||
|
@ -4,7 +4,6 @@
|
|||||||
[status-im.common.home.top-nav.style :as style]
|
[status-im.common.home.top-nav.style :as style]
|
||||||
[status-im.constants :as constants]
|
[status-im.constants :as constants]
|
||||||
[status-im.contexts.profile.utils :as profile.utils]
|
[status-im.contexts.profile.utils :as profile.utils]
|
||||||
[utils.debounce :refer [dispatch-and-chill]]
|
|
||||||
[utils.re-frame :as rf]))
|
[utils.re-frame :as rf]))
|
||||||
|
|
||||||
(defn view
|
(defn view
|
||||||
@ -36,7 +35,7 @@
|
|||||||
{:avatar-on-press #(rf/dispatch [:open-modal :settings])
|
{:avatar-on-press #(rf/dispatch [:open-modal :settings])
|
||||||
:scan-on-press #(js/alert "to be implemented")
|
:scan-on-press #(js/alert "to be implemented")
|
||||||
:activity-center-on-press #(rf/dispatch [:activity-center/open])
|
:activity-center-on-press #(rf/dispatch [:activity-center/open])
|
||||||
:qr-code-on-press #(dispatch-and-chill [:open-modal :share-shell] 1000)
|
:qr-code-on-press #(rf/dispatch [:open-modal :share-shell])
|
||||||
:container-style (merge style/top-nav-container container-style)
|
:container-style (merge style/top-nav-container container-style)
|
||||||
:blur? blur?
|
:blur? blur?
|
||||||
:jump-to? jump-to?
|
:jump-to? jump-to?
|
||||||
|
@ -23,7 +23,7 @@
|
|||||||
:label (i18n/label :t/new-chat)
|
:label (i18n/label :t/new-chat)
|
||||||
:on-press (fn []
|
:on-press (fn []
|
||||||
(rf/dispatch [:group-chat/clear-contacts])
|
(rf/dispatch [:group-chat/clear-contacts])
|
||||||
(debounce/dispatch-and-chill
|
(debounce/throttle-and-dispatch
|
||||||
[:open-modal :start-a-new-chat]
|
[:open-modal :start-a-new-chat]
|
||||||
1000))}
|
1000))}
|
||||||
{:icon :i/add-user
|
{:icon :i/add-user
|
||||||
@ -31,6 +31,6 @@
|
|||||||
:label (i18n/label :t/add-a-contact)
|
:label (i18n/label :t/add-a-contact)
|
||||||
:sub-label (i18n/label :t/enter-chat-key)
|
:sub-label (i18n/label :t/enter-chat-key)
|
||||||
:add-divider? true
|
:add-divider? true
|
||||||
:on-press #(debounce/dispatch-and-chill
|
:on-press #(debounce/throttle-and-dispatch
|
||||||
[:open-modal :new-contact]
|
[:open-modal :new-contact]
|
||||||
1000)}]]])
|
1000)}]]])
|
||||||
|
@ -79,10 +79,11 @@
|
|||||||
(let [on-toggle #(group-chat-member-toggle member? (swap! checked? not) public-key)]
|
(let [on-toggle #(group-chat-member-toggle member? (swap! checked? not) public-key)]
|
||||||
[contact-list-item/contact-list-item
|
[contact-list-item/contact-list-item
|
||||||
(when (not= current-pk public-key)
|
(when (not= current-pk public-key)
|
||||||
{:on-press on-toggle
|
{:on-press on-toggle
|
||||||
:accessory {:type :checkbox
|
:allow-multiple-presses? true
|
||||||
:checked? @checked?
|
:accessory {:type :checkbox
|
||||||
:on-check on-toggle}})
|
:checked? @checked?
|
||||||
|
:on-check on-toggle}})
|
||||||
item]))))
|
item]))))
|
||||||
|
|
||||||
(defn add-manage-members
|
(defn add-manage-members
|
||||||
@ -135,10 +136,11 @@
|
|||||||
extra-data])}])]
|
extra-data])}])]
|
||||||
[contact-list-item/contact-list-item
|
[contact-list-item/contact-list-item
|
||||||
(when (not= public-key current-pk)
|
(when (not= public-key current-pk)
|
||||||
{:on-press #(rf/dispatch [:chat.ui/show-profile public-key])
|
{:on-press #(rf/dispatch [:chat.ui/show-profile public-key])
|
||||||
:on-long-press show-profile-actions
|
:allow-multiple-presses? true
|
||||||
:accessory {:type :options
|
:on-long-press show-profile-actions
|
||||||
:on-press show-profile-actions}})
|
:accessory {:type :options
|
||||||
|
:on-press show-profile-actions}})
|
||||||
item]))
|
item]))
|
||||||
|
|
||||||
(defn group-details
|
(defn group-details
|
||||||
|
@ -18,7 +18,7 @@
|
|||||||
[chat-id]
|
[chat-id]
|
||||||
(fn []
|
(fn []
|
||||||
(rf/dispatch [:dismiss-keyboard])
|
(rf/dispatch [:dismiss-keyboard])
|
||||||
(debounce/dispatch-and-chill [:chat/navigate-to-chat chat-id] 500)))
|
(debounce/throttle-and-dispatch [:chat/navigate-to-chat chat-id] 500)))
|
||||||
|
|
||||||
(defn parsed-text-to-one-line
|
(defn parsed-text-to-one-line
|
||||||
[parsed-text]
|
[parsed-text]
|
||||||
|
@ -57,10 +57,11 @@
|
|||||||
(re-frame/dispatch [:deselect-contact public-key])
|
(re-frame/dispatch [:deselect-contact public-key])
|
||||||
(re-frame/dispatch [:select-contact public-key]))]
|
(re-frame/dispatch [:select-contact public-key]))]
|
||||||
[contact-list-item/contact-list-item
|
[contact-list-item/contact-list-item
|
||||||
{:on-press on-toggle
|
{:on-press on-toggle
|
||||||
:accessory {:type :checkbox
|
:allow-multiple-presses? true
|
||||||
:checked? user-selected?
|
:accessory {:type :checkbox
|
||||||
:on-check on-toggle}}
|
:checked? user-selected?
|
||||||
|
:on-check on-toggle}}
|
||||||
item])))
|
item])))
|
||||||
|
|
||||||
(defn- view-internal
|
(defn- view-internal
|
||||||
|
@ -190,16 +190,17 @@
|
|||||||
{:accessibility-label :audio-message-container
|
{:accessibility-label :audio-message-container
|
||||||
:style (style/container)}
|
:style (style/container)}
|
||||||
[rn/touchable-opacity
|
[rn/touchable-opacity
|
||||||
{:accessibility-label :play-pause-audio-message-button
|
{:accessibility-label :play-pause-audio-message-button
|
||||||
:on-press #(play-pause-player {:player-key player-key
|
:allow-multiple-presses? true
|
||||||
:player-state player-state
|
:on-press #(play-pause-player {:player-key player-key
|
||||||
:progress progress
|
:player-state player-state
|
||||||
:message-id message-id
|
:progress progress
|
||||||
:audio-duration-ms duration
|
:message-id message-id
|
||||||
:seeking-audio? seeking-audio?
|
:audio-duration-ms duration
|
||||||
:user-interaction? true
|
:seeking-audio? seeking-audio?
|
||||||
:mediaserver-port mediaserver-port})
|
:user-interaction? true
|
||||||
:style (style/play-pause-container)}
|
:mediaserver-port mediaserver-port})
|
||||||
|
:style (style/play-pause-container)}
|
||||||
[quo/icon
|
[quo/icon
|
||||||
(cond
|
(cond
|
||||||
(= @player-state :preparing)
|
(= @player-state :preparing)
|
||||||
|
@ -26,8 +26,9 @@
|
|||||||
[quo/communities-membership-list-item
|
[quo/communities-membership-list-item
|
||||||
{:customization-color customization-color
|
{:customization-color customization-color
|
||||||
:style {:padding-horizontal 20}
|
:style {:padding-horizontal 20}
|
||||||
:on-press #(debounce/dispatch-and-chill [:communities/navigate-to-community-overview id]
|
:on-press #(debounce/throttle-and-dispatch [:communities/navigate-to-community-overview
|
||||||
500)
|
id]
|
||||||
|
500)
|
||||||
:on-long-press #(rf/dispatch
|
:on-long-press #(rf/dispatch
|
||||||
[:show-bottom-sheet
|
[:show-bottom-sheet
|
||||||
{:content (fn []
|
{:content (fn []
|
||||||
|
@ -199,7 +199,7 @@
|
|||||||
(assoc :on-press (when joined-or-spectated
|
(assoc :on-press (when joined-or-spectated
|
||||||
(fn []
|
(fn []
|
||||||
(rf/dispatch [:dismiss-keyboard])
|
(rf/dispatch [:dismiss-keyboard])
|
||||||
(debounce/dispatch-and-chill
|
(debounce/throttle-and-dispatch
|
||||||
[:communities/navigate-to-community-chat (str community-id id)]
|
[:communities/navigate-to-community-chat (str community-id id)]
|
||||||
1000)))
|
1000)))
|
||||||
:on-long-press #(rf/dispatch
|
:on-long-press #(rf/dispatch
|
||||||
|
@ -19,16 +19,16 @@
|
|||||||
(reset! scan-sync-code/dismiss-animations reset-top-animation-fn))
|
(reset! scan-sync-code/dismiss-animations reset-top-animation-fn))
|
||||||
:animations-duration constants/onboarding-modal-animation-duration
|
:animations-duration constants/onboarding-modal-animation-duration
|
||||||
:animations-delay constants/onboarding-modal-animation-delay
|
:animations-delay constants/onboarding-modal-animation-delay
|
||||||
:top-card {:on-press #(debounce/dispatch-and-chill [:open-modal
|
:top-card {:on-press #(debounce/throttle-and-dispatch [:open-modal
|
||||||
:sign-in-intro]
|
:sign-in-intro]
|
||||||
2000)
|
2000)
|
||||||
:heading (i18n/label :t/sign-in)
|
:heading (i18n/label :t/sign-in)
|
||||||
:animated-heading (i18n/label :t/sign-in-by-syncing)
|
:animated-heading (i18n/label :t/sign-in-by-syncing)
|
||||||
:accessibility-label :already-use-status-button}
|
:accessibility-label :already-use-status-button}
|
||||||
:bottom-card {:on-press (fn []
|
:bottom-card {:on-press (fn []
|
||||||
(when-let [blur-show-fn @overlay/blur-show-fn-atom]
|
(when-let [blur-show-fn @overlay/blur-show-fn-atom]
|
||||||
(blur-show-fn))
|
(blur-show-fn))
|
||||||
(debounce/dispatch-and-chill
|
(debounce/throttle-and-dispatch
|
||||||
[:open-modal :new-to-status]
|
[:open-modal :new-to-status]
|
||||||
1000))
|
1000))
|
||||||
:heading (i18n/label :t/new-to-status)
|
:heading (i18n/label :t/new-to-status)
|
||||||
@ -45,7 +45,7 @@
|
|||||||
:style style/plain-text}
|
:style style/plain-text}
|
||||||
(i18n/label :t/by-continuing-you-accept)]
|
(i18n/label :t/by-continuing-you-accept)]
|
||||||
[quo/text
|
[quo/text
|
||||||
{:on-press #(debounce/dispatch-and-chill [:open-modal :privacy-policy] 1000)
|
{:on-press #(debounce/throttle-and-dispatch [:open-modal :privacy-policy] 1000)
|
||||||
:size :paragraph-2
|
:size :paragraph-2
|
||||||
:weight :regular
|
:weight :regular
|
||||||
:style style/highlighted-text}
|
:style style/highlighted-text}
|
||||||
|
@ -31,7 +31,7 @@
|
|||||||
(* 2 56) ;; two other list items
|
(* 2 56) ;; two other list items
|
||||||
(* 2 16) ;; spacing between items
|
(* 2 16) ;; spacing between items
|
||||||
220) ;; extra spacing (top bar)
|
220) ;; extra spacing (top bar)
|
||||||
:on-press #(debounce/dispatch-and-chill
|
:on-press #(debounce/throttle-and-dispatch
|
||||||
[:onboarding/navigate-to-create-profile]
|
[:onboarding/navigate-to-create-profile]
|
||||||
1000)}]
|
1000)}]
|
||||||
[rn/view {:style style/subtitle-container}
|
[rn/view {:style style/subtitle-container}
|
||||||
|
@ -35,8 +35,8 @@
|
|||||||
in-onboarding? (rf/dispatch [:navigate-back-to :sign-in-intro])
|
in-onboarding? (rf/dispatch [:navigate-back-to :sign-in-intro])
|
||||||
:else (do
|
:else (do
|
||||||
(rf/dispatch [:navigate-back])
|
(rf/dispatch [:navigate-back])
|
||||||
(debounce/dispatch-and-chill [:open-modal :sign-in]
|
(debounce/throttle-and-dispatch [:open-modal :sign-in]
|
||||||
1000))))
|
1000))))
|
||||||
:accessibility-label :try-again-later-button
|
:accessibility-label :try-again-later-button
|
||||||
:customization-color profile-color
|
:customization-color profile-color
|
||||||
:container-style style/try-again-button}
|
:container-style style/try-again-button}
|
||||||
|
@ -50,13 +50,13 @@
|
|||||||
:on-press (fn []
|
:on-press (fn []
|
||||||
(when @push-animation-fn-atom
|
(when @push-animation-fn-atom
|
||||||
(@push-animation-fn-atom))
|
(@push-animation-fn-atom))
|
||||||
(debounce/dispatch-and-chill
|
(debounce/throttle-and-dispatch
|
||||||
[:open-modal :new-to-status]
|
[:open-modal :new-to-status]
|
||||||
1000))
|
1000))
|
||||||
:accessibility-label :create-new-profile}
|
:accessibility-label :create-new-profile}
|
||||||
{:icon :i/multi-profile
|
{:icon :i/multi-profile
|
||||||
:label (i18n/label :t/add-existing-status-profile)
|
:label (i18n/label :t/add-existing-status-profile)
|
||||||
:on-press #(debounce/dispatch-and-chill
|
:on-press #(debounce/throttle-and-dispatch
|
||||||
[:open-modal :sign-in]
|
[:open-modal :sign-in]
|
||||||
1000)
|
1000)
|
||||||
:accessibility-label :multi-profile}]]])
|
:accessibility-label :multi-profile}]]])
|
||||||
|
@ -56,7 +56,7 @@
|
|||||||
:on-press #(rf/dispatch [:navigate-back])
|
:on-press #(rf/dispatch [:navigate-back])
|
||||||
:right-side [{:icon-name :i/multi-profile :on-press #(rf/dispatch [:open-modal :sign-in])}
|
:right-side [{:icon-name :i/multi-profile :on-press #(rf/dispatch [:open-modal :sign-in])}
|
||||||
{:icon-name :i/qr-code
|
{:icon-name :i/qr-code
|
||||||
:on-press #(debounce/dispatch-and-chill [:open-modal :share-shell] 1000)}
|
:on-press #(debounce/throttle-and-dispatch [:open-modal :share-shell] 1000)}
|
||||||
{:icon-name :i/share :on-press not-implemented/alert}]}]]
|
{:icon-name :i/share :on-press not-implemented/alert}]}]]
|
||||||
[rn/flat-list
|
[rn/flat-list
|
||||||
{:key :list
|
{:key :list
|
||||||
@ -74,7 +74,7 @@
|
|||||||
:jump-to
|
:jump-to
|
||||||
{:on-press (fn []
|
{:on-press (fn []
|
||||||
(rf/dispatch [:navigate-back])
|
(rf/dispatch [:navigate-back])
|
||||||
(debounce/dispatch-and-chill [:shell/navigate-to-jump-to] 500))
|
(debounce/throttle-and-dispatch [:shell/navigate-to-jump-to] 500))
|
||||||
:customization-color customization-color
|
:customization-color customization-color
|
||||||
:label (i18n/label :t/jump-to)}}
|
:label (i18n/label :t/jump-to)}}
|
||||||
{:position :absolute
|
{:position :absolute
|
||||||
|
@ -22,15 +22,15 @@
|
|||||||
(clear event-key)
|
(clear event-key)
|
||||||
(swap! timeout assoc event-key (js/setTimeout #(re-frame/dispatch event) duration-ms))))
|
(swap! timeout assoc event-key (js/setTimeout #(re-frame/dispatch event) duration-ms))))
|
||||||
|
|
||||||
(def chill (atom {}))
|
(def throttle (atom {}))
|
||||||
|
|
||||||
(defn dispatch-and-chill
|
(defn throttle-and-dispatch
|
||||||
"Dispatches event and ignores subsequent calls for the duration of `duration-ms`."
|
"Dispatches event and ignores subsequent calls for the duration of `duration-ms`."
|
||||||
[event duration-ms]
|
[event duration-ms]
|
||||||
(let [event-key (first event)]
|
(let [event-key (first event)]
|
||||||
(when-not (get @chill event-key)
|
(when-not (get @throttle event-key)
|
||||||
(swap! chill assoc event-key true)
|
(swap! throttle assoc event-key true)
|
||||||
(js/setTimeout #(swap! chill assoc event-key false) duration-ms)
|
(js/setTimeout #(swap! throttle dissoc event-key) duration-ms)
|
||||||
(re-frame/dispatch event))))
|
(re-frame/dispatch event))))
|
||||||
|
|
||||||
(defn debounce
|
(defn debounce
|
||||||
|
Loading…
x
Reference in New Issue
Block a user