2022-11-08 18:30:17 +01:00
|
|
|
(ns react-native.core
|
2023-01-16 17:20:10 +01:00
|
|
|
(:require ["react" :as react]
|
2022-11-08 18:30:17 +01:00
|
|
|
["react-native" :as react-native]
|
2022-12-20 21:52:28 +08:00
|
|
|
[cljs-bean.core :as bean]
|
|
|
|
[oops.core :as oops]
|
2022-11-21 16:03:49 +04:00
|
|
|
[react-native.flat-list :as flat-list]
|
2022-12-20 22:45:37 +08:00
|
|
|
[react-native.platform :as platform]
|
2022-12-05 14:22:06 +01:00
|
|
|
[react-native.section-list :as section-list]
|
2022-12-20 22:45:37 +08:00
|
|
|
[reagent.core :as reagent]))
|
2022-11-08 18:30:17 +01:00
|
|
|
|
2022-11-14 19:16:55 +01:00
|
|
|
(def app-state ^js (.-AppState ^js react-native))
|
|
|
|
|
2022-11-08 18:30:17 +01:00
|
|
|
(def view (reagent/adapt-react-class (.-View ^js react-native)))
|
|
|
|
(def scroll-view (reagent/adapt-react-class (.-ScrollView ^js react-native)))
|
|
|
|
(def image (reagent/adapt-react-class (.-Image ^js react-native)))
|
|
|
|
(def text (reagent/adapt-react-class (.-Text ^js react-native)))
|
2022-11-21 16:03:49 +04:00
|
|
|
(def text-input (reagent/adapt-react-class (.-TextInput ^js react-native)))
|
2022-11-08 18:30:17 +01:00
|
|
|
|
|
|
|
(def touchable-opacity (reagent/adapt-react-class (.-TouchableOpacity ^js react-native)))
|
|
|
|
(def touchable-highlight (reagent/adapt-react-class (.-TouchableHighlight ^js react-native)))
|
2022-12-20 22:45:37 +08:00
|
|
|
(def touchable-without-feedback
|
|
|
|
(reagent/adapt-react-class (.-TouchableWithoutFeedback ^js react-native)))
|
2022-11-08 18:30:17 +01:00
|
|
|
|
|
|
|
(def flat-list flat-list/flat-list)
|
|
|
|
|
2022-11-21 16:03:49 +04:00
|
|
|
(def section-list section-list/section-list)
|
|
|
|
|
2022-11-10 09:10:43 +01:00
|
|
|
(def activity-indicator (reagent/adapt-react-class (.-ActivityIndicator ^js react-native)))
|
|
|
|
|
2022-11-08 18:30:17 +01:00
|
|
|
(def modal (reagent/adapt-react-class (.-Modal ^js react-native)))
|
|
|
|
|
|
|
|
(def keyboard ^js (.-Keyboard ^js react-native))
|
|
|
|
|
|
|
|
(def dismiss-keyboard! #(.dismiss keyboard))
|
|
|
|
|
2022-12-20 22:45:37 +08:00
|
|
|
(defn use-window-dimensions
|
|
|
|
[]
|
2022-11-08 18:30:17 +01:00
|
|
|
(let [window ^js (react-native/useWindowDimensions)]
|
|
|
|
{:font-scale (.-fontScale window)
|
|
|
|
:height (.-height window)
|
|
|
|
:scale (.-scale window)
|
2022-11-14 19:16:55 +01:00
|
|
|
:width (.-width window)}))
|
|
|
|
|
2022-12-20 22:45:37 +08:00
|
|
|
(defn hide-splash-screen
|
|
|
|
[]
|
2022-11-14 19:16:55 +01:00
|
|
|
(.hide ^js (-> react-native .-NativeModules .-SplashScreen)))
|
|
|
|
|
2022-12-20 22:45:37 +08:00
|
|
|
(defn alert
|
|
|
|
[title message buttons options]
|
2022-11-14 19:16:55 +01:00
|
|
|
(.alert (.-Alert ^js react-native) title message (clj->js buttons) (clj->js options)))
|
|
|
|
|
|
|
|
(def appearance ^js (.-Appearance ^js react-native))
|
|
|
|
|
2022-12-20 22:45:37 +08:00
|
|
|
(defn get-color-scheme
|
|
|
|
[]
|
2022-11-14 19:16:55 +01:00
|
|
|
(.getColorScheme appearance))
|
|
|
|
|
2022-12-20 22:45:37 +08:00
|
|
|
(defn appearance-add-change-listener
|
|
|
|
[handler]
|
2022-11-14 19:16:55 +01:00
|
|
|
(.addChangeListener appearance handler))
|
|
|
|
|
2022-12-20 22:45:37 +08:00
|
|
|
(defn get-window
|
|
|
|
[]
|
2022-11-14 19:16:55 +01:00
|
|
|
(js->clj (.get (.-Dimensions ^js react-native) "window") :keywordize-keys true))
|
2022-11-16 12:00:16 +01:00
|
|
|
|
|
|
|
(def status-bar (.-StatusBar ^js react-native))
|
2022-12-05 14:22:06 +01:00
|
|
|
|
2022-12-28 15:23:58 +01:00
|
|
|
(def style-sheet (.-StyleSheet ^js react-native))
|
|
|
|
|
2022-12-20 22:45:37 +08:00
|
|
|
(defn status-bar-height
|
|
|
|
[]
|
2022-12-19 14:51:53 +05:30
|
|
|
(.-currentHeight ^js status-bar))
|
|
|
|
|
2022-12-20 22:45:37 +08:00
|
|
|
(defn hw-back-add-listener
|
|
|
|
[callback]
|
2022-12-05 14:22:06 +01:00
|
|
|
(.addEventListener (.-BackHandler ^js react-native) "hardwareBackPress" callback))
|
|
|
|
|
2022-12-20 22:45:37 +08:00
|
|
|
(defn hw-back-remove-listener
|
|
|
|
[callback]
|
2022-12-05 14:22:06 +01:00
|
|
|
(.removeEventListener (.-BackHandler ^js react-native) "hardwareBackPress" callback))
|
|
|
|
|
|
|
|
(def keyboard-avoiding-view-class (reagent/adapt-react-class (.-KeyboardAvoidingView react-native)))
|
|
|
|
|
2022-12-20 22:45:37 +08:00
|
|
|
(defn keyboard-avoiding-view
|
|
|
|
[props & children]
|
2022-12-05 14:22:06 +01:00
|
|
|
(into [keyboard-avoiding-view-class
|
|
|
|
(merge (when platform/ios? {:behavior :padding})
|
|
|
|
props)]
|
|
|
|
children))
|
2022-12-20 21:52:28 +08:00
|
|
|
|
2023-01-16 17:20:10 +01:00
|
|
|
(def create-ref react/createRef)
|
2022-12-20 21:52:28 +08:00
|
|
|
|
|
|
|
(def use-ref react/useRef)
|
2023-01-16 17:20:10 +01:00
|
|
|
|
|
|
|
(defn use-effect
|
|
|
|
([effect-fn]
|
|
|
|
(react/useEffect
|
|
|
|
#(let [ret (effect-fn)]
|
|
|
|
(if (fn? ret) ret js/undefined))))
|
|
|
|
([effect-fn deps]
|
|
|
|
(react/useEffect effect-fn (bean/->js deps))))
|
|
|
|
|
|
|
|
(defn use-effect-once
|
|
|
|
[effect-fn]
|
|
|
|
(use-effect effect-fn))
|
|
|
|
|
2022-12-20 22:45:37 +08:00
|
|
|
(defn use-unmount
|
|
|
|
[f]
|
2022-12-20 21:52:28 +08:00
|
|
|
(let [fn-ref (use-ref f)]
|
|
|
|
(oops/oset! fn-ref "current" f)
|
2023-01-10 10:02:23 +08:00
|
|
|
(use-effect-once (fn [] (fn [] (oops/ocall! fn-ref "current"))))))
|
2023-01-18 12:16:33 +01:00
|
|
|
|
|
|
|
(def layout-animation (.-LayoutAnimation ^js react-native))
|
|
|
|
(def configure-next (.-configureNext ^js layout-animation))
|
|
|
|
|
|
|
|
(def layout-animation-presets
|
|
|
|
{:ease-in-ease-out (-> ^js layout-animation .-Presets .-easeInEaseOut)
|
|
|
|
:linear (-> ^js layout-animation .-Presets .-linear)
|
|
|
|
:spring (-> ^js layout-animation .-Presets .-spring)})
|