|
10 | 10 | [status-im.privacy-policy.core :as privacy-policy]
|
11 | 11 | [status-im.ui.components.colors :as colors]))
|
12 | 12 |
|
| 13 | +(defonce index (reagent/atom 0)) |
| 14 | + |
13 | 15 | (defn code [val]
|
14 | 16 | ^{:key val}
|
15 | 17 | [animated/code {:exec val}])
|
|
22 | 24 | [code (animated/set active (if selected 1 0))]
|
23 | 25 | [animated/view {:style (styles/dot-progress active-transition progress)}]])))
|
24 | 26 |
|
25 |
| -(defn dots-selector [{:keys [n selected progress]}] |
26 |
| - [react/view {:style (styles/dot-selector)} |
27 |
| - (for [i (range n)] |
28 |
| - ^{:key i} |
29 |
| - [dot {:progress progress |
30 |
| - :selected (= selected i)}])]) |
| 27 | +(defn dots-selector [{:keys [n progress]}] |
| 28 | + (let [selected @index] |
| 29 | + [react/view {:style (styles/dot-selector)} |
| 30 | + (for [i (range n)] |
| 31 | + ^{:key i} |
| 32 | + [dot {:progress progress |
| 33 | + :selected (= selected i)}])])) |
| 34 | + |
| 35 | +(defn slides-view [slides width] |
| 36 | + (let [height (reagent/atom 0) |
| 37 | + text-height (reagent/atom 0) |
| 38 | + text-temp-height (atom 0) |
| 39 | + text-temp-timer (atom nil)] |
| 40 | + (fn [_] |
| 41 | + [:<> |
| 42 | + (doall |
| 43 | + (for [s slides] |
| 44 | + ^{:key (:title s)} |
| 45 | + [react/view {:style {:flex 1 |
| 46 | + :width width |
| 47 | + :justify-content :flex-end |
| 48 | + :align-items :center |
| 49 | + :padding-horizontal 32}} |
| 50 | + (let [size (min width @height)] |
| 51 | + [react/view {:style {:flex 1} |
| 52 | + :on-layout (fn [^js e] |
| 53 | + (let [new-height (-> e .-nativeEvent .-layout .-height)] |
| 54 | + (swap! height #(if (pos? %) (min % new-height) new-height))))} |
| 55 | + [react/image {:source (:image s) |
| 56 | + :resize-mode :contain |
| 57 | + :style {:width size |
| 58 | + :height size}}]]) |
| 59 | + [quo/text {:style styles/wizard-title |
| 60 | + :align :center |
| 61 | + :weight :bold |
| 62 | + :size :x-large} |
| 63 | + (i18n/label (:title s))] |
| 64 | + [quo/text {:style (styles/wizard-text-with-height @text-height) |
| 65 | + :on-layout |
| 66 | + (fn [^js e] |
| 67 | + (let [new-height (-> e .-nativeEvent .-layout .-height)] |
| 68 | + (when (and (not= new-height @text-temp-height) |
| 69 | + (not (zero? new-height)) |
| 70 | + (< new-height 200)) |
| 71 | + (swap! text-temp-height #(if (pos? %) (max % new-height) new-height)) |
| 72 | + (when @text-temp-timer (js/clearTimeout @text-temp-timer)) |
| 73 | + (reset! text-temp-timer |
| 74 | + (js/setTimeout #(reset! text-height @text-temp-height) 500)))))} |
| 75 | + (i18n/label (:text s))]]))]))) |
31 | 76 |
|
32 |
| -(defn carousel [slides] |
| 77 | +(defn carousel [slides width] |
33 | 78 | ;;TODO this is really not the best implementation, must be a better way
|
34 | 79 | (let [scroll-x (reagent/atom 0)
|
35 | 80 | scroll-view-ref (atom nil)
|
36 |
| - width (reagent/atom 0) |
37 |
| - height (reagent/atom 0) |
38 |
| - text-height (reagent/atom 0) |
39 |
| - index (reagent/atom 0) |
| 81 | + |
40 | 82 | manual-scroll (atom false)
|
41 |
| - text-temp-height (atom 0) |
42 |
| - text-temp-timer (atom nil) |
43 | 83 | progress (animated/value 1)
|
44 | 84 | autoscroll (animated/value 1)
|
45 | 85 | finished (animated/value 0)
|
46 | 86 | clock (animated/clock)
|
47 | 87 | go-next (fn []
|
48 | 88 | (let [x (if (>= @scroll-x (* (dec (count slides))
|
49 |
| - @width)) |
| 89 | + width)) |
50 | 90 | 0
|
51 |
| - (+ @scroll-x @width))] |
52 |
| - (reset! index (Math/round (/ x @width))) |
| 91 | + (+ @scroll-x width))] |
| 92 | + (reset! index (Math/round (/ x width))) |
53 | 93 | (some-> ^js @scroll-view-ref (.scrollTo #js {:x x :animated true}))))
|
54 | 94 | code (animated/block
|
55 | 95 | [(animated/cond* (animated/and* (animated/not* (animated/clock-running clock))
|
|
72 | 112 | (fn [_ _]
|
73 | 113 | [react/view {:style {:align-items :center
|
74 | 114 | :flex 1
|
75 |
| - :justify-content :flex-end} |
76 |
| - :on-layout (fn [^js e] |
77 |
| - (reset! width (-> e .-nativeEvent .-layout .-width)))} |
| 115 | + :justify-content :flex-end}} |
78 | 116 | [animated/code {:exec code}]
|
79 | 117 | [react/scroll-view {:horizontal true
|
80 | 118 | :paging-enabled true
|
|
86 | 124 | :on-scroll #(let [x (.-nativeEvent.contentOffset.x ^js %)]
|
87 | 125 | (when @manual-scroll
|
88 | 126 | ;; NOTE: Will be not synced if velocity is big
|
89 |
| - (reset! index (Math/round (/ x @width)))) |
| 127 | + (reset! index (Math/round (/ x width)))) |
90 | 128 | (reset! scroll-x x))
|
91 | 129 | :on-scroll-begin-drag cancel-animation
|
92 | 130 | :on-scroll-end-drag restart-animation
|
93 | 131 | :on-momentum-scroll-end #(reset! manual-scroll false)
|
94 | 132 | :style {:margin-bottom 16}}
|
95 |
| - (doall |
96 |
| - (for [s slides] |
97 |
| - ^{:key (:title s)} |
98 |
| - [react/view {:style {:flex 1 |
99 |
| - :width @width |
100 |
| - :justify-content :flex-end |
101 |
| - :align-items :center |
102 |
| - :padding-horizontal 32}} |
103 |
| - (let [size (min @width @height)] |
104 |
| - [react/view {:style {:flex 1} |
105 |
| - :on-layout (fn [^js e] |
106 |
| - (let [new-height (-> e .-nativeEvent .-layout .-height)] |
107 |
| - (swap! height #(if (pos? %) (min % new-height) new-height))))} |
108 |
| - [react/image {:source (:image s) |
109 |
| - :resize-mode :contain |
110 |
| - :style {:width size |
111 |
| - :height size}}]]) |
112 |
| - [react/text {:style styles/wizard-title |
113 |
| - :align :center |
114 |
| - :weight :bold |
115 |
| - :size :x-large} |
116 |
| - (i18n/label (:title s))] |
117 |
| - [react/text {:style (styles/wizard-text-with-height @text-height) |
118 |
| - :on-layout |
119 |
| - (fn [^js e] |
120 |
| - (let [new-height (-> e .-nativeEvent .-layout .-height)] |
121 |
| - (when (and (not= new-height @text-temp-height) |
122 |
| - (not (zero? new-height)) |
123 |
| - (< new-height 200)) |
124 |
| - (swap! text-temp-height #(if (pos? %) (max % new-height) new-height)) |
125 |
| - (when @text-temp-timer (js/clearTimeout @text-temp-timer)) |
126 |
| - (reset! text-temp-timer |
127 |
| - (js/setTimeout #(reset! text-height @text-temp-height) 500)))))} |
128 |
| - (i18n/label (:text s))]]))] |
129 |
| - [dots-selector {:selected @index |
130 |
| - :progress progress |
| 133 | + [slides-view slides width]] |
| 134 | + [dots-selector {:progress progress |
131 | 135 | :n (count slides)}]])))
|
132 | 136 |
|
133 | 137 | (defn intro []
|
|
140 | 144 | :text :intro-text2}
|
141 | 145 | {:image (resources/get-theme-image :browser)
|
142 | 146 | :title :intro-title3
|
143 |
| - :text :intro-text3}]] |
| 147 | + :text :intro-text3}] |
| 148 | + @(re-frame/subscribe [:dimensions/window-width])] |
144 | 149 | [react/view styles/buttons-container
|
145 | 150 | [react/view {:style (assoc styles/bottom-button :margin-bottom 16)}
|
146 | 151 | [quo/button {:on-press #(re-frame/dispatch [:init-onboarding])}
|
|
0 commit comments