Skip to content

Commit

Permalink
Makes API more future proof by using a map instead of a keyword
Browse files Browse the repository at this point in the history
  • Loading branch information
ilmotta committed Jun 8, 2023
1 parent 63c2767 commit 884b0b2
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 8 deletions.
22 changes: 16 additions & 6 deletions src/quo2/theme.cljs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
(ns quo2.theme
(:require [reagent.core :as reagent]
[react-native.core :as rn]))
(:require [react-native.core :as rn]
[reagent.core :as reagent]
utils.transforms))

(defonce ^:private theme-context (rn/create-context :light))
(defonce ^:private theme-state (reagent/atom :light))
Expand All @@ -26,20 +27,29 @@
(if (= theme :light) light-value dark-value))))

(defn provider
[theme & children]
(into [:> (.-Provider theme-context) {:value theme}]
"Wraps `children` in a React Provider using `quo2.theme/theme-context` as the
context.
`options`: Clojure map. Currently we only use the `:theme` key. In the future
we may support other settings.
"
[options & children]
(into [:> (.-Provider theme-context) {:value (clj->js options)}]
children))

(defn use-theme
"A hook that returns the current theme context."
[]
(keyword (rn/use-context theme-context)))
(utils.transforms/js->clj (rn/use-context theme-context)))

(defn ^:private f-with-theme
[component props & args]
(let [theme (use-theme)]
(let [theme (-> (use-theme) :theme keyword)]
(into [component (assoc props :theme theme)] args)))

(defn with-theme
"Create a functional component that assoc `:theme` into the first arg of
`component`. The theme value is taken from the nearest `quo2.theme/provider`."
[component]
(fn [& args]
(into [:f> f-with-theme component] args)))
2 changes: 1 addition & 1 deletion src/status_im2/contexts/activity_center/view.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@
(rf/dispatch [:activity-center.notifications/fetch-first-page])
(fn []
(let [notifications (rf/sub [:activity-center/notifications])]
[theme/provider :dark
[theme/provider {:theme :dark}
[rn/view {:flex 1 :padding-top (navigation/status-bar-height)}
[blur/view style/blur]
[header]
Expand Down
2 changes: 1 addition & 1 deletion src/status_im2/navigation/view.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
(defn screen-wrapper
[{:keys [insets background-color component sheet? screen-theme]}]
(let [user-theme (quo2.theme/get-theme)]
[quo2.theme/provider (or screen-theme user-theme)
[quo2.theme/provider {:theme (or screen-theme user-theme)}
[rn/view {:style (wrapped-screen-style insets background-color)}
[inactive]
(if sheet?
Expand Down

0 comments on commit 884b0b2

Please sign in to comment.