-
Notifications
You must be signed in to change notification settings - Fork 67
Expand file tree
/
Copy pathTextRenderer.tsx
More file actions
69 lines (62 loc) · 1.62 KB
/
Copy pathTextRenderer.tsx
File metadata and controls
69 lines (62 loc) · 1.62 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 { Alert, StyleSheet, View } from 'react-native';
import {
EnrichedText,
type OnLinkPressEvent,
type OnMentionPressEvent,
type OnImagePressEvent,
} from 'react-native-enriched-html';
import { enrichedTextHtmlStyle } from '../constants/editorConfig';
interface TextRendererProps {
nodes: Array<string>;
}
export const TextRenderer = ({ nodes }: TextRendererProps) => {
const handleLinkPress = (e: OnLinkPressEvent) => {
Alert.alert('Link Pressed', `You pressed the link: ${e.url}`);
};
const handleMentionPress = (e: OnMentionPressEvent) => {
Alert.alert(
'Mention Pressed',
`You pressed the mention: text: ${e.text}, type: ${e.indicator}, attributes: ${JSON.stringify(e.attributes)}`
);
};
const handleImagePress = (e: OnImagePressEvent) => {
Alert.alert(
'Image Pressed',
`You pressed the image: ${JSON.stringify(e.image)}`
);
};
if (nodes.length === 0) {
return null;
}
return (
<View style={styles.container}>
{nodes.map((node, index) => (
<EnrichedText
key={index}
style={styles.text}
htmlStyle={enrichedTextHtmlStyle}
onLinkPress={handleLinkPress}
onMentionPress={handleMentionPress}
onImagePress={handleImagePress}
>
{node}
</EnrichedText>
))}
</View>
);
};
const styles = StyleSheet.create({
container: {
width: '100%',
padding: 16,
borderWidth: StyleSheet.hairlineWidth,
marginVertical: 16,
borderRadius: 8,
},
text: {
fontSize: 18,
color: 'black',
marginTop: 4,
fontFamily: 'Nunito-Regular',
},
});