|
@@ -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} from './const';
|
|
5
|
+import * as consts from './const';
|
5
|
6
|
|
6
|
7
|
const injectScript = `
|
7
|
8
|
(function () {
|
|
@@ -26,7 +27,19 @@ export default class RichTextEditor extends Component {
|
26
|
27
|
}
|
27
|
28
|
|
28
|
29
|
onBridgeMessage(message){
|
29
|
|
- console.log('RichTextEditor', 'bridge message: ', message);
|
|
30
|
+ // handle other callbacks
|
|
31
|
+ const json = JSON.parse(message);
|
|
32
|
+ if (json && json.type && json.type === consts.HTML_RESPONSE) {
|
|
33
|
+ if (this.resolve) {
|
|
34
|
+ this.resolve(json.data);
|
|
35
|
+ this.resolve = undefined;
|
|
36
|
+ this.reject = undefined;
|
|
37
|
+ if (this.pendingHtml) {
|
|
38
|
+ clearTimeout(this.pendingHtml);
|
|
39
|
+ this.pendingHtml = undefined;
|
|
40
|
+ }
|
|
41
|
+ }
|
|
42
|
+ }
|
30
|
43
|
}
|
31
|
44
|
|
32
|
45
|
onShouldStartLoadRequest(event) {
|
|
@@ -54,7 +67,7 @@ export default class RichTextEditor extends Component {
|
54
|
67
|
|
55
|
68
|
//-------------------------------------------------------------------------------
|
56
|
69
|
//--------------- Public API
|
57
|
|
-
|
|
70
|
+
|
58
|
71
|
setHTML(html) {
|
59
|
72
|
this._sendAction(actions.setHtml, html);
|
60
|
73
|
}
|
|
@@ -154,4 +167,23 @@ export default class RichTextEditor extends Component {
|
154
|
167
|
setOutdent() {
|
155
|
168
|
this._sendAction(actions.setOutdent);
|
156
|
169
|
}
|
|
170
|
+
|
|
171
|
+ setPlaceholder() {
|
|
172
|
+ this._sendAction(actions.setPlaceholder);
|
|
173
|
+ }
|
|
174
|
+
|
|
175
|
+ async getHtml() {
|
|
176
|
+ return new Promise((resolve, reject) => {
|
|
177
|
+ this.resolve = resolve;
|
|
178
|
+ this.reject = reject;
|
|
179
|
+ this._sendAction(actions.getHtml);
|
|
180
|
+
|
|
181
|
+ this.pendingHtml = setTimeout(() => {
|
|
182
|
+ if (this.reject) {
|
|
183
|
+ this.reject('timeout')
|
|
184
|
+ }
|
|
185
|
+ }, 5000);
|
|
186
|
+ });
|
|
187
|
+ }
|
|
188
|
+
|
157
|
189
|
}
|