-
Notifications
You must be signed in to change notification settings - Fork 0
/
Editor.tsx
82 lines (77 loc) · 1.95 KB
/
Editor.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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
import React, { Component } from "react";
import { StyleSheet, TouchableOpacity, View, Text } from "react-native";
import WebView, { WebViewMessageEvent } from "react-native-webview";
import EditorHTML from "./html";
export default class Editor extends Component {
private _webview: React.RefObject<WebView>;
constructor(props: any) {
super(props);
this._webview = React.createRef();
}
handleFormat(format: string) {
console.log(format);
this._webview.current?.postMessage(format);
}
private onMessage = (event: WebViewMessageEvent) => {
console.log(event.nativeEvent.data);
};
render() {
return (
<View style={styles.container}>
<View style={styles.buttons}>
<TouchableOpacity
onPress={() => this.handleFormat("bold")}
style={styles.btn}
>
<Text>B</Text>
</TouchableOpacity>
<TouchableOpacity
onPress={() => this.handleFormat("italic")}
style={styles.btn}
>
<Text>I</Text>
</TouchableOpacity>
<TouchableOpacity
onPress={() => this.handleFormat("html")}
style={styles.btn}
>
<Text>Source</Text>
</TouchableOpacity>
</View>
<WebView
ref={this._webview}
style={styles.editor}
javaScriptEnabled={true}
source={{ html: EditorHTML }}
onMessage={this.onMessage}
/>
</View>
);
}
}
let styles = StyleSheet.create({
editor: {
flexGrow: 1,
borderWidth: 1,
},
container: {
margin: 10,
flexGrow: 1,
flexDirection: "column",
alignItems: "stretch",
justifyContent: "flex-start",
},
buttons: {
marginBottom: 10,
flexDirection: "row",
alignItems: "center",
justifyContent: "center",
},
btn: {
alignItems: "center",
backgroundColor: "#5E8D48",
padding: 5,
margin: 3,
minWidth: 70,
},
});