-
Notifications
You must be signed in to change notification settings - Fork 0
/
RichText.vr.js
48 lines (44 loc) · 1.09 KB
/
RichText.vr.js
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
import React from 'react'
import { View, Text } from 'react-vr'
import redraft from 'redraft'
const BLOCK_SPACING = 0.07
// Define callbacks for block and entity rendering.
// See: https://github.com/lokiuz/redraft
const renderers = {
inline: {},
blocks: {
unstyled: (children) => {
return (
<View style={{ flexDirection: 'column' }}>
{children.map(child => (
<Text
style={{
marginTop: BLOCK_SPACING / 2,
marginBottom: BLOCK_SPACING / 2,
}}
>
{child}
</Text>
))}
</View>
)
},
},
entities: {
// We don't actually want to render links in VR, but this code is here as an
// example for DOM rendering that will be implemented at some point.
LINK: (children) => <Text style={{ color: '#3af' }}>{children}</Text>
}
}
const RichText = ({ text }) => {
return (
<View
style={{
flexDirection: 'column',
}}
>
{redraft(text, renderers, { cleanup: false })}
</View>
)
}
export default RichText