Improve app theme naming and doc strings (#21107)

This commit is contained in:
Parvesh Monu 2024-08-22 10:55:05 +05:30 committed by GitHub
parent 4d26934949
commit 6bf1aecb6d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 34 additions and 32 deletions

View File

@ -99,9 +99,9 @@
(rf/defn system-theme-mode-changed
{:events [:system-theme-mode-changed]}
[{:keys [db] :as cofx} _]
(let [current-theme-type (get-in cofx [:db :profile/profile :appearance])]
(let [appearance-type (get-in cofx [:db :profile/profile :appearance])]
(when (and (multiaccounts.model/logged-in? db)
(= current-theme-type status-im.constants/theme-type-system))
(= appearance-type status-im.constants/appearance-type-system))
{:dispatch [:theme/switch]})))
(defn- on-biometric-auth-fail

View File

@ -2,23 +2,42 @@
(:require
[re-frame.core :as re-frame]
[status-im.common.theme.core :as theme]
[status-im.common.theme.utils :as utils]))
[status-im.constants :as constants]))
(re-frame/reg-fx
:theme/init-theme
(fn []
(theme/add-device-theme-change-listener)))
(defn- appearance-type->theme
"Converts appearance type identifier to a theme keyword.
Returns `:light` or `:dark` based on `appearance-type`:
- `appearance-type-light` (1): Light theme.
- `appearance-type-dark` (2): Dark theme.
- `appearance-type-system` (0): Uses system preference."
[appearance-type]
(condp = appearance-type
constants/appearance-type-dark :dark
constants/appearance-type-light :light
constants/appearance-type-system (if (theme/device-theme-dark?) :dark :light)
:dark))
;; Switches the theme and triggers related effects.
;;
;; Parameters:
;; - `theme`: Optional theme keyword to apply. If not provided, defaults to the theme determined by
;; `appearance-type`.
;; - `appearance-type`: Optional appearance type to determine the theme. If not provided, defaults to
;; the appearance type from the user's profile.
;; - `view-id`: Optional view ID for updating status and navigation color. If not provided, uses the
;; current view ID from the database. `view-id` is required because status and navigation bar colors
;; depends on the screen. For example, on the home screen, the navigation color should always be dark,
;; regardless of the theme, due to the bottom tabs.
(re-frame/reg-event-fx
:theme/switch
(fn [{db :db} [{:keys [theme view-id theme-type]}]]
"Switches the theme and triggers related effects.
Parameters:
- theme: Optional theme keyword to apply. If not provided, defaults to the theme determined by theme-type.
- theme-type: Optional theme type to determine the theme. If not provided, defaults to the theme type from the user's profile.
- view-id: Optional view ID for updating status color. If not provided, uses the current view ID from the database."
(let [theme-type (or theme-type (get-in db [:profile/profile :appearance]))
theme (or theme (utils/theme-type->theme-value theme-type))]
(fn [{db :db} [{:keys [theme view-id appearance-type]}]]
(let [appearance-type (or appearance-type (get-in db [:profile/profile :appearance]))
theme (or theme (appearance-type->theme appearance-type))]
{:db (assoc db :theme theme)
:fx [[:theme/legacy-theme-fx theme]
[:dispatch

View File

@ -1,17 +0,0 @@
(ns status-im.common.theme.utils
(:require
[status-im.common.theme.core :as theme]
[status-im.constants :as constants]))
(defn theme-type->theme-value
"Converts theme type identifier to a theme keyword.
Returns `:light` or `:dark` based on `theme-type`:
- `theme-type-light` (1): Light theme.
- `theme-type-dark` (2): Dark theme.
- `theme-type-system` (0): Uses system preference."
[theme-type]
(condp = theme-type
constants/theme-type-dark :dark
constants/theme-type-light :light
constants/theme-type-system (if (theme/device-theme-dark?) :dark :light)
:dark))

View File

@ -425,9 +425,9 @@
"We prefix our keys with 0xe701 prior to serialisation them"
"0xe701")
(def ^:const theme-type-system 0)
(def ^:const theme-type-light 1)
(def ^:const theme-type-dark 2)
(def ^:const appearance-type-system 0)
(def ^:const appearance-type-light 1)
(def ^:const appearance-type-dark 2)
(def ^:const bottom-sheet-animation-delay 450)
(def ^:const local-pair-event-process-success "process-success")

View File

@ -95,7 +95,7 @@
(rf/reg-event-fx :profile.settings/change-appearance
(fn [_ [theme]]
{:fx [[:dispatch [:profile.settings/profile-update :appearance theme]]
[:dispatch [:theme/switch {:theme-type theme}]]]}))
[:dispatch [:theme/switch {:appearance-type theme}]]]}))
(rf/reg-fx :profile.settings/get-profile-picture
(fn [key-uid]