-
Notifications
You must be signed in to change notification settings - Fork 66
Expand file tree
/
Copy pathMentionEditor.tsx
More file actions
54 lines (49 loc) · 1.36 KB
/
Copy pathMentionEditor.tsx
File metadata and controls
54 lines (49 loc) · 1.36 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
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';
const user = { id: '1', name: 'John' };
export default function App() {
const ref = useRef<EnrichedTextInputInstance>(null);
const insertMention = () => {
// Replaces the active '@' mention the user has started by typing '@'.
ref.current?.setMention('@', `@${user.name}`, { id: user.id });
};
return (
<View style={styles.container}>
<EnrichedTextInput
ref={ref}
style={styles.input}
htmlStyle={htmlStyle}
placeholder="Type '@', then tap the button below..."
/>
<Pressable style={styles.button} onPress={insertMention}>
<Text style={styles.text}>@{user.name}</Text>
</Pressable>
</View>
);
}
const styles = StyleSheet.create({
container: { gap: 12 },
input: {
fontSize: 18,
color: '#232736',
padding: 12,
borderRadius: 12,
minHeight: 96,
backgroundColor: '#eef0ff',
},
button: {
alignSelf: 'center',
padding: 8,
paddingHorizontal: 16,
borderRadius: 24,
borderWidth: 1,
borderColor: '#919fcf',
},
text: {
textAlign: 'center',
color: '#919fcf',
},
});