|
1 | 1 | (ns quo.components.tags.collectible-tag.view
|
2 | 2 | (:require
|
| 3 | + [oops.core :as oops] |
3 | 4 | [quo.components.icon :as icons]
|
4 | 5 | [quo.components.markdown.text :as text]
|
| 6 | + [quo.components.tags.collectible-tag.schema :as component-schema] |
5 | 7 | [quo.components.tags.collectible-tag.style :as style]
|
6 | 8 | [quo.theme]
|
7 | 9 | [react-native.core :as rn]
|
8 | 10 | [react-native.hole-view :as hole-view]
|
| 11 | + [reagent.core :as reagent] |
9 | 12 | [schema.core :as schema]))
|
10 | 13 |
|
11 |
| -(def ?schema |
12 |
| - [:=> |
13 |
| - [:catn |
14 |
| - [:props |
15 |
| - [:map {:closed true} |
16 |
| - [:options {:optional true} [:maybe [:enum false :add :hold]]] |
17 |
| - [:size {:optional true} [:enum :size-24 :size-32]] |
18 |
| - [:blur? {:optional true} :boolean] |
19 |
| - [:theme :schema.common/theme] |
20 |
| - [:collectible-img-src [:or :int :string]] |
21 |
| - [:collectible-name :string] |
22 |
| - [:collectible-id :string] |
23 |
| - [:container-width :number] |
24 |
| - [:on-layout {:optional true} [:maybe fn?]]]]] |
25 |
| - :any]) |
26 |
| - |
27 | 14 | (defn- view-internal
|
28 | 15 | []
|
29 |
| - (fn [{:keys [options size blur? theme collectible-img-src collectible-name collectible-id |
30 |
| - container-width on-layout] |
31 |
| - :or {size :size-24}}] |
32 |
| - [rn/view |
33 |
| - {:on-layout on-layout} |
34 |
| - [hole-view/hole-view |
35 |
| - {:holes (if options |
36 |
| - [{:x (- container-width |
37 |
| - (case size |
38 |
| - :size-24 10 |
39 |
| - :size-32 12 |
40 |
| - nil)) |
41 |
| - :y (case size |
42 |
| - :size-24 -6 |
43 |
| - :size-32 -4 |
44 |
| - nil) |
45 |
| - :width 16 |
46 |
| - :height 16 |
47 |
| - :borderRadius 8}] |
48 |
| - [])} |
49 |
| - [rn/view {:style (style/container size options blur? theme)} |
50 |
| - [rn/image {:style (style/collectible-img size) :source collectible-img-src}] |
51 |
| - [text/text |
52 |
| - {:size :paragraph-2 |
53 |
| - :weight :medium |
54 |
| - :style (style/label theme)} |
55 |
| - collectible-name] |
56 |
| - [text/text |
57 |
| - {:size :paragraph-2 |
58 |
| - :weight :medium |
59 |
| - :margin-left 5 |
60 |
| - :style (style/label theme)} |
61 |
| - collectible-id]]] |
62 |
| - (when options |
63 |
| - [rn/view {:style (style/options-icon size)} |
64 |
| - [icons/icon (if (= options :hold) :i/hold :i/add-token) |
65 |
| - {:size 20 |
66 |
| - :no-color true}]])])) |
| 16 | + (let [container-width (reagent/atom 0) |
| 17 | + on-layout #(->> (oops/oget % :nativeEvent :layout :width) |
| 18 | + (reset! container-width))] |
| 19 | + (fn [{:keys [options blur? theme collectible-img-src collectible-name collectible-id] :as props}] |
| 20 | + (let [size (or (:size props) :size-24)] |
| 21 | + [rn/view |
| 22 | + {:on-layout on-layout} |
| 23 | + [hole-view/hole-view |
| 24 | + {:holes (if options |
| 25 | + [{:x (- @container-width |
| 26 | + (case size |
| 27 | + :size-24 10 |
| 28 | + :size-32 12 |
| 29 | + nil)) |
| 30 | + :y (case size |
| 31 | + :size-24 -6 |
| 32 | + :size-32 -4 |
| 33 | + nil) |
| 34 | + :width 16 |
| 35 | + :height 16 |
| 36 | + :borderRadius 8}] |
| 37 | + [])} |
| 38 | + [rn/view {:style (style/container size options blur? theme)} |
| 39 | + [rn/image {:style (style/collectible-img size) :source collectible-img-src}] |
| 40 | + [text/text |
| 41 | + {:size :paragraph-2 |
| 42 | + :weight :medium |
| 43 | + :style (style/label theme)} |
| 44 | + collectible-name] |
| 45 | + [text/text |
| 46 | + {:size :paragraph-2 |
| 47 | + :weight :medium |
| 48 | + :margin-left 5 |
| 49 | + :style (style/label theme)} |
| 50 | + collectible-id]]] |
| 51 | + (when options |
| 52 | + [rn/view {:style (style/options-icon size)} |
| 53 | + [icons/icon (if (= options :hold) :i/hold :i/add-token) |
| 54 | + {:size 20 |
| 55 | + :no-color true}]])])))) |
67 | 56 |
|
68 | 57 | (def view
|
69 | 58 | (quo.theme/with-theme
|
70 |
| - (schema/instrument #'view-internal ?schema))) |
| 59 | + (schema/instrument #'view-internal component-schema/?schema))) |
0 commit comments