Skip to content

Commit db4f89e

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

File tree

6 files changed

+77
-66
lines changed

6 files changed

+77
-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
@@ -292,33 +293,35 @@
292293

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

324327
(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

status-go-version.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,6 @@
44
"owner": "status-im",
55
"repo": "status-go",
66
"version": "feat/contact-customization-color",
7-
"commit-sha1": "fa9178e9d53ba71c9872a59afa7afe99cf56ac38",
8-
"src-sha256": "1f3ji1vs89xh4ada9wahcl3ijskcv7y4i4fsfvcsy3japhrkmlbj"
7+
"commit-sha1": "96f04905371f16333b477225c4169c55a5f74a59",
8+
"src-sha256": "08klqpdqh1ikrp3zcxls0va1nrbgy0id7414isp57lbrhi330gkm"
99
}

0 commit comments

Comments
 (0)