|
| 1 | +(ns quo.components.list-items.market-token.view |
| 2 | + (:require |
| 3 | + [clojure.string :as string] |
| 4 | + [quo.components.counter.counter.view :as counter] |
| 5 | + [quo.components.icon :as icon] |
| 6 | + [quo.components.list-items.market-token.schema :as component-schema] |
| 7 | + [quo.components.list-items.market-token.style :as style] |
| 8 | + [quo.components.markdown.text :as text] |
| 9 | + [quo.components.utilities.token.view :as token] |
| 10 | + [quo.context :as quo.context] |
| 11 | + [react-native.core :as rn] |
| 12 | + [schema.core :as schema])) |
| 13 | + |
| 14 | +(defn- internal-view |
| 15 | + [{:keys [token token-name token-rank market-cap price percentage-change customization-color |
| 16 | + on-press on-long-press]}] |
| 17 | + (let [theme (quo.context/use-theme) |
| 18 | + [state set-state] (rn/use-state :default) |
| 19 | + bg-opacity (case state |
| 20 | + :active 10 |
| 21 | + :pressed 5 |
| 22 | + 0) |
| 23 | + on-press-in (rn/use-callback #(set-state :pressed)) |
| 24 | + on-press-out (rn/use-callback #(set-state :default)) |
| 25 | + on-press (rn/use-callback |
| 26 | + (fn [] |
| 27 | + (set-state :active) |
| 28 | + (js/setTimeout #(set-state :default) 300) |
| 29 | + on-press)) |
| 30 | + token-short-name (if token (string/upper-case (clj->js token)) "")] |
| 31 | + [rn/pressable |
| 32 | + {:style (style/container customization-color bg-opacity theme) |
| 33 | + :on-press-in on-press-in |
| 34 | + :on-press-out on-press-out |
| 35 | + :on-press on-press |
| 36 | + :on-long-press on-long-press |
| 37 | + :accessibility-label :market-token-container} |
| 38 | + [rn/view |
| 39 | + {:style style/left-side} |
| 40 | + [counter/view |
| 41 | + {:type :outline |
| 42 | + :max-value 99999 |
| 43 | + :container-style {:margin-right 8}} |
| 44 | + token-rank] |
| 45 | + [token/view {:token token :size :size-32}] |
| 46 | + [rn/view style/left-text-block |
| 47 | + [rn/text |
| 48 | + ;; If we place 2 texts of different styles within parent _view_ component they won't be |
| 49 | + ;; aligned to the same baseline. So they should be a children of the same _text_ component |
| 50 | + ;; to share same basline and look nice. But that means we can't use precise margins anymore |
| 51 | + ;; and have to rely on whitespaces to split 2 texts. |
| 52 | + [text/text style/token-name (str token-name " ")] |
| 53 | + [text/text |
| 54 | + {:weight :medium |
| 55 | + :size :paragraph-2 |
| 56 | + :style (style/token-short-name theme)} token-short-name]] |
| 57 | + [text/text |
| 58 | + {:size :paragraph-2 |
| 59 | + :style (style/market-cap theme)} |
| 60 | + market-cap]]] |
| 61 | + [rn/view |
| 62 | + {:style style/right-side} |
| 63 | + [text/text |
| 64 | + {:weight :medium |
| 65 | + :size :paragraph-2} price] |
| 66 | + (when percentage-change |
| 67 | + [rn/view |
| 68 | + {:style style/percentage-container} |
| 69 | + [text/text |
| 70 | + {:size :paragraph-2 |
| 71 | + :style (style/percentage-text percentage-change theme)} |
| 72 | + (str percentage-change "%")] |
| 73 | + [rn/view |
| 74 | + {:style style/arrow |
| 75 | + :accessibility-label :arrow-icon} |
| 76 | + [icon/icon (if (pos? percentage-change) :i/positive :i/negative) |
| 77 | + (style/arrow-icon percentage-change theme)]]])]])) |
| 78 | + |
| 79 | +(def view (schema/instrument #'internal-view component-schema/?schema)) |
0 commit comments