-
Notifications
You must be signed in to change notification settings - Fork 990
/
Copy pathgesture.cljs
106 lines (75 loc) · 3.42 KB
/
gesture.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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
(ns react-native.gesture
(:require ["react-native-gesture-handler" :refer
(Gesture
GestureDetector
RectButton
Swipeable
TouchableWithoutFeedback
gestureHandlerRootHOC
FlatList
ScrollView)]
[react-native.flat-list :as rn-flat-list]
[reagent.core :as reagent]))
(def gesture-detector (reagent/adapt-react-class GestureDetector))
(def gesture-handler-root-hoc gestureHandlerRootHOC)
(defn gesture-tap [] (.Tap ^js Gesture))
(defn gesture-pan [] (.Pan ^js Gesture))
(defn gesture-long-press [] (.LongPress ^js Gesture))
(defn gesture-pinch [] (.Pinch ^js Gesture))
(defn on-begin [gesture handler] (.onBegin ^js gesture handler))
(defn on-start [gesture handler] (.onStart ^js gesture handler))
(defn on-update [gesture handler] (.onUpdate ^js gesture handler))
(defn on-end [gesture handler] (.onEnd ^js gesture handler))
(defn on-finalize [gesture handler] (.onFinalize ^js gesture handler))
(defn max-pointers [gesture amount] (.maxPointers ^js gesture amount))
(defn min-distance [gesture dist] (.minDistance ^js gesture dist))
(defn fail-offset-x [gesture offset] (.failOffsetX ^js gesture offset))
(defn hit-slop [gesture settings] (.hitSlop ^js gesture settings))
(defn number-of-taps [gesture amount] (.numberOfTaps ^js gesture amount))
(defn enabled [gesture enabled?] (.enabled ^js gesture enabled?))
(defn average-touches [gesture average-touches?] (.averageTouches ^js gesture average-touches?))
(defn with-test-ID [gesture test-ID] (.withTestId ^js gesture (str test-ID)))
(defn simultaneous
([g1 g2] (.Simultaneous ^js Gesture g1 g2))
([g1 g2 g3] (.Simultaneous ^js Gesture g1 g2 g3)))
(defn exclusive [g1 g2] (.Exclusive ^js Gesture g1 g2))
;; RN Gesture Handler touchables are drop-in replacements for the RN ones. In
;; some cases, it's the only touchable that works with Swipeable components.
(def touchable-without-feedback (reagent/adapt-react-class TouchableWithoutFeedback))
(def rect-button (reagent/adapt-react-class RectButton))
(def ^:private swipeable-component
(reagent/adapt-react-class Swipeable))
(defn swipeable
[{:keys [render-left-actions render-right-actions] :as props} & children]
(into [swipeable-component
(cond-> props
render-left-actions
(assoc :render-left-actions
(fn [& args]
(reagent/as-element (apply render-left-actions args))))
render-right-actions
(assoc :render-right-actions
(fn [& args]
(reagent/as-element (apply render-right-actions args)))))]
children))
(def gesture-flat-list (reagent/adapt-react-class FlatList))
(defn flat-list
[props]
[gesture-flat-list (rn-flat-list/base-list-props props)])
(def scroll-view (reagent/adapt-react-class ScrollView))
;;; Custom gesture section-list
(defn- flatten-sections
[sections]
(mapcat (fn [{:keys [title data]}]
(into [{:title title :header? true}] data))
sections))
(defn section-list
[{:keys [sections render-section-header-fn render-fn] :as props}]
(let [data (flatten-sections sections)]
[flat-list
(merge props
{:data data
:render-fn (fn [p1 p2 p3 p4]
(if (:header? p1)
[render-section-header-fn p1 p2 p3 p4]
[render-fn p1 p2 p3 p4]))})]))