-
Notifications
You must be signed in to change notification settings - Fork 66
Expand file tree
/
Copy pathImagesEditor.tsx
More file actions
69 lines (64 loc) · 1.95 KB
/
Copy pathImagesEditor.tsx
File metadata and controls
69 lines (64 loc) · 1.95 KB
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
import { EnrichedTextInput } from 'react-native-enriched-html';
import type { EnrichedTextInputInstance } from 'react-native-enriched-html';
import { useRef } from 'react';
import { View, StyleSheet, Pressable, Text } from 'react-native';
import { htmlStyle } from './htmlStyle';
export default function App() {
const ref = useRef<EnrichedTextInputInstance>(null);
const insertImage = () => {
// A real, loadable image. You supply the dimensions yourself - here we
// ask Lorem Picsum for a 320x160 photo and pass the proportionally down-scaled size.
ref.current?.setImage('https://picsum.photos/320/160', 160, 80);
};
const insertBrokenImage = () => {
// An unreachable source. The editor renders its static placeholder
// instead of failing, so you can see what a broken image looks like.
ref.current?.setImage('https://picsum.photos/does-not-exist', 160, 80);
};
return (
<View style={styles.container}>
<EnrichedTextInput
ref={ref}
style={styles.input}
htmlStyle={htmlStyle}
placeholder="Place the cursor, then insert an image below..."
/>
<View style={styles.row}>
<Pressable style={styles.button} onPress={insertImage}>
<Text style={styles.text}>Insert image</Text>
</Pressable>
<Pressable style={styles.button} onPress={insertBrokenImage}>
<Text style={styles.text}>Insert broken image</Text>
</Pressable>
</View>
</View>
);
}
const styles = StyleSheet.create({
container: { gap: 12 },
input: {
fontSize: 18,
color: '#232736',
padding: 12,
borderRadius: 12,
minHeight: 96,
backgroundColor: '#eef0ff',
},
row: {
flexDirection: 'row',
flexWrap: 'wrap',
justifyContent: 'center',
gap: 8,
},
button: {
padding: 8,
paddingHorizontal: 16,
borderRadius: 24,
borderWidth: 1,
borderColor: '#919fcf',
},
text: {
textAlign: 'center',
color: '#919fcf',
},
});