|
@@ -2,6 +2,7 @@ import React, {Component, PropTypes} from 'react';
|
2
|
2
|
import WebViewBridge from 'react-native-webview-bridge-updated';
|
3
|
3
|
import {InjectedMessageHandler} from './WebviewMessageHandler';
|
4
|
4
|
import {actions, messages} from './const';
|
|
5
|
+import {Modal, View, Text, StyleSheet, TextInput, TouchableOpacity} from 'react-native';
|
5
|
6
|
|
6
|
7
|
const injectScript = `
|
7
|
8
|
(function () {
|
|
@@ -22,7 +23,10 @@ export default class RichTextEditor extends Component {
|
22
|
23
|
this.registerToolbar = this.registerToolbar.bind(this);
|
23
|
24
|
this.onBridgeMessage = this.onBridgeMessage.bind(this);
|
24
|
25
|
this.state = {
|
25
|
|
- listeners: []
|
|
26
|
+ listeners: [],
|
|
27
|
+ showLinkDialog: false,
|
|
28
|
+ linkTitle: '',
|
|
29
|
+ linkUrl: ''
|
26
|
30
|
};
|
27
|
31
|
}
|
28
|
32
|
|
|
@@ -80,16 +84,91 @@ export default class RichTextEditor extends Component {
|
80
|
84
|
}
|
81
|
85
|
}
|
82
|
86
|
|
|
87
|
+ _renderLinkModal() {
|
|
88
|
+ return (
|
|
89
|
+ <Modal
|
|
90
|
+ animationType={"fade"}
|
|
91
|
+ transparent
|
|
92
|
+ visible={this.state.showLinkDialog}
|
|
93
|
+ onRequestClose={() => this.setState({showLinkDialog: false})}
|
|
94
|
+ >
|
|
95
|
+ <View style={styles.modal}>
|
|
96
|
+
|
|
97
|
+
|
|
98
|
+ <View style={styles.innerModal}>
|
|
99
|
+
|
|
100
|
+ <Text>Title</Text>
|
|
101
|
+ <View style={styles.inputWrapper}>
|
|
102
|
+ <TextInput
|
|
103
|
+ style={{height: 20}}
|
|
104
|
+ onChangeText={(text) => this.setState({linkTitle: text})}
|
|
105
|
+ value={this.state.linkTitle}
|
|
106
|
+ />
|
|
107
|
+ </View>
|
|
108
|
+
|
|
109
|
+ <Text style={{marginTop: 10}}>URL</Text>
|
|
110
|
+ <View style={styles.inputWrapper}>
|
|
111
|
+ <TextInput
|
|
112
|
+ style={{height: 20}}
|
|
113
|
+ onChangeText={(text) => this.setState({linkUrl: text})}
|
|
114
|
+ value={this.state.linkUrl}
|
|
115
|
+ />
|
|
116
|
+ </View>
|
|
117
|
+
|
|
118
|
+ {this._renderModalButtons()}
|
|
119
|
+ </View>
|
|
120
|
+ </View>
|
|
121
|
+ </Modal>
|
|
122
|
+ );
|
|
123
|
+ }
|
|
124
|
+
|
|
125
|
+ _hideModal() {
|
|
126
|
+ this.setState({
|
|
127
|
+ showLinkDialog: false,
|
|
128
|
+ linkTitle: '',
|
|
129
|
+ linkUrl: ''
|
|
130
|
+ })
|
|
131
|
+ }
|
|
132
|
+
|
|
133
|
+ _renderModalButtons() {
|
|
134
|
+ return (
|
|
135
|
+ <View style={{paddingTop: 10, alignSelf: 'stretch', flexDirection: 'row'}}>
|
|
136
|
+ <View style={{flex: 1}}/>
|
|
137
|
+ <TouchableOpacity
|
|
138
|
+ onPress={() => this._hideModal()}
|
|
139
|
+ >
|
|
140
|
+ <Text style={[styles.button, {paddingRight: 10}]}>
|
|
141
|
+ Cancel
|
|
142
|
+ </Text>
|
|
143
|
+ </TouchableOpacity>
|
|
144
|
+ <TouchableOpacity
|
|
145
|
+ onPress={() => {
|
|
146
|
+ this.insertLink(this.state.linkUrl, this.state.linkTitle);
|
|
147
|
+ this._hideModal();
|
|
148
|
+ }}
|
|
149
|
+ >
|
|
150
|
+ <Text style={styles.button}>
|
|
151
|
+ OK
|
|
152
|
+ </Text>
|
|
153
|
+ </TouchableOpacity>
|
|
154
|
+ </View>
|
|
155
|
+ );
|
|
156
|
+ }
|
|
157
|
+
|
83
|
158
|
render() {
|
84
|
159
|
return (
|
85
|
|
- <WebViewBridge
|
86
|
|
- {...this.props}
|
87
|
|
- hideKeyboardAccessoryView={true}
|
88
|
|
- ref={(r) => {this.webviewBridge = r}}
|
89
|
|
- onBridgeMessage={(message) => this.onBridgeMessage(message)}
|
90
|
|
- injectedJavaScript={injectScript}
|
91
|
|
- source={require('./editor.html')}
|
92
|
|
- />
|
|
160
|
+ <View style={{flex: 1}}>
|
|
161
|
+ <WebViewBridge
|
|
162
|
+ style={{flex: 1}}
|
|
163
|
+ {...this.props}
|
|
164
|
+ hideKeyboardAccessoryView={true}
|
|
165
|
+ ref={(r) => {this.webviewBridge = r}}
|
|
166
|
+ onBridgeMessage={(message) => this.onBridgeMessage(message)}
|
|
167
|
+ injectedJavaScript={injectScript}
|
|
168
|
+ source={require('./editor.html')}
|
|
169
|
+ />
|
|
170
|
+ {this._renderLinkModal()}
|
|
171
|
+ </View>
|
93
|
172
|
);
|
94
|
173
|
}
|
95
|
174
|
|
|
@@ -114,9 +193,15 @@ export default class RichTextEditor extends Component {
|
114
|
193
|
//-------------------------------------------------------------------------------
|
115
|
194
|
//--------------- Public API
|
116
|
195
|
|
|
196
|
+ showLinkDialog() {
|
|
197
|
+ this.setState({
|
|
198
|
+ showLinkDialog: true
|
|
199
|
+ });
|
|
200
|
+ }
|
|
201
|
+
|
117
|
202
|
focusTitle() {
|
118
|
203
|
this._sendAction(actions.focusTitle);
|
119
|
|
- }wewe
|
|
204
|
+ }
|
120
|
205
|
|
121
|
206
|
focusContent() {
|
122
|
207
|
this._sendAction(actions.focusContent);
|
|
@@ -213,6 +298,7 @@ export default class RichTextEditor extends Component {
|
213
|
298
|
}
|
214
|
299
|
|
215
|
300
|
insertLink(url, title) {
|
|
301
|
+
|
216
|
302
|
this._sendAction(actions.insertLink, {url, title});
|
217
|
303
|
}
|
218
|
304
|
|
|
@@ -252,6 +338,14 @@ export default class RichTextEditor extends Component {
|
252
|
338
|
this._sendAction(actions.setContentPlaceholder);
|
253
|
339
|
}
|
254
|
340
|
|
|
341
|
+ prepareInsert() {
|
|
342
|
+ this._sendAction(actions.prepareInsert);
|
|
343
|
+ }
|
|
344
|
+
|
|
345
|
+ restoreSelection() {
|
|
346
|
+ this._sendAction(actions.restoreSelection);
|
|
347
|
+ }
|
|
348
|
+
|
255
|
349
|
async getTitleHtml() {
|
256
|
350
|
return new Promise((resolve, reject) => {
|
257
|
351
|
this.titleResolve = resolve;
|
|
@@ -289,4 +383,28 @@ export default class RichTextEditor extends Component {
|
289
|
383
|
this.contentFocusHandler = callbackHandler;
|
290
|
384
|
this._sendAction(actions.setContentFocusHandler);
|
291
|
385
|
}
|
292
|
|
-}
|
|
386
|
+}
|
|
387
|
+
|
|
388
|
+const styles = StyleSheet.create({
|
|
389
|
+ modal: {
|
|
390
|
+ flex: 1,
|
|
391
|
+ justifyContent: 'center',
|
|
392
|
+ alignItems: 'center',
|
|
393
|
+ backgroundColor: 'rgba(0, 0, 0, 0.5)'
|
|
394
|
+ },
|
|
395
|
+ innerModal: {
|
|
396
|
+ backgroundColor: '#ffffff',
|
|
397
|
+ padding: 20,
|
|
398
|
+ alignSelf: 'stretch',
|
|
399
|
+ margin: 40
|
|
400
|
+ },
|
|
401
|
+ button: {
|
|
402
|
+ fontSize: 16
|
|
403
|
+ },
|
|
404
|
+ inputWrapper: {
|
|
405
|
+ marginTop: 10,
|
|
406
|
+ marginBottom: 10,
|
|
407
|
+ borderBottomColor: '#000000',
|
|
408
|
+ borderBottomWidth: 1
|
|
409
|
+ }
|
|
410
|
+});
|