Skip to content

Commit 5822151

Browse files
committed
feat: customization-color for initial avatar
status-im/status-go@00f50a4...96f0490 Signed-off-by: yqrashawn <[email protected]>
1 parent daa88a2 commit 5822151

File tree

6 files changed

+79
-66
lines changed

6 files changed

+79
-66
lines changed

src/quo/components/avatars/user_avatar/view.cljs

+7-8
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@
1111
utils.string))
1212

1313
(defn initials-avatar
14-
[{:keys [full-name size customization-color theme]}]
14+
[{:keys [full-name size customization-color theme]
15+
:or {customization-color :blue}}]
1516
(let [font-size (get-in style/sizes [size :font-size])
1617
amount-initials (if (#{:xs :xxs :xxxs} size) 1 2)]
1718
[rn/view
@@ -30,13 +31,12 @@
3031
When calling the `profile-picture-fn` and passing the `:ring?` key, be aware that the `profile-picture-fn`
3132
may have an `:override-ring?` value. If it does then the `:ring?` value will not be used.
3233
For reference, refer to the `utils.image-server` namespace for these `profile-picture-fn` are generated."
33-
[{:keys [full-name size profile-picture customization-color static?
34+
[{:keys [full-name size profile-picture static?
3435
status-indicator? online? ring? theme]
35-
:or {size :big
36-
status-indicator? true
37-
online? true
38-
ring? true
39-
customization-color :blue}
36+
:or {size :big
37+
status-indicator? true
38+
online? true
39+
ring? true}
4040
:as props}]
4141
(let [full-name (or full-name "Your Name")
4242
;; image generated with `profile-picture-fn` is round cropped
@@ -76,7 +76,6 @@
7676
(:status-indicator-center-to-edge sizes))
7777
:indicator-color indicator-color
7878
:override-theme theme
79-
:background-color (style/customization-color customization-color theme)
8079
:color (:color style/initials-avatar-text)
8180
:size (:width outer-styles)
8281
:ring? ring?

src/schema/quo.cljs

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
(ns schema.quo
22
(:require
3+
[quo.foundations.colors :as colors]
34
[schema.registry :as registry]))
45

56
(def ^:private ?profile-picture-fn-params
@@ -23,6 +24,9 @@
2324
[:map
2425
[:fn [:=> [:cat ?profile-picture-fn-params] :string]]]])
2526

27+
(def ^:private ?customization-color (into [:enum] colors/account-colors))
28+
2629
(defn register-schemas
2730
[]
28-
(registry/register ::profile-picture-source ?profile-picture-source))
31+
(registry/register ::profile-picture-source ?profile-picture-source)
32+
(registry/register ::customization-color ?customization-color))

src/status_im/subs/contact.cljs

+9-8
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
(defn- replace-contact-image-uri
3636
[contact port public-key font-file]
3737
(let [theme (theme/get-theme)
38-
{:keys [images ens-name]} contact
38+
{:keys [images ens-name customization-color]} contact
3939
images
4040
(reduce (fn [acc image]
4141
(let [image-name (:type image)
@@ -63,13 +63,14 @@
6363
images
6464
{:thumbnail
6565
{:fn (image-server/get-initials-avatar-uri-fn
66-
{:port port
67-
:ratio pixel-ratio/ratio
68-
:public-key public-key
69-
:override-ring? (when ens-name false)
70-
:uppercase-ratio (:uppercase-ratio constants/initials-avatar-font-conf)
71-
:theme theme
72-
:font-file font-file})}})]
66+
{:port port
67+
:ratio pixel-ratio/ratio
68+
:public-key public-key
69+
:override-ring? (when ens-name false)
70+
:uppercase-ratio (:uppercase-ratio constants/initials-avatar-font-conf)
71+
:customization-color customization-color
72+
:theme theme
73+
:font-file font-file})}})]
7374

7475
(assoc contact :images images)))
7576

src/status_im/subs/profile.cljs

+40-37
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,9 @@
6060
:<- [:mediaserver/port]
6161
:<- [:initials-avatar-font-file]
6262
(fn [[profiles port font-file] [_ target-key-uid]]
63-
(let [{:keys [images ens-name?] :as profile} (get profiles target-key-uid)
64-
image-name (-> images first :type)
65-
override-ring? (when ens-name? false)]
63+
(let [{:keys [images ens-name? customization-color] :as profile} (get profiles target-key-uid)
64+
image-name (-> images first :type)
65+
override-ring? (when ens-name? false)]
6666
(when profile
6767
{:fn
6868
(if image-name
@@ -73,13 +73,14 @@
7373
:theme (theme/get-theme)
7474
:override-ring? override-ring?})
7575
(image-server/get-initials-avatar-uri-fn
76-
{:port port
77-
:ratio pixel-ratio/ratio
78-
:key-uid target-key-uid
79-
:theme (theme/get-theme)
80-
:uppercase-ratio (:uppercase-ratio constants/initials-avatar-font-conf)
81-
:override-ring? override-ring?
82-
:font-file font-file}))}))))
76+
{:port port
77+
:ratio pixel-ratio/ratio
78+
:key-uid target-key-uid
79+
:theme (theme/get-theme)
80+
:uppercase-ratio (:uppercase-ratio constants/initials-avatar-font-conf)
81+
:customization-color customization-color
82+
:override-ring? override-ring?
83+
:font-file font-file}))}))))
8384

