浏览代码

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

charlie 1 年之前
父节点
当前提交
7ba72aee75
共有 1 个文件被更改,包括 14 次插入13 次删除
  1. 14 13
      src/main/frontend/util.cljc

+ 14 - 13
src/main/frontend/util.cljc

@@ -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]
@@ -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]+" "")
                        (string/replace #"\)$" "")
                        (string/split #","))
                rgb (take 3 rgb)]
@@ -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]