Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(mobile): incorrect theme color for the android status bar #11272

Merged
merged 1 commit into from
May 13, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
27 changes: 14 additions & 13 deletions src/main/frontend/util.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@
(defn- get-computed-bg-color
[]
;; window.getComputedStyle(document.body, null).getPropertyValue('background-color');
(let [styles (js/window.getComputedStyle (js/document.querySelector "#app-container"))
(let [styles (js/window.getComputedStyle js/document.body)
bg-color (gobj/get styles "background-color")
;; convert rgb(r,g,b) to #rrggbb
rgb2hex (fn [rgb]
Expand All @@ -219,9 +219,9 @@
%))
(string/join)
(str "#")))]
(when (string/starts-with? bg-color "rgb(")
(when (string/starts-with? bg-color "rgb")
(let [rgb (-> bg-color
(string/replace #"^rgb\(" "")
(string/replace #"^rgb[^\d]+" "")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the left bracket ignored?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. The left bracket is included.
CleanShot 2024-04-29 at 16 57 58@2x

(string/replace #"\)$" "")
(string/split #","))
rgb (take 3 rgb)]
Expand All @@ -231,26 +231,27 @@
#?(:cljs
(defn set-android-theme
[]
(when (mobile-util/native-android?)
(when-let [bg-color (try (get-computed-bg-color)
(catch :default _
nil))]
(.setNavigationBarColor NavigationBar (clj->js {:color bg-color}))
(.setBackgroundColor StatusBar (clj->js {:color bg-color}))))))
(let [f #(when (mobile-util/native-android?)
(when-let [bg-color (try (get-computed-bg-color)
(catch :default _
nil))]
(.setNavigationBarColor NavigationBar (clj->js {:color bg-color}))
(.setBackgroundColor StatusBar (clj->js {:color bg-color}))))]
(js/setTimeout f 32))))

#?(:cljs
(defn set-theme-light
[]
(p/do!
(.setStyle StatusBar (clj->js {:style (.-Light Style)}))
(set-android-theme))))
(.setStyle StatusBar (clj->js {:style (.-Light Style)}))
(set-android-theme))))

#?(:cljs
(defn set-theme-dark
[]
(p/do!
(.setStyle StatusBar (clj->js {:style (.-Dark Style)}))
(set-android-theme))))
(.setStyle StatusBar (clj->js {:style (.-Dark Style)}))
(set-android-theme))))

(defn find-first
[pred coll]
Expand Down