Pārlūkot izejas kodu

Add: DOM change detection, android setup guide on README

Calvin Kei 6 gadus atpakaļ
vecāks
revīzija
1fedd1f471
3 mainītis faili ar 51 papildinājumiem un 8 dzēšanām
  1. 17
    2
      README.md
  2. 19
    3
      autoHeightWebView/index.android.js
  3. 15
    3
      autoHeightWebView/index.ios.js

+ 17
- 2
README.md Parādīt failu

@@ -12,7 +12,22 @@ Cause of moving View.propTypes to ViewPropTypes in React Naitve 0.44 (https://gi
12 12
 `npm install react-native-autoheight-webview@0.2.3 --save` (rn < 0.44)
13 13
 
14 14
 ## android
15
-`react-native link react-native-autoheight-webview`
15
+1. `react-native link react-native-autoheight-webview`
16
+2. in MainApplication.java
17
+```javascript
18
+import com.dscj.autoheightwebview.AutoHeightWebViewPackage; // Add this
19
+
20
+public class MainApplication extends Application implements ReactApplication {
21
+  //...
22
+  private final ReactNativeHost mReactNativeHost = new ReactNativeHost(this) {
23
+    //...
24
+    @Override
25
+    protected List<ReactPackage> getPackages() {
26
+      return Arrays.<ReactPackage>asList(
27
+        //...
28
+        new AutoHeightWebViewPackage() // Add this
29
+        //...
30
+```
16 31
 
17 32
 ## showcase
18 33
 ![react-native-autoheight-webview ios](https://media.giphy.com/media/l4FGyhnvWfUgxCfe0/200w.gif)&nbsp;
@@ -32,7 +47,7 @@ Cause of moving View.propTypes to ViewPropTypes in React Naitve 0.44 (https://gi
32 47
     scalesPageToFit={Platform.OS === 'android' ? true : false}
33 48
     // baseUrl not work in android 4.3 or below version
34 49
     enableBaseUrl={true}
35
-    // offset of rn webview margin 
50
+    // offset of rn webview margin
36 51
     heightOffset={5}
37 52
     // default width is the width of screen
38 53
     // if there are some text selection issues on iOS, the width should be reduced more than 15 and the marginTop should be added more than 35

+ 19
- 3
autoHeightWebView/index.android.js Parādīt failu

@@ -23,7 +23,7 @@ import Immutable from "immutable";
23 23
 const RCTAutoHeightWebView = requireNativeComponent(
24 24
   "RCTAutoHeightWebView",
25 25
   AutoHeightWebView,
26
-  { nativeOnly: 
26
+  { nativeOnly:
27 27
     {
28 28
       nativeOnly: {
29 29
         onLoadingStart: true,
@@ -343,12 +343,28 @@ const BaseScript = IsBelowKitKat
343 343
         AutoHeightWebView.onMessage = function (message) {
344 344
             AutoHeightWebView.send(String(document.body.offsetHeight));
345 345
         };
346
-    } ()); 
346
+        MutationObserver = window.MutationObserver || window.WebKitMutationObserver;
347
+        var observer = new MutationObserver(function() {
348
+            AutoHeightWebView.send(String(document.body.offsetHeight));
349
+        });
350
+        observer.observe(document, {
351
+            subtree: true,
352
+            attributes: true
353
+        });
354
+    } ());
347 355
     `
348 356
   : `
349 357
     ; (function () {
350 358
         document.addEventListener('message', function (e) {
351 359
             window.postMessage(String(document.body.offsetHeight));
352 360
         });
353
-    } ()); 
361
+        MutationObserver = window.MutationObserver || window.WebKitMutationObserver;
362
+        var observer = new MutationObserver(function() {
363
+            window.postMessage(String(document.body.offsetHeight));
364
+        });
365
+        observer.observe(document, {
366
+            subtree: true,
367
+            attributes: true
368
+        });
369
+    } ());
354 370
     `;

+ 15
- 3
autoHeightWebView/index.ios.js Parādīt failu

@@ -175,7 +175,7 @@ const Styles = StyleSheet.create({
175 175
 
176 176
 const BaseScript =
177 177
     `
178
-    ; 
178
+    ;
179 179
     (function () {
180 180
         var i = 0;
181 181
         var height = 0;
@@ -195,12 +195,18 @@ const BaseScript =
195 195
         updateHeight();
196 196
         window.addEventListener('load', updateHeight);
197 197
         window.addEventListener('resize', updateHeight);
198
+        MutationObserver = window.MutationObserver || window.WebKitMutationObserver;
199
+        var observer = new MutationObserver(updateHeight);
200
+        observer.observe(document, {
201
+            subtree: true,
202
+            attributes: true
203
+        });
198 204
     } ());
199 205
     `;
200 206
 
201 207
 const IframeBaseScript =
202 208
     `
203
-    ; 
209
+    ;
204 210
     (function () {
205 211
         var i = 0;
206 212
         var height = 0;
@@ -214,5 +220,11 @@ const IframeBaseScript =
214 220
         updateHeight();
215 221
         window.addEventListener('load', updateHeight);
216 222
         window.addEventListener('resize', updateHeight);
223
+        MutationObserver = window.MutationObserver || window.WebKitMutationObserver;
224
+        var observer = new MutationObserver(updateHeight);
225
+        observer.observe(document, {
226
+            subtree: true,
227
+            attributes: true
228
+        });
217 229
     } ());
218
-    `;
230
+    `;