generated from PEZ/rn-rf-shadow
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathportrait.cljs
27 lines (24 loc) · 1.31 KB
/
portrait.cljs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
(ns gurps.pages.character.info.widgets.portrait
(:require [gurps.widgets.base :refer [view button image]]
["twrnc" :refer [style] :rename {style tw}]
["expo-image-picker" :as picker]
[re-frame.core :as rf]))
;; TODO: need to remove this, by annotating the js types in pick-image as recommended in:
;; https://cljs.github.io/api/cljs.core/STARwarn-on-inferSTAR
(set! *warn-on-infer* false)
(defn- pick-image []
(-> (picker/requestMediaLibraryPermissionsAsync)
(.then #(picker/launchImageLibraryAsync #js {:mediaTypes (.-Images picker/MediaTypeOptions)
:allowsEditing true
:aspect #js [4, 4]
:quality 1}))
(.then #(when (not (.-canceled ^js %))
(-> ^js % .-assets first .-uri)))
(.then #(when % (rf/dispatch [:profile/update :portrait ^js/String %])))))
(defn portrait []
(let [uri (some-> (rf/subscribe [:profile/portrait]) deref)]
[:> view {:style (tw "flex items-center justify-center")}
[:> button {:style (tw "w-50 h-50")
:onPress pick-image}
[:> image {:style (tw "w-50 h-50 bg-slate-200 border-2 border-slate-400 rounded-sm")
:source {:uri uri}}]]]))