From e618f5d1f75e67c265dbef6bb2084fefad656eea Mon Sep 17 00:00:00 2001 From: Andelf Date: Mon, 21 Nov 2022 10:50:10 +0800 Subject: [PATCH] Fix: android nav bar and status bar color (#7385) * fix(android): set nav bar and status bar color Close #7382 --- android/app/capacitor.build.gradle | 1 + .../src/main/assets/capacitor.plugins.json | 4 ++ android/app/src/main/res/values/colors.xml | 2 + android/app/src/main/res/values/styles.xml | 2 + android/capacitor.settings.gradle | 3 + ios/App/Podfile | 1 + package.json | 1 + src/main/frontend/handler.cljs | 8 ++- src/main/frontend/state.cljs | 15 ++++- src/main/frontend/util.cljc | 64 +++++++++++-------- yarn.lock | 12 ++-- 11 files changed, 74 insertions(+), 39 deletions(-) diff --git a/android/app/capacitor.build.gradle b/android/app/capacitor.build.gradle index 8b1d328bad..c54a23a06a 100644 --- a/android/app/capacitor.build.gradle +++ b/android/app/capacitor.build.gradle @@ -19,6 +19,7 @@ dependencies { implementation project(':capacitor-splash-screen') implementation project(':capacitor-status-bar') implementation project(':capawesome-capacitor-background-task') + implementation project(':hugotomazi-capacitor-navigation-bar') implementation project(':logseq-capacitor-file-sync') implementation project(':capacitor-voice-recorder') implementation project(':send-intent') diff --git a/android/app/src/main/assets/capacitor.plugins.json b/android/app/src/main/assets/capacitor.plugins.json index 7f0df6f23d..6499045a71 100644 --- a/android/app/src/main/assets/capacitor.plugins.json +++ b/android/app/src/main/assets/capacitor.plugins.json @@ -39,6 +39,10 @@ "pkg": "@capawesome/capacitor-background-task", "classpath": "io.capawesome.capacitorjs.plugins.backgroundtask.BackgroundTaskPlugin" }, + { + "pkg": "@hugotomazi/capacitor-navigation-bar", + "classpath": "br.com.tombus.capacitor.plugin.navigationbar.NavigationBarPlugin" + }, { "pkg": "@logseq/capacitor-file-sync", "classpath": "com.logseq.app.filesync.FileSyncPlugin" diff --git a/android/app/src/main/res/values/colors.xml b/android/app/src/main/res/values/colors.xml index b70eee43a5..1eba8652a8 100644 --- a/android/app/src/main/res/values/colors.xml +++ b/android/app/src/main/res/values/colors.xml @@ -1,4 +1,6 @@ #002b36 + #ffffff + #002b36 diff --git a/android/app/src/main/res/values/styles.xml b/android/app/src/main/res/values/styles.xml index b8f8f0ba95..6d3897ca24 100644 --- a/android/app/src/main/res/values/styles.xml +++ b/android/app/src/main/res/values/styles.xml @@ -14,6 +14,8 @@ true @null true + @color/colorPrimary + @color/colorPrimary diff --git a/android/capacitor.settings.gradle b/android/capacitor.settings.gradle index 97695fe96b..522a903ef7 100644 --- a/android/capacitor.settings.gradle +++ b/android/capacitor.settings.gradle @@ -32,6 +32,9 @@ project(':capacitor-status-bar').projectDir = new File('../node_modules/@capacit include ':capawesome-capacitor-background-task' project(':capawesome-capacitor-background-task').projectDir = new File('../node_modules/@capawesome/capacitor-background-task/android') +include ':hugotomazi-capacitor-navigation-bar' +project(':hugotomazi-capacitor-navigation-bar').projectDir = new File('../node_modules/@hugotomazi/capacitor-navigation-bar/android') + include ':logseq-capacitor-file-sync' project(':logseq-capacitor-file-sync').projectDir = new File('../node_modules/@logseq/capacitor-file-sync/android') diff --git a/ios/App/Podfile b/ios/App/Podfile index 9af1be496d..a24f0451fe 100644 --- a/ios/App/Podfile +++ b/ios/App/Podfile @@ -21,6 +21,7 @@ def capacitor_pods pod 'CapacitorSplashScreen', :path => '../../node_modules/@capacitor/splash-screen' pod 'CapacitorStatusBar', :path => '../../node_modules/@capacitor/status-bar' pod 'CapawesomeCapacitorBackgroundTask', :path => '../../node_modules/@capawesome/capacitor-background-task' + pod 'HugotomaziCapacitorNavigationBar', :path => '../../node_modules/@hugotomazi/capacitor-navigation-bar' pod 'LogseqCapacitorFileSync', :path => '../../node_modules/@logseq/capacitor-file-sync' pod 'CapacitorVoiceRecorder', :path => '../../node_modules/capacitor-voice-recorder' pod 'SendIntent', :path => '../../node_modules/send-intent' diff --git a/package.json b/package.json index b4871f0d9b..978c1b101e 100644 --- a/package.json +++ b/package.json @@ -90,6 +90,7 @@ "@capacitor/status-bar": "^4.0.0", "@capawesome/capacitor-background-task": "^2.0.0", "@excalidraw/excalidraw": "0.12.0", + "@hugotomazi/capacitor-navigation-bar": "^2.0.0", "@kanru/rage-wasm": "^0.3.0", "@logseq/capacitor-file-sync": "0.0.13", "@logseq/react-tweet-embed": "1.3.1-1", diff --git a/src/main/frontend/handler.cljs b/src/main/frontend/handler.cljs index 8715899d1a..cefd931976 100644 --- a/src/main/frontend/handler.cljs +++ b/src/main/frontend/handler.cljs @@ -219,13 +219,15 @@ (-> (p/let [repos (get-repos) _ (state/set-repos! repos) - _ (restore-and-setup! repos)]) + _ (restore-and-setup! repos)] + (when (mobile-util/native-platform?) + (p/do! + (mobile-util/hide-splash) + (state/restore-mobile-theme!)))) (p/catch (fn [e] (js/console.error "Error while restoring repos: " e))) (p/finally (fn [] (state/set-db-restoring! false)))) - (when (mobile-util/native-platform?) - (mobile-util/hide-splash)) (db/run-batch-txs!) (file/js {:style (.-Light Style)}))))) + (.setStyle StatusBar (clj->js {:style (.-Light Style)})) + (when (mobile-util/native-android?) + (.setColor NavigationBar (clj->js {:color "#ffffff"})) + (.setBackgroundColor StatusBar (clj->js {:color "#ffffff"})))))) #?(:cljs (defn set-theme-dark [] (p/do! - (.setStyle StatusBar (clj->js {:style (.-Dark Style)}))))) + (.setStyle StatusBar (clj->js {:style (.-Dark Style)})) + (when (mobile-util/native-android?) + (.setColor NavigationBar (clj->js {:color "#002b36"})) + (.setBackgroundColor StatusBar (clj->js {:color "#002b36"})))))) (defn find-first [pred coll] @@ -818,9 +826,9 @@ (let [block-id (.-id block) block-ids (mapv #(.-id %) blocks)] (when-let [index (.indexOf block-ids block-id)] - (let [idx (dec index)] - (when (>= idx 0) - (nth-safe blocks idx)))))))) + (let [idx (dec index)] + (when (>= idx 0) + (nth-safe blocks idx)))))))) #?(:cljs (defn get-next-block-non-collapsed @@ -829,9 +837,9 @@ (let [block-id (.-id block) block-ids (mapv #(.-id %) blocks)] (when-let [index (.indexOf block-ids block-id)] - (let [idx (inc index)] - (when (>= (count blocks) idx) - (nth-safe blocks idx)))))))) + (let [idx (inc index)] + (when (>= (count blocks) idx) + (nth-safe blocks idx)))))))) #?(:cljs (defn get-next-block-non-collapsed-skip @@ -840,14 +848,14 @@ (let [block-id (.-id block) block-ids (mapv #(.-id %) blocks)] (when-let [index (.indexOf block-ids block-id)] - (loop [idx (inc index)] - (when (>= (count blocks) idx) - (let [block (nth-safe blocks idx) - nested? (->> (array-seq (gdom/getElementsByClass "selected")) - (some (fn [dom] (.contains dom block))))] - (if nested? - (recur (inc idx)) - block))))))))) + (loop [idx (inc index)] + (when (>= (count blocks) idx) + (let [block (nth-safe blocks idx) + nested? (->> (array-seq (gdom/getElementsByClass "selected")) + (some (fn [dom] (.contains dom block))))] + (if nested? + (recur (inc idx)) + block))))))))) (defn rand-str [n] @@ -934,9 +942,9 @@ "Normalize string for searching (loose)" [s remove-accents?] (let [normalize-str (.normalize (string/lower-case s) "NFKC")] - (if remove-accents? - (removeAccents normalize-str) - normalize-str)))) + (if remove-accents? + (removeAccents normalize-str) + normalize-str)))) #?(:cljs (def page-name-sanity-lc @@ -944,10 +952,10 @@ gp-util/page-name-sanity-lc)) #?(:cljs - (defn safe-page-name-sanity-lc - [s] - (if (string? s) - (page-name-sanity-lc s) s))) + (defn safe-page-name-sanity-lc + [s] + (if (string? s) + (page-name-sanity-lc s) s))) (defn get-page-original-name [page] @@ -1286,7 +1294,7 @@ #?(:cljs (defn scroll-editor-cursor [^js/HTMLElement el & {:keys [to-vw-one-quarter?]}] - (when (and el (or (native-platform?) mobile?)) + (when (and el (or (mobile-util/native-platform?) mobile?)) (let [box-rect (.getBoundingClientRect el) box-top (.-top box-rect) box-bottom (.-bottom box-rect) @@ -1428,4 +1436,4 @@ (-> (.blob data) (.then (fn [blob] (js/navigator.clipboard.write (clj->js [(js/ClipboardItem. (clj->js {(.-type blob) blob}))])))) - (.catch js/console.error))))))) \ No newline at end of file + (.catch js/console.error))))))) diff --git a/yarn.lock b/yarn.lock index 7c43ec8e2e..fb63d91834 100644 --- a/yarn.lock +++ b/yarn.lock @@ -358,6 +358,11 @@ dependencies: dotenv "10.0.0" +"@hugotomazi/capacitor-navigation-bar@^2.0.0": + version "2.0.0" + resolved "https://registry.yarnpkg.com/@hugotomazi/capacitor-navigation-bar/-/capacitor-navigation-bar-2.0.0.tgz#d5297025da12c486e7f733e311e367eeebd8a011" + integrity sha512-hebf0ixGPugiZfH6g7HS/hrDzkKmNdJV/pV2jUz5lfoZXFMjE+7aeAr1AqwW6EGNej65WcEP8VUL5YUc3wSCjw== + "@ionic/cli-framework-output@^2.2.1", "@ionic/cli-framework-output@^2.2.5": version "2.2.5" resolved "https://registry.yarnpkg.com/@ionic/cli-framework-output/-/cli-framework-output-2.2.5.tgz#0db9fba7efe0c27bb5085b12ee01f22053e44152" @@ -1616,12 +1621,7 @@ caniuse-api@^3.0.0: lodash.memoize "^4.1.2" lodash.uniq "^4.5.0" -caniuse-lite@^1.0.0, caniuse-lite@^1.0.30001109, caniuse-lite@^1.0.30001370: - version "1.0.30001431" - resolved "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001431.tgz" - integrity sha512-zBUoFU0ZcxpvSt9IU66dXVT/3ctO1cy4y9cscs1szkPlcWb6pasYM144GqrUygUbT+k7cmUCW61cvskjcv0enQ== - -caniuse-lite@^1.0.30001400, caniuse-lite@^1.0.30001426: +caniuse-lite@^1.0.0, caniuse-lite@^1.0.30001109, caniuse-lite@^1.0.30001370, caniuse-lite@^1.0.30001400, caniuse-lite@^1.0.30001426: version "1.0.30001431" resolved "https://registry.yarnpkg.com/caniuse-lite/-/caniuse-lite-1.0.30001431.tgz#e7c59bd1bc518fae03a4656be442ce6c4887a795" integrity sha512-zBUoFU0ZcxpvSt9IU66dXVT/3ctO1cy4y9cscs1szkPlcWb6pasYM144GqrUygUbT+k7cmUCW61cvskjcv0enQ==