|
24 | 24 | (defn make-app []
|
25 | 25 | (material-app
|
26 | 26 | {:title "Expandable Fab/MX"
|
| 27 | + :theme (.dark m/ThemeData) ;;(m/ThemeData. :primarySwatch m.Colors/pink) |
27 | 28 | :debugShowCheckedModeBanner false}
|
28 | 29 | {:name :mat-app}
|
29 | 30 |
|
|
47 | 48 | (defn expandable-fab [& {:keys [initial-open? distance actions] :or [initial-open? false]}]
|
48 | 49 | (fx/sized-box+expand
|
49 | 50 | {:initState (fn [this me]
|
| 51 | + (dp :all-new-fab!) |
50 | 52 | (let [c (util/rmap-meta-setf [:controller me]
|
51 | 53 | (m/AnimationController
|
52 | 54 | :value (if initial-open? 1.0 0.0)
|
53 | 55 | :duration ^:const (dart:core/Duration :milliseconds 250)
|
54 | 56 | :vsync this))]
|
55 |
| - ;; todo can we just make a Ticker instead of using the state mixin |
56 | 57 | (util/rmap-meta-setf [:expand-animation me]
|
57 | 58 | (m/CurvedAnimation
|
58 | 59 | :curve m.Curves/fastOutSlowIn
|
59 | 60 | :reverseCurve m.Curves/easeOutQuad
|
60 |
| - :parent c))))} |
| 61 | + :parent c)))) |
| 62 | + :dispose (fn [this me] |
| 63 | + (when-let [controller (:controller (meta me))] |
| 64 | + (.dispose controller)))} |
61 | 65 | {:name :fab
|
62 | 66 | :step (cF (/ 90.0 (dec (count actions))))
|
63 | 67 | :open? (cI initial-open?
|
|
71 | 75 | :clipBehavior m.Clip/none}
|
72 | 76 | (tap-to-close-fab me)
|
73 | 77 | ;; Matrix always flattens children, and discards nils, so we can offer a collection mid-children
|
74 |
| - (doall (map-indexed |
75 |
| - (fn [i action] |
76 |
| - (expanding-action-button me |
77 |
| - :direction-degrees (* i (fmuv :step :fab)) |
78 |
| - :max-distance distance |
79 |
| - :progress-key :expand-animation |
80 |
| - :action action)) |
81 |
| - actions)) |
| 78 | + (doall (do (dp :rebuilding-actions!!) |
| 79 | + (map-indexed |
| 80 | + (fn [i action] |
| 81 | + (expanding-action-button me |
| 82 | + :direction-degrees (* i (fmuv :step :fab)) |
| 83 | + :max-distance distance |
| 84 | + :progress-key :expand-animation |
| 85 | + :action action)) |
| 86 | + actions))) |
82 | 87 | (tap-to-open-fab me))))
|
83 | 88 |
|
84 | 89 | (defn expanding-action-button [me & {:keys [action direction-degrees max-distance progress-key]}]
|
85 |
| - (dp :eab-entry |
86 |
| - ;;:fab (md/fm* :fab) |
87 |
| - :ani-key progress-key ;; :ani (progress-key (meta (md/fm* :fab)) :notfound) |
88 |
| - :ctx! (when-let [^State state (:state-ref (meta me))] |
89 |
| - (.context state))) |
| 90 | + #_(dp :eab-entry |
| 91 | + ;;:fab (md/fm* :fab) |
| 92 | + :ani-key progress-key ;; :ani (progress-key (meta (md/fm* :fab)) :notfound) |
| 93 | + :ctx! (when-let [^State state (:state-ref (meta me))] |
| 94 | + (.context state))) |
90 | 95 |
|
91 | 96 | (fx/animated-builder
|
92 |
| - {:animation ;;(cF (progress-key (meta (md/fm* :fab)))) |
93 |
| - (fn [me ctx] |
94 |
| - (progress-key (meta (md/fm* :fab)))) |
| 97 | + {:animation (fn [me ctx] |
| 98 | + (progress-key (meta (md/fm* :fab)))) |
95 | 99 | ;; todo lose "beefer"
|
96 | 100 | :ani-beefer (fn [me ctx child]
|
97 | 101 | (let [fab (md/fm* :fab)
|
|
124 | 128 | (show-action ctx action)
|
125 | 129 | nil))))
|
126 | 130 |
|
127 |
| - (action-button |
| 131 | + (action-button ctx |
128 | 132 | :icon (:icon action)
|
129 | 133 | :onPressed (fn ^void []
|
| 134 | + ;; todo roll up into (with-context (ctx) ....) |
130 | 135 | (let [^State state (:state-ref (meta me))]
|
131 | 136 | (assert state)
|
132 | 137 | (assert (.context state))
|
|
161 | 166 | :onPressed #(-> ctx m.Navigator/of .pop)
|
162 | 167 | :child ^:const (m/Text "CLOSE"))]))))
|
163 | 168 |
|
164 |
| -(defn action-button [& {:keys [onPressed icon]}] |
| 169 | +(defn action-button [ctx & {:keys [onPressed icon]}] |
165 | 170 | (fx/material {:shape ^:const (m/CircleBorder)
|
166 | 171 | :clipBehavior m.Clip/antiAlias
|
167 |
| - :color (fn [me ctx] |
168 |
| - (dp :color-callback!!!!!) |
169 |
| - (-> (Theme/of ctx) .-colorScheme .-secondary)) |
170 |
| - ;; todo avoid callback |
171 |
| - #_(cF (dp :mtlcolor-meta (meta me)) |
172 |
| - |
173 |
| - Colors/red) #_(cF |
174 |
| - (dp :mtlcolor-sees (my-state)) |
175 |
| - |
176 |
| - ;;(-> (Theme/of (my-ctx)) .-colorScheme .-secondary) |
177 |
| - ) |
| 172 | + :color (-> (Theme/of ctx) .-colorScheme .-secondary) |
178 | 173 | :elevation 4.0}
|
179 | 174 | (fx/icon-button
|
180 | 175 | {:onPressed onPressed
|
181 | 176 | :icon icon
|
182 |
| - :color Colors/white ;; todo use theme |
183 |
| - #_(cF (assert (my-ctx)) |
184 |
| - (-> (Theme/of (my-ctx)) .-colorScheme .-onSecondary))}))) |
185 |
| - |
| 177 | + :color (-> (Theme/of ctx) .-colorScheme .-onSecondary)}))) |
186 | 178 |
|
187 | 179 | (defn- tap-to-close-fab [par]
|
188 | 180 | (f/nest
|
|
200 | 192 | (m/Icon m.Icons/close :color m.Colors/blue #_(.primaryColor theme)))) ;; todo use theme
|
201 | 193 |
|
202 | 194 | (defn- tap-to-open-fab [par]
|
| 195 | + (dp :tap-to-open-entry) |
203 | 196 | (f/nest
|
204 | 197 | (m/IgnorePointer :ignoring (boolean (mget (md/fasc :fab par) :open?)))
|
205 | 198 | (m/AnimatedContainer
|
|
0 commit comments