2016-05-19 18:31:56 +02:00
|
|
|
(ns status-im.utils.utils
|
2018-03-16 18:50:17 +01:00
|
|
|
(:require [status-im.i18n :as i18n]
|
2018-05-18 02:30:33 +02:00
|
|
|
[status-im.react-native.js-dependencies :as rn-dependencies]
|
|
|
|
[re-frame.core :as re-frame]))
|
2016-03-27 17:59:03 +03:00
|
|
|
|
2018-04-25 21:37:32 -07:00
|
|
|
(defn show-popup
|
|
|
|
([title content]
|
2018-05-07 17:09:06 +03:00
|
|
|
(show-popup title content nil))
|
2018-04-25 21:37:32 -07:00
|
|
|
([title content on-dismiss]
|
2018-05-07 17:09:06 +03:00
|
|
|
(.alert (.-Alert rn-dependencies/react-native)
|
|
|
|
title
|
|
|
|
content
|
|
|
|
(clj->js
|
|
|
|
(vector (merge {:text "OK"
|
|
|
|
:style "cancel"
|
|
|
|
:accessibility-label :cancel-button}
|
|
|
|
(when on-dismiss {:onPress on-dismiss}))))
|
|
|
|
(when on-dismiss
|
|
|
|
(clj->js {:cancelable false})))))
|
2016-03-27 17:59:03 +03:00
|
|
|
|
2017-05-13 00:44:17 +02:00
|
|
|
(defn show-confirmation
|
|
|
|
([title content on-accept]
|
|
|
|
(show-confirmation title content nil on-accept))
|
2017-10-05 13:23:25 +02:00
|
|
|
([title content confirm-button-text on-accept]
|
|
|
|
(show-confirmation title content confirm-button-text on-accept nil))
|
|
|
|
([title content confirm-button-text on-accept on-cancel]
|
2018-05-11 09:54:18 +01:00
|
|
|
(show-confirmation nil title content confirm-button-text on-accept on-cancel))
|
2018-07-18 16:48:08 +03:00
|
|
|
([ios-style title content confirm-button-text on-accept on-cancel]
|
|
|
|
(show-confirmation ios-style title content confirm-button-text on-accept on-cancel nil))
|
|
|
|
([{:keys [ios-confirm-style] :or {ios-confirm-style "destructive"}}
|
|
|
|
title content confirm-button-text on-accept on-cancel cancel-button-text]
|
2017-07-16 12:04:35 +03:00
|
|
|
(.alert (.-Alert rn-dependencies/react-native)
|
2017-05-13 00:44:17 +02:00
|
|
|
title
|
|
|
|
content
|
2017-07-20 13:59:57 +02:00
|
|
|
;; Styles are only relevant on iOS. On Android first button is 'neutral' and second is 'positive'
|
2017-05-13 00:44:17 +02:00
|
|
|
(clj->js
|
2018-07-18 16:48:08 +03:00
|
|
|
(vector (merge {:text (or cancel-button-text (i18n/label :t/cancel))
|
2018-03-04 10:56:39 +08:00
|
|
|
:style "cancel"
|
|
|
|
:accessibility-label :cancel-button}
|
2017-07-20 13:59:57 +02:00
|
|
|
(when on-cancel {:onPress on-cancel}))
|
2018-03-04 10:56:39 +08:00
|
|
|
{:text (or confirm-button-text "OK")
|
|
|
|
:onPress on-accept
|
2018-05-11 09:54:18 +01:00
|
|
|
:style ios-confirm-style
|
2018-03-04 10:56:39 +08:00
|
|
|
:accessibility-label :confirm-button})))))
|
2017-05-13 00:44:17 +02:00
|
|
|
|
2017-09-27 13:40:50 +03:00
|
|
|
(defn show-question
|
|
|
|
([title content on-accept]
|
|
|
|
(show-question title content on-accept nil))
|
|
|
|
([title content on-accept on-cancel]
|
|
|
|
(.alert (.-Alert rn-dependencies/react-native)
|
|
|
|
title
|
|
|
|
content
|
|
|
|
(clj->js
|
2018-03-04 10:56:39 +08:00
|
|
|
(vector (merge {:text (i18n/label :t/no)
|
|
|
|
:accessibility-label :no-button}
|
2017-10-25 17:33:46 +02:00
|
|
|
(when on-cancel {:onPress on-cancel}))
|
2018-03-04 10:56:39 +08:00
|
|
|
{:text (i18n/label :t/yes)
|
|
|
|
:onPress on-accept
|
|
|
|
:accessibility-label :yes-button})))))
|
2017-09-27 13:40:50 +03:00
|
|
|
|
2017-12-30 12:35:25 +08:00
|
|
|
;; background-timer
|
|
|
|
|
|
|
|
(defn set-timeout [cb ms]
|
|
|
|
(.setTimeout rn-dependencies/background-timer cb ms))
|
|
|
|
|
2018-05-18 02:30:33 +02:00
|
|
|
;; same as re-frame dispatch-later but using background timer for long
|
|
|
|
;; running timeouts
|
|
|
|
(re-frame/reg-fx
|
|
|
|
:utils/dispatch-later
|
|
|
|
(fn [params]
|
|
|
|
(doseq [{:keys [ms dispatch]} params]
|
|
|
|
(set-timeout #(re-frame/dispatch dispatch) ms))))
|
|
|
|
|
2017-12-30 12:35:25 +08:00
|
|
|
(defn clear-timeout [id]
|
|
|
|
(.clearTimeout rn-dependencies/background-timer id))
|
|
|
|
|
|
|
|
(defn set-interval [cb ms]
|
|
|
|
(.setInterval rn-dependencies/background-timer cb ms))
|
|
|
|
|
|
|
|
(defn clear-interval [id]
|
|
|
|
(.clearInterval rn-dependencies/background-timer id))
|