Procházet zdrojové kódy

Removed waiting a second hack

Yedidya Kennard před 8 roky
rodič
revize
fc1c1782b9

+ 53
- 0
example/app.js Zobrazit soubor

@@ -0,0 +1,53 @@
1
+import React, { Component } from 'react';
2
+import {
3
+    StyleSheet,
4
+    Text,
5
+    View
6
+} from 'react-native';
7
+import RichTextEditor from 'react-native-ZSSRichTextEditor'
8
+
9
+export default class RichTextExample extends Component {
10
+
11
+  constructor(props) {
12
+    super(props);
13
+    this.getHTML = this.getHTML.bind(this);
14
+  }
15
+
16
+  render() {
17
+    return (
18
+        <View style={styles.container}>
19
+          <RichTextEditor
20
+              ref={(r)=>this.richtext = r}
21
+              style={styles.richText}
22
+              initialHTML={'Hello <b>World</b> <p>this is a new paragraph</p> <p>this is another new paragraph</p>'}
23
+          />
24
+        </View>
25
+    );
26
+  }
27
+
28
+  async getHTML() {
29
+    const html = await this.richtext.getHtml();
30
+  }
31
+
32
+  componentDidMount() {
33
+
34
+    setTimeout(()=>{
35
+      this.getHTML();
36
+    }, 3000);
37
+  }
38
+}
39
+
40
+const styles = StyleSheet.create({
41
+  container: {
42
+    flex: 1,
43
+    flexDirection: 'column',
44
+    backgroundColor: '#F5FCFF',
45
+    paddingTop: 40
46
+  },
47
+  richText: {
48
+    alignItems:'center',
49
+    justifyContent: 'center',
50
+    backgroundColor: 'transparent',
51
+  },
52
+});
53
+

+ 3
- 55
example/index.android.js Zobrazit soubor

@@ -1,56 +1,4 @@
1
-import React, { Component } from 'react';
2
-import {
3
-    AppRegistry,
4
-    StyleSheet,
5
-    Text,
6
-    View
7
-} from 'react-native';
8
-import RichTextEditor from 'react-native-ZSSRichTextEditor'
1
+import RichTextExample from './app';
2
+import {AppRegistry} from 'react-native';
9 3
 
10
-class RichTextExample extends Component {
11
-
12
-  constructor(props) {
13
-    super(props);
14
-    this.getHTML = this.getHTML.bind(this);
15
-  }
16
-
17
-  render() {
18
-    return (
19
-        <View style={styles.container}>
20
-          <RichTextEditor
21
-              ref={(r)=>this.richtext = r}
22
-              style={styles.richText}
23
-              initialHTML={'Hello <b>World</b> <p>this is a new paragraph</p>'}
24
-          />
25
-        </View>
26
-    );
27
-  }
28
-
29
-  async getHTML() {
30
-    const html = await this.richtext.getHtml();
31
-    alert(html);
32
-  }
33
-
34
-  componentDidMount() {
35
-
36
-    setTimeout(()=>{
37
-      this.getHTML();
38
-    }, 3000);
39
-  }
40
-}
41
-
42
-const styles = StyleSheet.create({
43
-  container: {
44
-    flex: 1,
45
-    flexDirection: 'column',
46
-    backgroundColor: '#F5FCFF',
47
-    paddingTop: 40
48
-  },
49
-  richText: {
50
-    alignItems:'center',
51
-    justifyContent: 'center',
52
-    backgroundColor: 'transparent',
53
-  },
54
-});
55
-
56
-AppRegistry.registerComponent('example', () => RichTextExample);
4
+AppRegistry.registerComponent('example', () => RichTextExample);

+ 3
- 55
example/index.ios.js Zobrazit soubor

@@ -1,56 +1,4 @@
1
-import React, { Component } from 'react';
2
-import {
3
-  AppRegistry,
4
-  StyleSheet,
5
-  Text,
6
-  View
7
-} from 'react-native';
8
-import RichTextEditor from 'react-native-ZSSRichTextEditor'
1
+import RichTextExample from './app';
2
+import {AppRegistry} from 'react-native';
9 3
 
10
-class RichTextExample extends Component {
11
-
12
-  constructor(props) {
13
-    super(props);
14
-    this.getHTML = this.getHTML.bind(this);
15
-  }
16
-
17
-  render() {
18
-    return (
19
-      <View style={styles.container}>
20
-        <RichTextEditor
21
-          ref={(r)=>this.richtext = r}
22
-          style={styles.richText}
23
-          initialHTML={'Hello <b>World</b> <p>this is a new paragraph</p>'}
24
-        />
25
-      </View>
26
-    );
27
-  }
28
-
29
-  async getHTML() {
30
-    const html = await this.richtext.getHtml();
31
-    alert(html);
32
-  }
33
-
34
-  componentDidMount() {
35
-
36
-    setTimeout(()=>{
37
-      this.getHTML();
38
-    }, 3000);
39
-  }
40
-}
41
-
42
-const styles = StyleSheet.create({
43
-  container: {
44
-    flex: 1,
45
-    flexDirection: 'column',
46
-    backgroundColor: '#F5FCFF',
47
-    paddingTop: 40
48
-  },
49
-  richText: {
50
-    alignItems:'center',
51
-    justifyContent: 'center',
52
-    backgroundColor: 'transparent',
53
-  },
54
-});
55
-
56
-AppRegistry.registerComponent('example', () => RichTextExample);
4
+AppRegistry.registerComponent('example', () => RichTextExample);