8485
(re-frame/reg-sub
8586
:multiaccount/public-key
@@ -298,33 +299,35 @@
298299

299300
(defn- replace-multiaccount-image-uri
300301
[profile ens-names port font-file avatar-opts]
301-
(let [{:keys [key-uid ens-name? images]} profile
302-
ens-name? (or ens-name? (seq ens-names))
303-
theme (theme/get-theme)
304-
avatar-opts (assoc avatar-opts :override-ring? (when ens-name? false))
305-
images-with-uri (mapv (fn [{key-uid :keyUid image-name :type :as image}]
306-
(let [uri-fn (image-server/get-account-image-uri-fn
307-
(merge
308-
{:port port
309-
:ratio pixel-ratio/ratio
310-
:image-name image-name
311-
:key-uid key-uid
312-
:theme theme}
313-
avatar-opts))]
314-
(assoc image :fn uri-fn)))
315-
images)
316-
new-images (if (seq images-with-uri)
317-
images-with-uri
318-
[{:fn (image-server/get-initials-avatar-uri-fn
319-
(merge {:port port
320-
:ratio pixel-ratio/ratio
321-
:uppercase-ratio
322-
(:uppercase-ratio
323-
constants/initials-avatar-font-conf)
324-
:key-uid key-uid
325-
:theme theme
326-
:font-file font-file}
327-
avatar-opts))}])]
302+
(let [{:keys [key-uid ens-name? images
303+
customization-color]} profile
304+
ens-name? (or ens-name? (seq ens-names))
305+
theme (theme/get-theme)
306+
avatar-opts (assoc avatar-opts :override-ring? (when ens-name? false))
307+
images-with-uri (mapv (fn [{key-uid :keyUid image-name :type :as image}]
308+
(let [uri-fn (image-server/get-account-image-uri-fn
309+
(merge
310+
{:port port
311+
:ratio pixel-ratio/ratio
312+
:image-name image-name
313+
:key-uid key-uid
314+
:theme theme}
315+
avatar-opts))]
316+
(assoc image :fn uri-fn)))
317+
images)
318+
new-images (if (seq images-with-uri)
319+
images-with-uri
320+
[{:fn (image-server/get-initials-avatar-uri-fn
321+
(merge {:port port
322+
:ratio pixel-ratio/ratio
323+
:uppercase-ratio
324+
(:uppercase-ratio
325+
constants/initials-avatar-font-conf)
326+
:key-uid key-uid
327+
:customization-color customization-color
328+
:theme theme
329+
:font-file font-file}
330+
avatar-opts))}])]
328331
(assoc profile :images new-images)))
329332

330333
(re-frame/reg-sub

src/utils/image_server.cljs

+14-10
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
(ns utils.image-server
22
(:require
3+
[quo.foundations.colors :as colors]
34
[react-native.fs :as utils.fs]
45
[react-native.platform :as platform]
56
[schema.core :as schema]
@@ -139,9 +140,10 @@
139140
check `get-font-file-ready` for `font-file`
140141
141142
`uppercase-ratio` is the uppercase-height/line-height for `font-file`"
142-
[{:keys [port public-key key-uid theme ring? length size background-color color
143-
font-size font-file uppercase-ratio indicator-size indicator-border
144-
indicator-center-to-edge indicator-color full-name ring-width ratio]}]
143+
[{:keys [port public-key key-uid theme ring? length size customization-color
144+
color font-size font-file uppercase-ratio indicator-size
145+
indicator-border indicator-center-to-edge indicator-color full-name
146+
ring-width ratio]}]
145147
(str
146148
image-server-uri-prefix
147149
port
@@ -155,7 +157,7 @@
155157
"&size="
156158
(Math/round (* size ratio))
157159
"&bgColor="
158-
(js/encodeURIComponent background-color)
160+
(js/encodeURIComponent (colors/resolve-color customization-color theme))
159161
"&color="
160162
(js/encodeURIComponent color)
161163
"&fontSize="
@@ -188,10 +190,11 @@
188190
[:cat
189191
[:map
190192
[:color string?]
191-
[:background-color string?]
193+
[:theme :schema.common/theme]
192194
[:size number?]
193195
[:ratio float?]
194196
[:uppercase-ratio number?]
197+
[:customization-color :schema.quo/customization-color]
195198
[:font-size number?]
196199
[:font-file string?]]]
197200
[:string]])
@@ -204,10 +207,11 @@
204207
check `get-font-file-ready` for `font-file`
205208
206209
check `get-account-image-uri-fn` for `override-ring?`"
207-
[{:keys [port public-key key-uid theme override-ring? font-file ratio uppercase-ratio]}]
208-
(fn [{:keys [full-name length size background-color font-size color
209-
indicator-size indicator-border indicator-color indicator-center-to-edge
210-
ring? ring-width override-theme]}]
210+
[{:keys [port public-key key-uid theme override-ring? font-file ratio
211+
uppercase-ratio customization-color]}]
212+
(fn [{:keys [full-name length size font-size color indicator-size indicator-border
213+
indicator-color indicator-center-to-edge ring? ring-width
214+
override-theme]}]
211215
(get-initials-avatar-uri
212216
{:port port
213217
:public-key public-key
@@ -216,7 +220,7 @@
216220
:full-name full-name
217221
:length length
218222
:size size
219-
:background-color background-color
223+
:customization-color customization-color
220224
:theme (if (nil? override-theme) theme override-theme)
221225
:ring? (if (nil? override-ring?) ring? override-ring?)
222226
:ring-width ring-width

src/utils/image_server_test.cljs

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
(ns utils.image-server-test
22
(:require
33
[cljs.test :as t]
4+
[quo.foundations.colors :as colors]
45
[utils.image-server :as sut]))
56

67
(t/deftest get-account-image-uri
@@ -25,6 +26,7 @@
2526
(t/deftest get-account-initials-uri
2627
(with-redefs
2728
[sut/current-theme-index identity
29+
colors/resolve-color str
2830
sut/timestamp (constantly "timestamp")]
2931
(t/is
3032
(=
@@ -38,7 +40,7 @@
3840
:size 48
3941
:theme :light
4042
:ring? "ring?"
41-
:background-color "background-color"
43+
:customization-color :blue
4244
:color "#0E162000"
4345
:font-size 12
4446
:font-file "/font/Inter Medium.otf"
@@ -47,4 +49,4 @@
4749
:indicator-center-to-edge 6
4850
:indicator-color "#0E1620"
4951
:ring-width 4})
50-
"https://localhost:port/accountInitials?publicKey=public-key&keyUid=key-uid&length=length&size=96&bgColor=background-color&color=%230E162000&fontSize=24&fontFile=%2Ffont%2FInter%20Medium.otf&uppercaseRatio=0.6&theme=:light&clock=&name=full-nametimestamp&indicatorColor=%230E1620&indicatorSize=4&indicatorBorder=0&indicatorCenterToEdge=12&addRing=1&ringWidth=8"))))
52+
"https://localhost:port/accountInitials?publicKey=public-key&keyUid=key-uid&length=length&size=96&bgColor=%3Ablue%3Alight&color=%230E162000&fontSize=24&fontFile=%2Ffont%2FInter%20Medium.otf&uppercaseRatio=0.6&theme=:light&clock=&name=full-nametimestamp&indicatorColor=%230E1620&indicatorSize=4&indicatorBorder=0&indicatorCenterToEdge=12&addRing=1&ringWidth=8"))))

0 commit comments

Comments
 (0)