Browse Source

ZSS init called when React side web view onLoad is called, fix issue with race condition on Android

Yedidya Kennard 8 years ago
parent
commit
8e349f974a
4 changed files with 11 additions and 2 deletions
  1. 5
    0
      src/RichTextEditor.js
  2. 3
    0
      src/WebviewMessageHandler.js
  3. 2
    1
      src/const.js
  4. 1
    1
      src/editor.html

+ 5
- 0
src/RichTextEditor.js View File

@@ -177,6 +177,7 @@ export default class RichTextEditor extends Component {
177 177
           onBridgeMessage={(message) => this.onBridgeMessage(message)}
178 178
           injectedJavaScript={injectScript}
179 179
           source={pageSource}
180
+          onLoad={() => this.init()}
180 181
         />
181 182
         {this._renderLinkModal()}
182 183
       </View>
@@ -370,6 +371,10 @@ export default class RichTextEditor extends Component {
370 371
     this._sendAction(actions.restoreSelection);
371 372
   }
372 373
 
374
+  init() {
375
+    this._sendAction(actions.init);
376
+  }
377
+
373 378
   async getTitleHtml() {
374 379
     return new Promise((resolve, reject) => {
375 380
       this.titleResolve = resolve;

+ 3
- 0
src/WebviewMessageHandler.js View File

@@ -135,6 +135,9 @@ export const InjectedMessageHandler = `
135 135
         case '${actions.setBackgroundColor}':
136 136
           zss_editor.setBackgroundColor(action.data);
137 137
           break;
138
+        case '${actions.init}':
139
+          zss_editor.init();
140
+          break;
138 141
       }
139 142
     };
140 143
   }

+ 2
- 1
src/const.js View File

@@ -41,7 +41,8 @@ export const actions = {
41 41
   restoreSelection: 'RESTORE_SELECTION',
42 42
   setCustomCSS: 'SET_CUSTOM_CSS',
43 43
   setTextColor: 'SET_TEXT_COLOR',
44
-  setBackgroundColor: 'SET_BACKGROUND_COLOR'
44
+  setBackgroundColor: 'SET_BACKGROUND_COLOR',
45
+  init: 'ZSSS_INIT'
45 46
 };
46 47
 
47 48
 

+ 1
- 1
src/editor.html View File

@@ -1649,7 +1649,7 @@
1649 1649
 		</style>
1650 1650
 	</head>
1651 1651
 
1652
-	<body onLoad="zss_editor.init();">
1652
+	<body>
1653 1653
 		<!-- ZSSRichTextEditor Editable Content -->
1654 1654
 		<div id="zss_editor_title" class="zss_editor_title" contenteditable="true" placeholder="" disableLineBreaks="true"></div>
1655 1655
 		<div id="separatorContainer"><hr></div>