/
ScrollView.purs
200 lines (174 loc) · 6.05 KB
/
ScrollView.purs
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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
-- | See [ScrollView](https://facebook.github.io/react-native/docs/scrollview.html)
module ReactNative.Components.ScrollView (
scrollView', scrollView_, scrollView, scrollTo, scrollTo'
, Scrollable, DecelerationRate, IndicatorStyle, SnapToAlignment
, KeyboardDismissMode, KeyboardShouldPersistTaps
, keyboardDismissMode, decelerationRate, decelerateBy, indicatorStyle
, snapToAlignment, keyboardShouldPersistTaps
, ScrollViewPropsEx, ScrollViewAndroid, ScrollViewIOS
, RefreshControl, RefreshControlSize
, refreshControl, refreshControl', refreshControlSize
)
where
import Prelude
import Control.Monad.Eff (Eff)
import Data.Function.Uncurried (Fn2, runFn2)
import ReactNative.Optional (class Optional)
import React (ReactElement, ReactThis)
import ReactNative.Components.View (ViewPropsEx)
import ReactNative.Events (EventHandler2, ScrollEvent, UnitEventHandler, EventHandler)
import ReactNative.PropTypes (Insets)
import ReactNative.PropTypes.Color (Color)
import ReactNative.Styles (Styles)
import ReactNative.Unsafe.ApplyProps (unsafeApplyProps)
import ReactNative.Unsafe.Components (refreshControlU, scrollViewU)
import Unsafe.Coerce (unsafeCoerce)
type ScrollViewPropsO eff = ScrollViewPropsEx eff ()
scrollView' :: forall eff o
. Optional o (ScrollViewPropsO eff)
=> {|o} -> Array ReactElement -> ReactElement
scrollView' = scrollViewU <<< unsafeApplyProps
scrollView_ :: Array ReactElement -> ReactElement
scrollView_ = scrollViewU {}
scrollView :: Styles -> Array ReactElement -> ReactElement
scrollView style = scrollViewU {style}
type RefreshProps eff r = {
onRefresh :: UnitEventHandler eff
, refreshing :: Boolean
| r
}
type RefreshPropsO eff = (
onRefresh :: UnitEventHandler eff
, refreshing :: Boolean
, android :: {
colors :: Array Color
, enabled :: Boolean
, progressBackgroundColor :: Color
, progressViewOffset :: Number
, size :: RefreshControlSize
}
, ios :: {
tintColor :: Color
, title :: String
, titleColor :: Color
}
)
refreshControl :: forall eff. UnitEventHandler eff -> Boolean -> RefreshControl
refreshControl onRefresh refreshing = RefreshControl $ refreshControlU {onRefresh, refreshing}
refreshControl' :: forall eff o
. Optional o (RefreshPropsO eff)
=> {|o} -> RefreshControl
refreshControl' = RefreshControl <<< refreshControlU <<< unsafeApplyProps
newtype RefreshControl = RefreshControl ReactElement
foreign import data RefreshControlSize :: Type
foreign import rcSizeImpl :: String -> RefreshControlSize
refreshControlSize :: {
default :: RefreshControlSize
, large :: RefreshControlSize
}
refreshControlSize = {
default: rcSizeImpl "DEFAULT"
, large: rcSizeImpl "LARGE"
}
newtype KeyboardDismissMode = KeyboardDismissMode String
keyboardDismissMode :: {
none :: KeyboardDismissMode
, interactive :: KeyboardDismissMode
, onDrag :: KeyboardDismissMode
}
keyboardDismissMode = {
none: KeyboardDismissMode "none"
, interactive: KeyboardDismissMode "interactive"
, onDrag: KeyboardDismissMode "on-drag"
}
newtype DecelerationRate = DecelerationRate String
decelerationRate :: { fast :: DecelerationRate
, normal :: DecelerationRate
}
decelerationRate = {
fast: DecelerationRate "fast"
, normal: DecelerationRate "normal"
}
decelerateBy :: Number -> DecelerationRate
decelerateBy = unsafeCoerce
newtype IndicatorStyle = IndicatorStyle String
indicatorStyle :: {
default :: IndicatorStyle
, black :: IndicatorStyle
, white :: IndicatorStyle
}
indicatorStyle = {
default: IndicatorStyle "default"
, black: IndicatorStyle "black"
, white: IndicatorStyle "white"
}
newtype SnapToAlignment = SnapToAlignment String
snapToAlignment :: {
start :: SnapToAlignment
, center :: SnapToAlignment
, end :: SnapToAlignment
}
snapToAlignment = {
start: SnapToAlignment "start"
, center: SnapToAlignment "center"
, end: SnapToAlignment "end"
}
newtype KeyboardShouldPersistTaps = KeyboardShouldPersistTaps String
keyboardShouldPersistTaps :: {
always :: KeyboardShouldPersistTaps
, never :: KeyboardShouldPersistTaps
, handled :: KeyboardShouldPersistTaps
}
keyboardShouldPersistTaps = {
always: KeyboardShouldPersistTaps "always"
, never: KeyboardShouldPersistTaps "never"
, handled: KeyboardShouldPersistTaps "handled"
}
type ScrollViewPropsEx eff r = ViewPropsEx eff (
contentContainerStyle :: Styles
, horizontal :: Boolean
, keyboardDismissMode :: KeyboardDismissMode
, keyboardShouldPersistTaps :: KeyboardShouldPersistTaps
, onContentSizeChange :: EventHandler2 eff Number Number
, onScroll :: EventHandler eff ScrollEvent
, pagingEnabled :: Boolean
, refreshControl :: RefreshControl
, scrollEnabled :: Boolean
, showsHorizontalScrollIndicator :: Boolean
, showsVerticalScrollIndicator :: Boolean
| r
) ScrollViewAndroid (ScrollViewIOS eff)
type ScrollViewAndroid = (
endFillColor :: Color
, scrollPerfTag :: String
)
type ScrollViewIOS eff = (
alwaysBounceHorizontal :: Boolean
, alwaysBounceVertical :: Boolean
, automaticallyAdjustContentInsets :: Boolean
, bounces :: Boolean
, bouncesZoom :: Boolean
, canCancelContentTouches :: Boolean
, centerContent :: Boolean
, contentInset :: Insets
, contentOffset :: {x::Number, y::Number}
, decelerationRate :: DecelerationRate
, directionalLockEnabled :: Boolean
, indicatorStyle :: IndicatorStyle
, maximumZoomScale :: Number
, minimumZoomScale :: Number
, onScrollAnimationEnd :: UnitEventHandler eff
, scrollEventThrottle :: Number
, scrollIndicatorInsets :: Insets
, scrollsToTop :: Boolean
, snapToAlignment :: SnapToAlignment
, snapToInterval :: Number
, stickyHeaderIndices :: Array Number
, zoomScale :: Number
)
newtype Scrollable = Scrollable (forall props state. ReactThis props state)
foreign import scrollToImpl :: forall eff. Fn2 {x:: Int, y :: Int, animated :: Boolean} Scrollable (Eff eff Unit)
scrollTo' :: forall eff. { x :: Int, y :: Int, animated :: Boolean } -> Scrollable -> Eff eff Unit
scrollTo' = runFn2 scrollToImpl
scrollTo :: forall eff. {x::Int, y::Int} -> Scrollable -> Eff eff Unit
scrollTo {x,y} = scrollTo' {x,y,animated:true}