浏览代码

Added scroll and log callbacks

Yedidya Kennard 8 年前
父节点
当前提交
b39bfc4d1a
共有 4 个文件被更改,包括 17 次插入7 次删除
  1. 1
    0
      example/android/app/src/main/AndroidManifest.xml
  2. 10
    4
      src/RichTextEditor.js
  3. 3
    2
      src/ZSSRichTextEditor/ZSSRichTextEditor.js
  4. 3
    1
      src/const.js

+ 1
- 0
example/android/app/src/main/AndroidManifest.xml 查看文件

18
       android:theme="@style/AppTheme">
18
       android:theme="@style/AppTheme">
19
       <activity
19
       <activity
20
         android:name=".MainActivity"
20
         android:name=".MainActivity"
21
+        android:windowSoftInputMode="adjustResize"
21
         android:label="@string/app_name"
22
         android:label="@string/app_name"
22
         android:configChanges="keyboard|keyboardHidden|orientation|screenSize">
23
         android:configChanges="keyboard|keyboardHidden|orientation|screenSize">
23
         <intent-filter>
24
         <intent-filter>

+ 10
- 4
src/RichTextEditor.js 查看文件

19
     this._sendAction = this._sendAction.bind(this);
19
     this._sendAction = this._sendAction.bind(this);
20
   }
20
   }
21
 
21
 
22
-  onBridgeMessage(message){
22
+  onBridgeMessage(str){
23
     try {
23
     try {
24
-      const json = JSON.parse(message);
24
+      const message = JSON.parse(str);
25
 
25
 
26
-      switch (json.type) {
26
+      switch (message.type) {
27
         case messages.HTML_RESPONSE:
27
         case messages.HTML_RESPONSE:
28
           if (this.resolve) {
28
           if (this.resolve) {
29
-            this.resolve(json.data);
29
+            this.resolve(message.data);
30
             this.resolve = undefined;
30
             this.resolve = undefined;
31
             this.reject = undefined;
31
             this.reject = undefined;
32
             if (this.pendingHtml) {
32
             if (this.pendingHtml) {
38
         case messages.ZSS_INITIALIZED:
38
         case messages.ZSS_INITIALIZED:
39
           this.setHTML(this.props.initialHTML);
39
           this.setHTML(this.props.initialHTML);
40
           break;
40
           break;
41
+        case messages.LOG:
42
+          console.log('FROM ZSS', message.data);
43
+          break;
44
+        case messages.SCROLL:
45
+          this.webviewBridge.setNativeProps({contentOffset: {y: message.data}});
46
+          break;
41
       }
47
       }
42
 
48
 
43
     } catch(e) {
49
     } catch(e) {

+ 3
- 2
src/ZSSRichTextEditor/ZSSRichTextEditor.js 查看文件

38
  */
38
  */
39
 zss_editor.init = function() {
39
 zss_editor.init = function() {
40
 
40
 
41
+
41
     $('#zss_editor_content').on('touchend', function(e) {
42
     $('#zss_editor_content').on('touchend', function(e) {
42
                                 zss_editor.enabledEditingItems(e);
43
                                 zss_editor.enabledEditingItems(e);
43
                                 var clicked = $(e.target);
44
                                 var clicked = $(e.target);
103
 
104
 
104
 // This will show up in the XCode console as we are able to push this into an NSLog.
105
 // This will show up in the XCode console as we are able to push this into an NSLog.
105
 zss_editor.debug = function(msg) {
106
 zss_editor.debug = function(msg) {
106
-    WebViewBridge.send('debug://'+msg);
107
+    WebViewBridge.send(JSON.stringify({type: 'LOG', data: msg}));
107
 }
108
 }
108
 
109
 
109
 
110
 
110
 zss_editor.setScrollPosition = function() {
111
 zss_editor.setScrollPosition = function() {
111
     var position = window.pageYOffset;
112
     var position = window.pageYOffset;
112
-    WebViewBridge.send('scroll://'+position);
113
+    WebViewBridge.send(JSON.stringify({type: 'SCROLL', data: position}));
113
 }
114
 }
114
 
115
 
115
 
116
 

+ 3
- 1
src/const.js 查看文件

30
 
30
 
31
 export const messages = {
31
 export const messages = {
32
   HTML_RESPONSE : 'HTML_RESPONSE',
32
   HTML_RESPONSE : 'HTML_RESPONSE',
33
-  ZSS_INITIALIZED: 'ZSS_INITIALIZED'
33
+  ZSS_INITIALIZED: 'ZSS_INITIALIZED',
34
+  SCROLL: 'SCROLL',
35
+  LOG: 'LOG'
34
 }
36
 }