-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathApp.tsx
62 lines (54 loc) · 1.66 KB
/
App.tsx
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
import React from 'react';
import { StyleSheet, ScrollView, View, Text } from 'react-native';
import { createEditorJsViewer } from './src/config/createEditorJsViewer';
import { IComponentBlockProps } from './src/types/createEditorJsViewerProps';
import data from './data.json';
interface IPopcornBlockData {
text: string;
emoji: string;
}
const PopcornBlock = ({ block, containerStyle }: IComponentBlockProps<IPopcornBlockData>) => {
return (
<View style={[containerStyle, { marginVertical: 8 }]}>
<Text style={{ fontSize: 20 }}>{block.data.emoji}</Text>
<Text style={{ color: 'green', fontSize: 20 }}>{block.data.text}</Text>
</View>
);
};
interface IRandomColeredTextData {
text: string;
}
const RandomColeredTextBlock = ({ block, containerStyle }: IComponentBlockProps<IRandomColeredTextData>) => {
const randomColor = `#${Math.floor(Math.random()*16777215).toString(16)}`;
return (
<Text style={[containerStyle, { marginVertical: 8, fontSize: 20, color: randomColor }]}>{block.data.text}</Text>
);
};
const EditorJsViewerNative = createEditorJsViewer({
customTools: {
// popcorn: { // This can be any name
// Component: PopcornBlock
// },
// randomColeredText: { // This can be any name
// Component: RandomColeredTextBlock
// },
}
});
export default function App() {
return (
<ScrollView style={{ flex: 1 }}>
<View style={styles.container}>
<EditorJsViewerNative data={data} />
</View>
</ScrollView>
);
}
const styles = StyleSheet.create({
container: {
flex: 1,
marginTop: 50,
paddingHorizontal: 16,
alignItems: 'center',
justifyContent: 'center',
},
});