@@ -24,6 +24,77 @@ const styles = StyleSheet.create({
24
24
} ,
25
25
} ) ;
26
26
27
+
28
+ function DragDropView ( ) : React . Node {
29
+ // $FlowFixMe[missing-empty-array-annot]
30
+ const [ log , setLog ] = React . useState ( [ ] ) ;
31
+ const appendLog = ( line : string ) => {
32
+ const limit = 3 ;
33
+ let newLog = log . slice ( 0 , limit - 1 ) ;
34
+ newLog . unshift ( line ) ;
35
+ setLog ( newLog ) ;
36
+ } ;
37
+ const [ imageUri , setImageUri ] = React . useState (
38
+ 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mP8z/C/HgAGgwJ/lK3Q6wAAAABJRU5ErkJggg==' ,
39
+ ) ;
40
+ const [ isDraggingOver , setIsDraggingOver ] = React . useState ( false ) ;
41
+
42
+ return (
43
+ < >
44
+ < View
45
+ draggedTypes = { [ 'fileUrl' , 'image' ] }
46
+ onDragEnter = { e => {
47
+ appendLog ( 'onDragEnter' ) ;
48
+ setIsDraggingOver ( true ) ;
49
+ } }
50
+ onDragLeave = { e => {
51
+ appendLog ( 'onDragLeave' ) ;
52
+ setIsDraggingOver ( false ) ;
53
+ } }
54
+ onDrop = { e => {
55
+ appendLog ( 'onDrop' ) ;
56
+ setIsDraggingOver ( false ) ;
57
+ if ( e . nativeEvent . dataTransfer . files && e . nativeEvent . dataTransfer . files [ 0 ] ) {
58
+ setImageUri ( e . nativeEvent . dataTransfer . files [ 0 ] . uri ) ;
59
+ }
60
+ } }
61
+ style = { {
62
+ height : 150 ,
63
+ backgroundColor : isDraggingOver ? '#e3f2fd' : '#f0f0f0' ,
64
+ borderWidth : 2 ,
65
+ borderColor : isDraggingOver ? '#2196f3' : '#0066cc' ,
66
+ borderStyle : 'dashed' ,
67
+ borderRadius : 8 ,
68
+ justifyContent : 'center' ,
69
+ alignItems : 'center' ,
70
+ marginVertical : 10 ,
71
+ } } >
72
+ < Text style = { { color : isDraggingOver ? '#1976d2' : '#666' , fontSize : 14 } } >
73
+ { isDraggingOver ? 'Release to drop' : 'Drop an image or file here' }
74
+ </ Text >
75
+ </ View >
76
+ < View style = { { flexDirection : 'row' , gap : 10 , alignItems : 'flex-start' } } >
77
+ < View style = { { flex : 1 } } >
78
+ < Text style = { { fontWeight : 'bold' , marginBottom : 4 } } > Event Log:</ Text >
79
+ < Text style = { { height : 90 } } > { log . join ( '\n' ) } </ Text >
80
+ </ View >
81
+ < View style = { { flex : 1 } } >
82
+ < Text style = { { fontWeight : 'bold' , marginBottom : 4 } } > Dropped Image:</ Text >
83
+ < Image
84
+ source = { { uri : imageUri } }
85
+ style = { {
86
+ width : 128 ,
87
+ height : 128 ,
88
+ borderWidth : 1 ,
89
+ borderColor : '#ccc' ,
90
+ } }
91
+ />
92
+ </ View >
93
+ </ View >
94
+ </ >
95
+ ) ;
96
+ }
97
+
27
98
function OnDragEnterOnDragLeaveOnDrop ( ) : React . Node {
28
99
// $FlowFixMe[missing-empty-array-annot]
29
100
const [ log , setLog ] = React . useState ( [ ] ) ;
@@ -117,94 +188,24 @@ function OnPaste(): React.Node {
117
188
) ;
118
189
}
119
190
120
- function OnDropView ( ) : React . Node {
121
- // $FlowFixMe[missing-empty-array-annot]
122
- const [ log , setLog ] = React . useState ( [ ] ) ;
123
- const appendLog = ( line : string ) => {
124
- const limit = 3 ;
125
- let newLog = log . slice ( 0 , limit - 1 ) ;
126
- newLog . unshift ( line ) ;
127
- setLog ( newLog ) ;
128
- } ;
129
- const [ imageUri , setImageUri ] = React . useState (
130
- 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mP8z/C/HgAGgwJ/lK3Q6wAAAABJRU5ErkJggg==' ,
131
- ) ;
132
- const [ isDraggingOver , setIsDraggingOver ] = React . useState ( false ) ;
133
-
134
- return (
135
- < >
136
- < View
137
- draggedTypes = { [ 'fileUrl' , 'image' ] }
138
- onDragEnter = { e => {
139
- appendLog ( 'onDragEnter' ) ;
140
- setIsDraggingOver ( true ) ;
141
- } }
142
- onDragLeave = { e => {
143
- appendLog ( 'onDragLeave' ) ;
144
- setIsDraggingOver ( false ) ;
145
- } }
146
- onDrop = { e => {
147
- appendLog ( 'onDrop' ) ;
148
- setIsDraggingOver ( false ) ;
149
- if ( e . nativeEvent . dataTransfer . files && e . nativeEvent . dataTransfer . files [ 0 ] ) {
150
- setImageUri ( e . nativeEvent . dataTransfer . files [ 0 ] . uri ) ;
151
- }
152
- } }
153
- style = { {
154
- height : 150 ,
155
- backgroundColor : isDraggingOver ? '#e3f2fd' : '#f0f0f0' ,
156
- borderWidth : 2 ,
157
- borderColor : isDraggingOver ? '#2196f3' : '#0066cc' ,
158
- borderStyle : 'dashed' ,
159
- borderRadius : 8 ,
160
- justifyContent : 'center' ,
161
- alignItems : 'center' ,
162
- marginVertical : 10 ,
163
- } } >
164
- < Text style = { { color : isDraggingOver ? '#1976d2' : '#666' , fontSize : 14 } } >
165
- { isDraggingOver ? 'Release to drop' : 'Drop an image or file here' }
166
- </ Text >
167
- </ View >
168
- < View style = { { flexDirection : 'row' , gap : 10 , alignItems : 'flex-start' } } >
169
- < View style = { { flex : 1 } } >
170
- < Text style = { { fontWeight : 'bold' , marginBottom : 4 } } > Event Log:</ Text >
171
- < Text style = { { height : 90 } } > { log . join ( '\n' ) } </ Text >
172
- </ View >
173
- < View style = { { flex : 1 } } >
174
- < Text style = { { fontWeight : 'bold' , marginBottom : 4 } } > Dropped Image:</ Text >
175
- < Image
176
- source = { { uri : imageUri } }
177
- style = { {
178
- width : 128 ,
179
- height : 128 ,
180
- borderWidth : 1 ,
181
- borderColor : '#ccc' ,
182
- } }
183
- />
184
- </ View >
185
- </ View >
186
- </ >
187
- ) ;
188
- }
189
-
190
191
exports . title = 'Drag and Drop Events' ;
191
192
exports . category = 'UI' ;
192
193
exports . description = 'Demonstrates onDragEnter, onDragLeave, onDrop, and onPaste event handling in TextInput.' ;
193
194
exports . examples = [
194
195
{
195
- title : 'onDrop with View - Drop Image ' ,
196
+ title : 'Drag and Drop (View) ' ,
196
197
render : function ( ) : React . Node {
197
- return < OnDropView /> ;
198
+ return < DragDropView /> ;
198
199
} ,
199
200
} ,
200
201
{
201
- title : 'onDragEnter, onDragLeave and onDrop - Single- & MultiLineTextInput ' ,
202
+ title : 'Drag and Drop (TextInput) ' ,
202
203
render : function ( ) : React . Node {
203
204
return < OnDragEnterOnDragLeaveOnDrop /> ;
204
205
} ,
205
206
} ,
206
207
{
207
- title : 'onPaste - MultiLineTextInput' ,
208
+ title : 'onPaste ( MultiLineTextInput) ' ,
208
209
render : function ( ) : React . Node {
209
210
return < OnPaste /> ;
210
211
} ,
0 commit comments