|
@@ -1,17 +1,10 @@
|
1
|
1
|
import React, {Component} from 'react';
|
2
|
2
|
import PropTypes from 'prop-types';
|
3
|
|
-// import WebViewBridge from 'react-native-webview-bridge-updated';
|
4
|
3
|
import WebView from 'react-native-webview';
|
5
|
4
|
import {MessageConverter} from './WebviewMessageHandler';
|
6
|
5
|
import {actions, messages} from './const';
|
7
|
6
|
import {Modal, View, Text, StyleSheet, TextInput, TouchableOpacity, Platform, PixelRatio, Keyboard, Dimensions} from 'react-native';
|
8
|
7
|
|
9
|
|
-// const injectScript = `
|
10
|
|
-// (function () {
|
11
|
|
-// ${InjectedMessageHandler}
|
12
|
|
-// }());
|
13
|
|
-// `;
|
14
|
|
-
|
15
|
8
|
const PlatformIOS = Platform.OS === 'ios';
|
16
|
9
|
|
17
|
10
|
export default class RichTextEditor extends Component {
|
|
@@ -43,7 +36,7 @@ export default class RichTextEditor extends Component {
|
43
|
36
|
this.state = {
|
44
|
37
|
selectionChangeListeners: [],
|
45
|
38
|
onChange: [],
|
46
|
|
- showLinkDialog: false,
|
|
39
|
+ isShowLinkDialog: false,
|
47
|
40
|
linkInitialUrl: '',
|
48
|
41
|
linkTitle: '',
|
49
|
42
|
linkUrl: '',
|
|
@@ -160,7 +153,6 @@ export default class RichTextEditor extends Component {
|
160
|
153
|
|
161
|
154
|
break;
|
162
|
155
|
case messages.LINK_TOUCHED:
|
163
|
|
- this.prepareInsert();
|
164
|
156
|
const {title, url} = message.data;
|
165
|
157
|
this.showLinkDialog(title, url);
|
166
|
158
|
break;
|
|
@@ -202,16 +194,17 @@ export default class RichTextEditor extends Component {
|
202
|
194
|
}
|
203
|
195
|
|
204
|
196
|
_renderLinkModal() {
|
|
197
|
+ const {linkOption} = this.props;
|
205
|
198
|
return (
|
206
|
199
|
<Modal
|
207
|
200
|
animationType={"fade"}
|
208
|
201
|
transparent
|
209
|
|
- visible={this.state.showLinkDialog}
|
210
|
|
- onRequestClose={() => this.setState({showLinkDialog: false})}
|
|
202
|
+ visible={this.state.isShowLinkDialog}
|
|
203
|
+ onRequestClose={() => this.setState({isShowLinkDialog: false})}
|
211
|
204
|
>
|
212
|
205
|
<View style={styles.modal}>
|
213
|
206
|
<View style={[styles.innerModal, {marginBottom: PlatformIOS ? this.state.keyboardHeight : 0}]}>
|
214
|
|
- <Text style={styles.inputTitle}>Title</Text>
|
|
207
|
+ <Text style={styles.inputTitle}>{linkOption.titleText}</Text>
|
215
|
208
|
<View style={styles.inputWrapper}>
|
216
|
209
|
<TextInput
|
217
|
210
|
style={styles.input}
|
|
@@ -219,7 +212,7 @@ export default class RichTextEditor extends Component {
|
219
|
212
|
value={this.state.linkTitle}
|
220
|
213
|
/>
|
221
|
214
|
</View>
|
222
|
|
- <Text style={[styles.inputTitle ,{marginTop: 10}]}>URL</Text>
|
|
215
|
+ <Text style={[styles.inputTitle ,{marginTop: 10}]}>{linkOption.urlText}</Text>
|
223
|
216
|
<View style={styles.inputWrapper}>
|
224
|
217
|
<TextInput
|
225
|
218
|
style={styles.input}
|
|
@@ -240,7 +233,7 @@ export default class RichTextEditor extends Component {
|
240
|
233
|
|
241
|
234
|
_hideModal() {
|
242
|
235
|
this.setState({
|
243
|
|
- showLinkDialog: false,
|
|
236
|
+ isShowLinkDialog: false,
|
244
|
237
|
linkInitialUrl: '',
|
245
|
238
|
linkTitle: '',
|
246
|
239
|
linkUrl: ''
|
|
@@ -251,6 +244,7 @@ export default class RichTextEditor extends Component {
|
251
|
244
|
const insertUpdateDisabled = this.state.linkTitle.trim().length <= 0 || this.state.linkUrl.trim().length <= 0;
|
252
|
245
|
const containerPlatformStyle = PlatformIOS ? {justifyContent: 'space-between'} : {paddingTop: 15};
|
253
|
246
|
const buttonPlatformStyle = PlatformIOS ? {flex: 1, height: 45, justifyContent: 'center'} : {};
|
|
247
|
+ const { linkOption } = this.props;
|
254
|
248
|
return (
|
255
|
249
|
<View style={[{alignSelf: 'stretch', flexDirection: 'row'}, containerPlatformStyle]}>
|
256
|
250
|
{!PlatformIOS && <View style={{flex: 1}}/>}
|
|
@@ -259,7 +253,7 @@ export default class RichTextEditor extends Component {
|
259
|
253
|
style={buttonPlatformStyle}
|
260
|
254
|
>
|
261
|
255
|
<Text style={[styles.button, {paddingRight: 10}]}>
|
262
|
|
- {this._upperCaseButtonTextIfNeeded('Cancel')}
|
|
256
|
+ {linkOption.cancelText}
|
263
|
257
|
</Text>
|
264
|
258
|
</TouchableOpacity>
|
265
|
259
|
<TouchableOpacity
|
|
@@ -275,7 +269,7 @@ export default class RichTextEditor extends Component {
|
275
|
269
|
style={buttonPlatformStyle}
|
276
|
270
|
>
|
277
|
271
|
<Text style={[styles.button, {opacity: insertUpdateDisabled ? 0.5 : 1}]}>
|
278
|
|
- {this._upperCaseButtonTextIfNeeded(this._linkIsNew() ? 'Insert' : 'Update')}
|
|
272
|
+ {this._linkIsNew() ? linkOption.insertText : linkOption.updateText}
|
279
|
273
|
</Text>
|
280
|
274
|
</TouchableOpacity>
|
281
|
275
|
</View>
|
|
@@ -286,10 +280,6 @@ export default class RichTextEditor extends Component {
|
286
|
280
|
return !this.state.linkInitialUrl;
|
287
|
281
|
}
|
288
|
282
|
|
289
|
|
- _upperCaseButtonTextIfNeeded(buttonText) {
|
290
|
|
- return PlatformIOS ? buttonText : buttonText.toUpperCase();
|
291
|
|
- }
|
292
|
|
-
|
293
|
283
|
render() {
|
294
|
284
|
//in release build, external html files in Android can't be required, so they must be placed in the assets folder and accessed via uri
|
295
|
285
|
const pageSource = PlatformIOS ? require('./editor.html') : { uri: 'file:///android_asset/editor.html' };
|
|
@@ -301,7 +291,6 @@ export default class RichTextEditor extends Component {
|
301
|
291
|
keyboardDisplayRequiresUserAction={false}
|
302
|
292
|
ref={(r) => {this.webview = r}}
|
303
|
293
|
onMessage={(message) => this.onMessage(message)}
|
304
|
|
- // injectedJavaScript={injectScript}
|
305
|
294
|
source={pageSource}
|
306
|
295
|
onLoad={() => this.init()}
|
307
|
296
|
/>
|
|
@@ -310,23 +299,9 @@ export default class RichTextEditor extends Component {
|
310
|
299
|
);
|
311
|
300
|
}
|
312
|
301
|
|
313
|
|
- escapeJSONString = function(string) {
|
314
|
|
- return string
|
315
|
|
- .replace(/[\\]/g, '\\\\')
|
316
|
|
- .replace(/[\"]/g, '\\\"')
|
317
|
|
- .replace(/[\']/g, '\\\'')
|
318
|
|
- .replace(/[\/]/g, '\\/')
|
319
|
|
- .replace(/[\b]/g, '\\b')
|
320
|
|
- .replace(/[\f]/g, '\\f')
|
321
|
|
- .replace(/[\n]/g, '\\n')
|
322
|
|
- .replace(/[\r]/g, '\\r')
|
323
|
|
- .replace(/[\t]/g, '\\t');
|
324
|
|
- };
|
325
|
|
-
|
326
|
302
|
_sendAction(action, data) {
|
327
|
303
|
let jsToBeExecutedOnPage = MessageConverter({ type: action, data });
|
328
|
|
-
|
329
|
|
- console.log(jsToBeExecutedOnPage)
|
|
304
|
+ console.log(jsToBeExecutedOnPage + ';true;')
|
330
|
305
|
this.webview.injectJavaScript(jsToBeExecutedOnPage + ';true;');
|
331
|
306
|
}
|
332
|
307
|
|
|
@@ -334,11 +309,12 @@ export default class RichTextEditor extends Component {
|
334
|
309
|
//--------------- Public API
|
335
|
310
|
|
336
|
311
|
showLinkDialog(optionalTitle = '', optionalUrl = '') {
|
|
312
|
+ this.prepareInsert();
|
337
|
313
|
this.setState({
|
338
|
314
|
linkInitialUrl: optionalUrl,
|
339
|
315
|
linkTitle: optionalTitle,
|
340
|
316
|
linkUrl: optionalUrl,
|
341
|
|
- showLinkDialog: true
|
|
317
|
+ isShowLinkDialog: true
|
342
|
318
|
});
|
343
|
319
|
}
|
344
|
320
|
|