+ 22
- 18
src/RichTextEditor.js Zobrazit soubor

@@ -1,8 +1,7 @@
1 1
 import React, {Component, PropTypes} from 'react';
2 2
 import WebViewBridge from 'react-native-webview-bridge-updated';
3 3
 import {InjectedMessageHandler} from './WebviewMessageHandler';
4
-import {actions} from './const';
5
-import * as consts from './const';
4
+import {actions, messages} from './const';
6 5
 
7 6
 const injectScript = `
8 7
   (function () {
@@ -20,24 +19,29 @@ export default class RichTextEditor extends Component {
20 19
     this._sendAction = this._sendAction.bind(this);
21 20
   }
22 21
 
23
-  componentDidMount() {
24
-    setTimeout(() => {
25
-      this.setHTML(this.props.initialHTML);
26
-    }, 1000);
27
-  }
28
-
29 22
   onBridgeMessage(message){
30
-    const json = JSON.parse(message);
31
-    if (json && json.type && json.type === consts.HTML_RESPONSE) {
32
-      if (this.resolve) {
33
-        this.resolve(json.data);
34
-        this.resolve = undefined;
35
-        this.reject = undefined;
36
-        if (this.pendingHtml) {
37
-          clearTimeout(this.pendingHtml);
38
-          this.pendingHtml = undefined;
39
-        }
23
+    try {
24
+      const json = JSON.parse(message);
25
+
26
+      switch (json.type) {
27
+        case messages.HTML_RESPONSE:
28
+          if (this.resolve) {
29
+            this.resolve(json.data);
30
+            this.resolve = undefined;
31
+            this.reject = undefined;
32
+            if (this.pendingHtml) {
33
+              clearTimeout(this.pendingHtml);
34
+              this.pendingHtml = undefined;
35
+            }
36
+          }
37
+          break;
38
+        case messages.ZSS_INITIALIZED:
39
+          this.setHTML(this.props.initialHTML);
40
+          break;
40 41
       }
42
+
43
+    } catch(e) {
44
+      //alert('NON JSON MESSAGE');
41 45
     }
42 46
   }
43 47
 

+ 2
- 3
src/WebviewMessageHandler.js Zobrazit soubor

@@ -1,5 +1,4 @@
1
-import {actions} from './const';
2
-import * as consts from './const';
1
+import {actions, messages} from './const';
3 2
 
4 3
 export const InjectedMessageHandler = `
5 4
   if (WebViewBridge) {
@@ -86,7 +85,7 @@ export const InjectedMessageHandler = `
86 85
           break;
87 86
         case '${actions.getHtml}':
88 87
           const html = zss_editor.getHTML();
89
-          WebViewBridge.send(JSON.stringify({type: '${consts.HTML_RESPONSE}', data: html}));
88
+          WebViewBridge.send(JSON.stringify({type: '${messages.HTML_RESPONSE}', data: html}));
90 89
           break;
91 90
       }
92 91
     };

+ 5
- 0
src/ZSSRichTextEditor/ZSSRichTextEditor.js Zobrazit soubor

@@ -71,6 +71,11 @@ zss_editor.init = function() {
71 71
                  zss_editor.focusEditor();
72 72
                  }
73 73
                  });
74
+
75
+
76
+    setTimeout(function() {
77
+        WebViewBridge.send(JSON.stringify({type: 'ZSS_INITIALIZED'}))
78
+    }, 20);
74 79
     
75 80
 }//end
76 81
 

+ 4
- 1
src/const.js Zobrazit soubor

@@ -28,4 +28,7 @@ export const actions = {
28 28
   setPlaceholder: 'SET_PLACEHOLDER'
29 29
 };
30 30
 
31
-export const HTML_RESPONSE = 'HTML_RESPONSE';
31
+export const messages = {
32
+  HTML_RESPONSE : 'HTML_RESPONSE',
33
+  ZSS_INITIALIZED: 'ZSS_INITIALIZED'
34
+}

+ 1
- 1
src/editor.html Zobrazit soubor

@@ -8,7 +8,7 @@
8 8
 		<!-- JSBeautifier Source for ZSSRichTextEditor -->
9 9
 		<script type="text/javascript" src="ZSSRichTextEditor/JSBeautifier.js"></script>
10 10
 		<!-- Javascript for ZSSRichTextEditor -->
11
-        <script type="text/javascript" src="ZSSRichTextEditor/ZSSRichTextEditor.js"></script>
11
+		<script type="text/javascript" src="ZSSRichTextEditor/ZSSRichTextEditor.js"></script>
12 12
 		<!-- CSS Styles for ZSSRichTextEditor -->
13 13
 		<link rel="stylesheet" type="text/css" href="ZSSRichTextEditor/style.css">
14 14
 	</head>