Tweak UI for contact request notifications (#19337)

* fix: ensure contact-request notifications are displayed as notifications

* fix: provide context-theme for notification sub-components

* fix: adjust font weight for notification text

* fix: adjust alignment of user-avatar inside a notification with a header and body

* tidy: rename override-theme to theme inside notifications

* fix: update notifications component to use `user` prop instead of `avatar`

* tweak: adapt notification to avatar to vertically center when only displaying header or title

* fix: use title font-size for contact-request-accepted notification

* fix: allow for custom avatar component prop in quo notification component

* fix: ensure we use the correct font-weight for contact-request-accepted notification

* tidy: fix formatting
This commit is contained in:
Sean Hagstrom 2024-03-25 10:17:47 +00:00 committed by GitHub
parent 2528efb538
commit 418053b21e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 67 additions and 53 deletions

View File

@ -26,14 +26,20 @@
:padding-vertical 8 :padding-vertical 8
:padding-horizontal 12})) :padding-horizontal 12}))
(def right-side-container {:flex 1}) (def right-side-container
{:flex 1
:justify-content :center})
(defn title (defn title
[override-theme] [theme]
{:color (colors/theme-colors colors/white colors/neutral-100 override-theme)}) {:color (colors/theme-colors colors/white colors/neutral-100 theme)})
(defn text (defn text
[override-theme] [theme]
{:color (colors/theme-colors colors/white colors/neutral-100 override-theme)}) {:color (colors/theme-colors colors/white colors/neutral-100 theme)})
(def avatar-container {:margin-right 8 :margin-top 4}) (defn avatar-container
[{:keys [multiline?]}]
{:margin-right 8
:align-self (when-not multiline? :center)
:margin-top (if multiline? 4 0)})

View File

@ -1,7 +1,9 @@
(ns quo.components.notifications.notification.view (ns quo.components.notifications.notification.view
(:require (:require
[quo.components.avatars.user-avatar.view :as user-avatar]
[quo.components.markdown.text :as text] [quo.components.markdown.text :as text]
[quo.components.notifications.notification.style :as style] [quo.components.notifications.notification.style :as style]
[quo.theme]
[react-native.blur :as blur] [react-native.blur :as blur]
[react-native.core :as rn])) [react-native.core :as rn]))
@ -15,33 +17,33 @@
[into [rn/view {:accessibility-label :notification-body}] children]) [into [rn/view {:accessibility-label :notification-body}] children])
(defn avatar-container (defn avatar-container
[& children] [{:keys [multiline?]} & children]
[into [into
[rn/view [rn/view
{:style style/avatar-container {:style (style/avatar-container {:multiline? multiline?})
:accessibility-label :notification-avatar}] :accessibility-label :notification-avatar}]
children]) children])
(defn title (defn title
([text weight] (title text weight nil)) ([{:keys [text weight theme multiline?]}]
([text weight override-theme]
[text/text [text/text
{:size :paragraph-1 {:size :paragraph-1
:weight (or weight :semi-bold) :weight (or weight (if multiline? :semi-bold :medium))
:style (style/title override-theme) :style (style/title theme)
:accessibility-label :notification-title} :accessibility-label :notification-title}
text])) text]))
(defn message (defn message
[text override-theme] [text theme]
[text/text [text/text
{:size :paragraph-2 {:size :paragraph-2
:style (style/text override-theme) :weight :medium
:style (style/text theme)
:accessibility-label :notification-content} :accessibility-label :notification-content}
text]) text])
(defn- notification-container (defn- notification-container
[{:keys [avatar header body container-style override-theme]}] [{:keys [avatar header body container-style theme]}]
[rn/view [rn/view
{:style (merge style/box-container container-style)} {:style (merge style/box-container container-style)}
[blur/view [blur/view
@ -51,7 +53,7 @@
:blur-type :transparent :blur-type :transparent
:overlay-color :transparent}] :overlay-color :transparent}]
[rn/view [rn/view
{:style (style/content-container override-theme)} {:style (style/content-container theme)}
avatar avatar
[rn/view [rn/view
{:style style/right-side-container} {:style style/right-side-container}
@ -59,17 +61,27 @@
body]]]) body]]])
(defn notification (defn notification
[{title-text :title :keys [avatar header title-weight text body container-style override-theme]}] [{title-text :title :keys [avatar user header title-weight text body container-style theme]}]
(let [header (or header (let [theme (or theme (quo.theme/get-theme))
(when title-text body (or body (when text [message text theme]))
[title title-text title-weight override-theme])) header (or header
header (when header [header-container header]) (when title-text
body (or body (when text [message text override-theme])) [title
body (when body [body-container body]) {:text title-text
avatar (when avatar [avatar-container avatar])] :weight title-weight
[notification-container :theme theme
{:avatar avatar :multiline? (some? body)}]))
:header header header (when header [header-container header])
:body body body (when body [body-container body])
:container-style container-style user-avatar (or avatar (when user (user-avatar/user-avatar user)))
:override-theme override-theme}])) avatar (when user-avatar
[avatar-container
{:multiline? (and header body)}
user-avatar])]
[quo.theme/provider {:theme theme}
[notification-container
{:avatar avatar
:header header
:body body
:container-style container-style
:theme theme}]]))

