Skip to content

Commit

Permalink
Fix: android nav bar and status bar color (logseq#7385)
Browse files Browse the repository at this point in the history
* fix(android): set nav bar and status bar color

Close logseq#7382
  • Loading branch information
andelf authored Nov 21, 2022
1 parent 962998a commit e618f5d
Show file tree
Hide file tree
Showing 11 changed files with 74 additions and 39 deletions.
1 change: 1 addition & 0 deletions android/app/capacitor.build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down
4 changes: 4 additions & 0 deletions android/app/src/main/assets/capacitor.plugins.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 2 additions & 0 deletions android/app/src/main/res/values/colors.xml
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="logoPrimary">#002b36</color>
<color name="colorPrimary">#ffffff</color>
<color name="colorPrimaryDark">#002b36</color>
</resources>
2 changes: 2 additions & 0 deletions android/app/src/main/res/values/styles.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
<item name="windowNoTitle">true</item>
<item name="android:background">@null</item>
<item name="android:windowIsTranslucent">true</item>
<item name="android:navigationBarColor">@color/colorPrimary</item>
<item name="android:statusBarColor">@color/colorPrimary</item>
</style>

<!-- App Starting -->
Expand Down
3 changes: 3 additions & 0 deletions android/capacitor.settings.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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')

Expand Down
1 change: 1 addition & 0 deletions ios/App/Podfile
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
8 changes: 5 additions & 3 deletions src/main/frontend/handler.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -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/<ratelimit-file-writes!)
Expand Down
15 changes: 13 additions & 2 deletions src/main/frontend/state.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -1114,7 +1114,7 @@ Similar to re-frame subscriptions"

(defn set-theme-mode!
[mode]
(when (mobile-util/native-ios?)
(when (mobile-util/native-platform?)
(if (= mode "light")
(util/set-theme-light)
(util/set-theme-dark)))
Expand All @@ -1137,7 +1137,7 @@ Similar to re-frame subscriptions"
(set-state! :ui/system-theme? false)
(storage/set :ui/system-theme? false))))

(defn toggle-theme
(defn- toggle-theme
[theme]
(if (= theme "dark") "light" "dark"))

Expand All @@ -1152,6 +1152,17 @@ Similar to re-frame subscriptions"
(set-state! (if mode [:ui/custom-theme (keyword mode)] :ui/custom-theme) theme)
(storage/set :ui/custom-theme (:ui/custom-theme @state))))

(defn restore-mobile-theme!
"Restore mobile theme setting from local storage"
[]
(let [mode (or (storage/get :ui/theme) "light")
system-theme? (storage/get :ui/system-theme?)]
(when (and (not system-theme?)
(mobile-util/native-platform?))
(if (= mode "light")
(util/set-theme-light)
(util/set-theme-dark)))))

(defn set-editing-block-dom-id!
[block-dom-id]
(set-state! :editor/block-dom-id block-dom-id))
Expand Down
64 changes: 36 additions & 28 deletions src/main/frontend/util.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
["/frontend/selection" :as selection]
["/frontend/utils" :as utils]
["@capacitor/status-bar" :refer [^js StatusBar Style]]
["@hugotomazi/capacitor-navigation-bar" :refer [^js NavigationBar]]
["grapheme-splitter" :as GraphemeSplitter]
["remove-accents" :as removeAccents]
["sanitize-filename" :as sanitizeFilename]
Expand All @@ -16,7 +17,7 @@
[cljs-time.core :as t]
[clojure.pprint]
[dommy.core :as d]
[frontend.mobile.util :refer [native-platform?]]
[frontend.mobile.util :as mobile-util]
[logseq.graph-parser.util :as gp-util]
[goog.dom :as gdom]
[goog.object :as gobj]
Expand Down Expand Up @@ -91,7 +92,7 @@

#?(:cljs
(defn mobile?
"Triggering condition: Mobile phones
"Triggering condition: Mobile phones
*** Warning!!! ***
For UX logic only! Don't use for FS logic
iPad / Android Pad doesn't trigger!"
Expand All @@ -114,7 +115,7 @@
#?(:cljs
(do
(def nfs? (and (not (electron?))
(not (native-platform?))))
(not (mobile-util/native-platform?))))
(def web-platform? nfs?)))

#?(:cljs
Expand Down Expand Up @@ -163,17 +164,24 @@
[]
(gobj/get js/window "innerWidth")))

;; Keep the following colors in sync with common.css
#?(:cljs
(defn set-theme-light
[]
(p/do!
(.setStyle StatusBar (clj->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]
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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]
Expand Down Expand Up @@ -934,20 +942,20 @@
"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
"Delegate to gp-util to loosely couple app usages to graph-parser"
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]
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)))))))
(.catch js/console.error)))))))
12 changes: 6 additions & 6 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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==
Expand Down

0 comments on commit e618f5d

Please sign in to comment.