@@ -35,7 +35,8 @@ module ReactNative.Unsafe.Components (
35
35
, webViewU
36
36
) where
37
37
38
- import React (ReactClass , ReactElement , createElement )
38
+ import React (Children , ReactClass , ReactElement , createElement , createLeafElement )
39
+ import Unsafe.Coerce (unsafeCoerce )
39
40
40
41
foreign import activityIndicatorClass :: forall props . ReactClass props
41
42
foreign import buttonClass :: forall props . ReactClass props
@@ -72,141 +73,152 @@ foreign import viewClass :: forall props. ReactClass props
72
73
foreign import viewPagerAndroidClass :: forall props . ReactClass props
73
74
foreign import webViewClass :: forall props . ReactClass props
74
75
75
- createNoChild :: forall props . ReactClass props -> props -> ReactElement
76
- createNoChild c p = createElement c p []
77
-
78
76
-- | Create a [Text](https://facebook.github.io/react-native/docs/text.html) component unsafely
79
77
textU :: forall props . props -> Array ReactElement -> ReactElement
80
- textU = createElement textClass
78
+ textU = createElementU textClass
81
79
82
80
-- | Create a [View](https://facebook.github.io/react-native/docs/view.html) component unsafely
83
81
viewU :: forall props . props -> Array ReactElement -> ReactElement
84
- viewU = createElement viewClass
82
+ viewU = createElementU viewClass
85
83
86
84
-- | Create a [SafeAreaView](https://facebook.github.io/react-native/docs/safeareaview.html) component unsafely
87
85
safeAreaViewU :: forall props . props -> Array ReactElement -> ReactElement
88
- safeAreaViewU = createElement viewClass
86
+ safeAreaViewU = createElementU viewClass
89
87
90
88
-- | Create an [Image](https://facebook.github.io/react-native/docs/image.html) component unsafely
91
89
imageU :: forall props . props -> Array ReactElement -> ReactElement
92
- imageU = createElement imageClass
90
+ imageU = createElementU imageClass
93
91
94
92
-- | Create a [ListView](https://facebook.github.io/react-native/docs/listview.html) component unsafely
95
93
listViewU :: forall props . props -> ReactElement
96
- listViewU = createNoChild listViewClass
94
+ listViewU = createLeafElementU listViewClass
97
95
98
96
-- | Create a [ToolbarAndroid](https://facebook.github.io/react-native/docs/toolbarandroid.html) component unsafely
99
97
toolbarAndroidU :: forall props . props -> Array ReactElement -> ReactElement
100
- toolbarAndroidU = createElement toolbarAndroidClass
98
+ toolbarAndroidU = createElementU toolbarAndroidClass
101
99
102
100
-- | Create an [ActivityIndicator](https://facebook.github.io/react-native/docs/activityindicator.html) component unsafely
103
101
activityIndicatorU :: forall props . props -> ReactElement
104
- activityIndicatorU = createNoChild activityIndicatorClass
102
+ activityIndicatorU = createLeafElementU activityIndicatorClass
105
103
106
104
-- | Create a [TouchableNativeFeedback](https://facebook.github.io/react-native/docs/touchablenativefeedback.html) component unsafely
107
105
touchableNativeFeedbackU :: forall props . props -> ReactElement -> ReactElement
108
- touchableNativeFeedbackU p c = createElement touchableNativeFeedbackClass p [c]
106
+ touchableNativeFeedbackU p c = createElementU touchableNativeFeedbackClass p [c]
109
107
110
108
-- | Create a [TouchableWithoutFeedback](https://facebook.github.io/react-native/docs/touchablewithoutfeedback.html) component unsafely
111
109
touchableWithoutFeedbackU :: forall props . props -> ReactElement -> ReactElement
112
- touchableWithoutFeedbackU p c = createElement touchableWithoutFeedbackClass p [c]
110
+ touchableWithoutFeedbackU p c = createElementU touchableWithoutFeedbackClass p [c]
113
111
114
112
-- | Create a [TouchableHighlight](http://facebook.github.io/react-native/docs/touchablehighlight.html#touchablehighlight) component unsafely
115
113
touchableHighlightU :: forall props . props -> ReactElement -> ReactElement
116
- touchableHighlightU p c = createElement touchableHighlightClass p [c]
114
+ touchableHighlightU p c = createElementU touchableHighlightClass p [c]
117
115
118
116
-- | Create a [TouchableOpacity](https://facebook.github.io/react-native/docs/touchableopacity.html) component unsafely
119
117
touchableOpacityU :: forall props . props -> ReactElement -> ReactElement
120
- touchableOpacityU p c = createElement touchableOpacityClass p [c]
118
+ touchableOpacityU p c = createElementU touchableOpacityClass p [c]
121
119
122
120
-- | Create a [ScrollView](https://facebook.github.io/react-native/docs/scrollview.html) component unsafely
123
121
scrollViewU :: forall props . props -> Array ReactElement -> ReactElement
124
- scrollViewU = createElement scrollViewClass
122
+ scrollViewU = createElementU scrollViewClass
125
123
126
124
-- | Create an [RefreshControl](https://facebook.github.io/react-native/docs/refreshcontrol.html) component unsafely
127
125
refreshControlU :: forall props . props -> ReactElement
128
- refreshControlU = createNoChild refreshControlClass
126
+ refreshControlU = createLeafElementU refreshControlClass
129
127
130
128
-- | Create a [Switch](https://facebook.github.io/react-native/docs/switch.html) component unsafely
131
129
switchU :: forall props . props -> ReactElement
132
- switchU = createNoChild switchClass
130
+ switchU = createLeafElementU switchClass
133
131
134
132
-- | Create a [DrawerLayoutAndroid](https://facebook.github.io/react-native/docs/drawerlayoutandroid.html) component unsafely
135
133
drawerLayoutAndroidU :: forall props . props -> Array ReactElement -> ReactElement
136
- drawerLayoutAndroidU = createElement drawerLayoutAndroidClass
134
+ drawerLayoutAndroidU = createElementU drawerLayoutAndroidClass
137
135
138
136
-- | Create a [Button](https://facebook.github.io/react-native/docs/button.html) component unsafely
139
137
buttonU :: forall props . props -> ReactElement
140
- buttonU = createNoChild buttonClass
138
+ buttonU = createLeafElementU buttonClass
141
139
142
140
-- | Create a [Picker](https://facebook.github.io/react-native/docs/picker.html) component unsafely
143
141
pickerU :: forall props . props -> Array ReactElement -> ReactElement
144
- pickerU = createElement pickerClass
142
+ pickerU = createElementU pickerClass
145
143
146
144
-- | Create a [Picker.Item](https://facebook.github.io/react-native/docs/picker.html) component unsafely
147
145
pickerItemU :: forall props . props -> ReactElement
148
- pickerItemU = createNoChild pickerItemClass
146
+ pickerItemU = createLeafElementU pickerItemClass
149
147
150
148
-- | Create a [Slider](https://facebook.github.io/react-native/docs/activityindicator.html) component unsafely
151
149
sliderU :: forall props . props -> ReactElement
152
- sliderU = createNoChild sliderClass
150
+ sliderU = createLeafElementU sliderClass
153
151
154
152
-- | Create a [NavigatorIOS](https://facebook.github.io/react-native/docs/navigatorios.html) component unsafely
155
153
navigatorIOSU :: forall props . props -> ReactElement
156
- navigatorIOSU = createNoChild navigatorIOSClass
154
+ navigatorIOSU = createLeafElementU navigatorIOSClass
157
155
158
156
-- | Create a [TextInput](https://facebook.github.io/react-native/docs/textinput.html) component unsafely
159
157
textInputU :: forall props . props -> ReactElement
160
- textInputU = createNoChild textInputClass
158
+ textInputU = createLeafElementU textInputClass
161
159
162
160
-- | Create a [DatePickerIOS](https://facebook.github.io/react-native/docs/datepickerios.html) component unsafely
163
161
datePickerIOSU :: forall props . props -> ReactElement
164
- datePickerIOSU = createNoChild datePickerIOSClass
162
+ datePickerIOSU = createLeafElementU datePickerIOSClass
165
163
166
164
-- | Create a [KeyboardAvoidingView](https://facebook.github.io/react-native/docs/keyboardavoidingview.html) component unsafely
167
165
keyboardAvoidingViewU :: forall props . props -> Array ReactElement -> ReactElement
168
- keyboardAvoidingViewU = createElement keyboardAvoidingViewClass
166
+ keyboardAvoidingViewU = createElementU keyboardAvoidingViewClass
169
167
170
168
-- | Create a [MapView](https://facebook.github.io/react-native/docs/mapview.html) component unsafely
171
169
mapViewU :: forall props . props -> Array ReactElement -> ReactElement
172
- mapViewU = createElement mapViewClass
170
+ mapViewU = createElementU mapViewClass
173
171
174
172
-- | Create a [Modal](https://facebook.github.io/react-native/docs/modal.html) component unsafely
175
173
modalU :: forall props . props -> Array ReactElement -> ReactElement
176
- modalU = createElement modalClass
174
+ modalU = createElementU modalClass
177
175
178
176
-- | Create a [ProgressBarAndroid](https://facebook.github.io/react-native/docs/progressbarandroid.html) component unsafely
179
177
progressBarAndroidU :: forall props . props -> ReactElement
180
- progressBarAndroidU = createNoChild progressBarAndroidClass
178
+ progressBarAndroidU = createLeafElementU progressBarAndroidClass
181
179
182
180
-- | Create a [ProgressViewIOS](https://facebook.github.io/react-native/docs/progressviewios.html) component unsafely
183
181
progressViewIOSU :: forall props . props -> ReactElement
184
- progressViewIOSU = createNoChild progressViewIOSClass
182
+ progressViewIOSU = createLeafElementU progressViewIOSClass
185
183
186
184
-- | Create a [SegmentedControlIOS](https://facebook.github.io/react-native/docs/segmentedcontrolios.html) component unsafely
187
185
segmentedControlIOSU :: forall props . props -> ReactElement
188
- segmentedControlIOSU = createNoChild segmentedControlIOSClass
186
+ segmentedControlIOSU = createLeafElementU segmentedControlIOSClass
189
187
190
188
-- | Create a [StatusBar](https://facebook.github.io/react-native/docs/statusbar.html) component unsafely
191
189
statusBarU :: forall props . props -> ReactElement
192
- statusBarU = createNoChild statusBarClass
190
+ statusBarU = createLeafElementU statusBarClass
193
191
194
192
-- | Create a [SnapshotViewIOS](https://facebook.github.io/react-native/docs/snapshotviewios.html) component unsafely
195
193
snapshotViewIOSU :: forall props . props -> ReactElement
196
- snapshotViewIOSU = createNoChild snapshotViewIOSClass
194
+ snapshotViewIOSU = createLeafElementU snapshotViewIOSClass
197
195
198
196
-- | Create a [TabBarIOS](https://facebook.github.io/react-native/docs/tabbarios.html) component unsafely
199
197
tabBarIOSU :: forall props . props -> Array ReactElement -> ReactElement
200
- tabBarIOSU = createElement tabBarIOSClass
198
+ tabBarIOSU = createElementU tabBarIOSClass
201
199
202
200
-- | Create a [TabBarIOS.Item](https://facebook.github.io/react-native/docs/tabbarios-item.html) component unsafely
203
201
tabBarIOSItemU :: forall props . props -> Array ReactElement -> ReactElement
204
- tabBarIOSItemU = createElement tabBarIOSItemClass
202
+ tabBarIOSItemU = createElementU tabBarIOSItemClass
205
203
206
204
-- | Create a [ViewPagerAndroid](https://facebook.github.io/react-native/docs/viewpagerandroid.html) component unsafely
207
205
viewPagerAndroidU :: forall props . props -> Array ReactElement -> ReactElement
208
- viewPagerAndroidU = createElement viewPagerAndroidClass
206
+ viewPagerAndroidU = createElementU viewPagerAndroidClass
209
207
210
208
-- | Create a [WebView](https://facebook.github.io/react-native/docs/webview.html) component unsafely
211
209
webViewU :: forall props . props -> ReactElement
212
- webViewU = createNoChild webViewClass
210
+ webViewU = createLeafElementU webViewClass
211
+
212
+ -- Unsafe createElement
213
+
214
+ createElementU :: forall props . ReactClass props -> props -> Array ReactElement -> ReactElement
215
+ createElementU c p =
216
+ createElement
217
+ (unsafeCoerce c :: ReactClass { children :: Children } )
218
+ (unsafeCoerce p :: { } )
219
+
220
+ createLeafElementU :: forall props . ReactClass props -> props -> ReactElement
221
+ createLeafElementU c p =
222
+ createLeafElement
223
+ (unsafeCoerce c :: ReactClass { } )
224
+ (unsafeCoerce p :: { } )
0 commit comments