View File

@ -30,12 +30,11 @@
[] []
[notification-button [notification-button
"Notification: with title(header)" "Notification: with title(header)"
{:avatar [quo/user-avatar {:user {:full-name "A Y"
{:full-name "A Y" :status-indicator? true
:status-indicator? true :online? true
:online? true :size :small
:size :small :customization-color :blue}
:customization-color :blue}]
:title "Alisher Yakupov accepted your contact request" :title "Alisher Yakupov accepted your contact request"
:duration 4000 :duration 4000
:title-weight :medium :title-weight :medium
@ -45,12 +44,11 @@
[] []
[notification-button [notification-button
"with title and body" "with title and body"
{:avatar [quo/user-avatar {:user {:full-name "A Y"
{:full-name "A Y" :status-indicator? true
:status-indicator? true :online? true
:online? true :size :small
:size :small :customization-color :blue}
:customization-color :blue}]
:title "Default to semibold title" :title "Default to semibold title"
:text "The quick brown fox jumped over the lazy dog and ate a potatoe." :text "The quick brown fox jumped over the lazy dog and ate a potatoe."
:duration 4000 :duration 4000
@ -60,12 +58,11 @@
[] []
[notification-button [notification-button
"with anything as header & body" "with anything as header & body"
{:avatar [quo/user-avatar {:user {:full-name "A Y"
{:full-name "A Y" :status-indicator? true
:status-indicator? true :online? true
:online? true :size :small
:size :small :customization-color :blue}
:customization-color :blue}]
:header [rn/view :header [rn/view
[quo/info-message [quo/info-message
{:type :success {:type :success

View File

@ -2,7 +2,6 @@
(:require (:require
[legacy.status-im.data-store.activities :as activities] [legacy.status-im.data-store.activities :as activities]
[legacy.status-im.data-store.chats :as data-store.chats] [legacy.status-im.data-store.chats :as data-store.chats]
[quo.foundations.colors :as colors]
[re-frame.core :as re-frame] [re-frame.core :as re-frame]
[status-im.common.json-rpc.events :as json-rpc] [status-im.common.json-rpc.events :as json-rpc]
[status-im.common.toasts.events :as toasts] [status-im.common.toasts.events :as toasts]
@ -544,9 +543,9 @@
(not accepted) (not accepted)
(not dismissed)) (not dismissed))
(toasts/upsert cofx (toasts/upsert cofx
{:user user-avatar {:type :notification
:user user-avatar
:user-public-key author :user-public-key author
:icon-color colors/primary-50-opa-40
:title (i18n/label :t/contact-request-sent-toast :title (i18n/label :t/contact-request-sent-toast
{:name name}) {:name name})
:text (get-in message [:content :text])}) :text (get-in message [:content :text])})
@ -556,10 +555,10 @@
accepted accepted
(not dismissed)) (not dismissed))
(toasts/upsert cofx (toasts/upsert cofx
{:user user-avatar {:type :notification
:user user-avatar
;; user public key who accepted the request ;; user public key who accepted the request
:user-public-key chat-id :user-public-key chat-id
:icon-color colors/success-50-opa-40
:title (i18n/label :t/contact-request-accepted-toast :title (i18n/label :t/contact-request-accepted-toast
{:name (or name (:alias message))})}) {:name (or name (:alias message))})})
:else :else