Skip to content

Commit ccdb59c

Browse files
committed
wip
1 parent d0c0076 commit ccdb59c

File tree

1 file changed

+56
-0
lines changed

1 file changed

+56
-0
lines changed

packages/rn-tester/js/examples/KeyboardEventsExample/KeyboardEventsExample.js

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import {
2121
Text,
2222
TextInput,
2323
View,
24+
// Image,
2425
} from 'react-native';
2526

2627
function formatKeyEvent(event: any) {
@@ -280,6 +281,55 @@ function KeyboardEventExample(): React.Node {
280281
);
281282
}
282283

284+
function OnPaste(): React.Node {
285+
// $FlowFixMe[missing-empty-array-annot]
286+
const [log, setLog] = React.useState([]);
287+
const appendLog = (line: string) => {
288+
const limit = 3;
289+
let newLog = log.slice(0, limit - 1);
290+
newLog.unshift(line);
291+
setLog(newLog);
292+
};
293+
const [imageUri, setImageUri] = React.useState(
294+
'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mP8z/C/HgAGgwJ/lK3Q6wAAAABJRU5ErkJggg==',
295+
);
296+
return (
297+
<>
298+
<TextInput
299+
multiline={true}
300+
style={styles.multiline}
301+
onPaste={(e: PasteEvent) => {
302+
appendLog(JSON.stringify(e.nativeEvent.dataTransfer.types));
303+
setImageUri(e.nativeEvent.dataTransfer.files[0].uri);
304+
}}
305+
pastedTypes={['string']}
306+
placeholder="MULTI LINE with onPaste() text from clipboard"
307+
/>
308+
<TextInput
309+
multiline={true}
310+
style={styles.multiline}
311+
onPaste={(e: PasteEvent) => {
312+
appendLog(JSON.stringify(e.nativeEvent.dataTransfer.types));
313+
setImageUri(e.nativeEvent.dataTransfer.files[0].uri);
314+
}}
315+
pastedTypes={['fileUrl', 'image', 'string']}
316+
placeholder="MULTI LINE with onPaste() for PNG/TIFF images from clipboard or fileUrl (via Finder) and text from clipboard"
317+
/>
318+
<Text style={{height: 30}}>{log.join('\n')}</Text>
319+
{/* <Image
320+
source={{uri: imageUri}}
321+
style={{
322+
width: 128,
323+
height: 128,
324+
margin: 4,
325+
borderWidth: 1,
326+
borderColor: 'white',
327+
}}
328+
/> */}
329+
</>
330+
);
331+
}
332+
283333
const styles = StyleSheet.create({
284334
eventLogBox: {
285335
padding: 10,
@@ -448,4 +498,10 @@ exports.examples = [
448498
return <KeyboardEventExample />;
449499
},
450500
},
501+
{
502+
title: 'onPaste',
503+
render: function (): React.Node {
504+
return <onPaste />;
505+
},
506+
},
451507
];

0 commit comments

Comments
 (0)