浏览代码

split index.android.js into index.android.current.js & index.android.old.js; remove support below kitkat on android; remove native android module; remove native module ref from demo on android

iou90 5 年前
父节点
当前提交
adaa308ad9

+ 0
- 32
android/build.gradle 查看文件

@@ -1,32 +0,0 @@
1
-apply plugin: 'com.android.library'
2
-
3
-android {
4
-    compileSdkVersion 26
5
-    buildToolsVersion "27.0.3"
6
-
7
-    defaultConfig {
8
-        minSdkVersion 16
9
-        targetSdkVersion 26
10
-        versionCode 1
11
-        versionName "1.0"
12
-
13
-        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
14
-
15
-    }
16
-    buildTypes {
17
-        release {
18
-            minifyEnabled false
19
-            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
20
-        }
21
-    }
22
-}
23
-
24
-dependencies {
25
-    compile fileTree(dir: 'libs', include: ['*.jar'])
26
-    androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
27
-        exclude group: 'com.android.support', module: 'support-annotations'
28
-    })
29
-    compile 'com.android.support:appcompat-v7:26.1.0'
30
-    compile "com.facebook.react:react-native:+"  // From node_modules
31
-    testCompile 'junit:junit:4.12'
32
-}

二进制
android/gradle/wrapper/gradle-wrapper.jar 查看文件


+ 0
- 6
android/gradle/wrapper/gradle-wrapper.properties 查看文件

@@ -1,6 +0,0 @@
1
-#Mon Dec 28 10:00:20 PST 2015
2
-distributionBase=GRADLE_USER_HOME
3
-distributionPath=wrapper/dists
4
-zipStoreBase=GRADLE_USER_HOME
5
-zipStorePath=wrapper/dists
6
-distributionUrl=https\://services.gradle.org/distributions/gradle-2.14.1-all.zip

+ 0
- 160
android/gradlew 查看文件

@@ -1,160 +0,0 @@
1
-#!/usr/bin/env bash
2
-
3
-##############################################################################
4
-##
5
-##  Gradle start up script for UN*X
6
-##
7
-##############################################################################
8
-
9
-# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
10
-DEFAULT_JVM_OPTS=""
11
-
12
-APP_NAME="Gradle"
13
-APP_BASE_NAME=`basename "$0"`
14
-
15
-# Use the maximum available, or set MAX_FD != -1 to use that value.
16
-MAX_FD="maximum"
17
-
18
-warn ( ) {
19
-    echo "$*"
20
-}
21
-
22
-die ( ) {
23
-    echo
24
-    echo "$*"
25
-    echo
26
-    exit 1
27
-}
28
-
29
-# OS specific support (must be 'true' or 'false').
30
-cygwin=false
31
-msys=false
32
-darwin=false
33
-case "`uname`" in
34
-  CYGWIN* )
35
-    cygwin=true
36
-    ;;
37
-  Darwin* )
38
-    darwin=true
39
-    ;;
40
-  MINGW* )
41
-    msys=true
42
-    ;;
43
-esac
44
-
45
-# Attempt to set APP_HOME
46
-# Resolve links: $0 may be a link
47
-PRG="$0"
48
-# Need this for relative symlinks.
49
-while [ -h "$PRG" ] ; do
50
-    ls=`ls -ld "$PRG"`
51
-    link=`expr "$ls" : '.*-> \(.*\)$'`
52
-    if expr "$link" : '/.*' > /dev/null; then
53
-        PRG="$link"
54
-    else
55
-        PRG=`dirname "$PRG"`"/$link"
56
-    fi
57
-done
58
-SAVED="`pwd`"
59
-cd "`dirname \"$PRG\"`/" >/dev/null
60
-APP_HOME="`pwd -P`"
61
-cd "$SAVED" >/dev/null
62
-
63
-CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
64
-
65
-# Determine the Java command to use to start the JVM.
66
-if [ -n "$JAVA_HOME" ] ; then
67
-    if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
68
-        # IBM's JDK on AIX uses strange locations for the executables
69
-        JAVACMD="$JAVA_HOME/jre/sh/java"
70
-    else
71
-        JAVACMD="$JAVA_HOME/bin/java"
72
-    fi
73
-    if [ ! -x "$JAVACMD" ] ; then
74
-        die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
75
-
76
-Please set the JAVA_HOME variable in your environment to match the
77
-location of your Java installation."
78
-    fi
79
-else
80
-    JAVACMD="java"
81
-    which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
82
-
83
-Please set the JAVA_HOME variable in your environment to match the
84
-location of your Java installation."
85
-fi
86
-
87
-# Increase the maximum file descriptors if we can.
88
-if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then
89
-    MAX_FD_LIMIT=`ulimit -H -n`
90
-    if [ $? -eq 0 ] ; then
91
-        if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
92
-            MAX_FD="$MAX_FD_LIMIT"
93
-        fi
94
-        ulimit -n $MAX_FD
95
-        if [ $? -ne 0 ] ; then
96
-            warn "Could not set maximum file descriptor limit: $MAX_FD"
97
-        fi
98
-    else
99
-        warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
100
-    fi
101
-fi
102
-
103
-# For Darwin, add options to specify how the application appears in the dock
104
-if $darwin; then
105
-    GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
106
-fi
107
-
108
-# For Cygwin, switch paths to Windows format before running java
109
-if $cygwin ; then
110
-    APP_HOME=`cygpath --path --mixed "$APP_HOME"`
111
-    CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
112
-    JAVACMD=`cygpath --unix "$JAVACMD"`
113
-
114
-    # We build the pattern for arguments to be converted via cygpath
115
-    ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
116
-    SEP=""
117
-    for dir in $ROOTDIRSRAW ; do
118
-        ROOTDIRS="$ROOTDIRS$SEP$dir"
119
-        SEP="|"
120
-    done
121
-    OURCYGPATTERN="(^($ROOTDIRS))"
122
-    # Add a user-defined pattern to the cygpath arguments
123
-    if [ "$GRADLE_CYGPATTERN" != "" ] ; then
124
-        OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
125
-    fi
126
-    # Now convert the arguments - kludge to limit ourselves to /bin/sh
127
-    i=0
128
-    for arg in "$@" ; do
129
-        CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
130
-        CHECK2=`echo "$arg"|egrep -c "^-"`                                 ### Determine if an option
131
-
132
-        if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then                    ### Added a condition
133
-            eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
134
-        else
135
-            eval `echo args$i`="\"$arg\""
136
-        fi
137
-        i=$((i+1))
138
-    done
139
-    case $i in
140
-        (0) set -- ;;
141
-        (1) set -- "$args0" ;;
142
-        (2) set -- "$args0" "$args1" ;;
143
-        (3) set -- "$args0" "$args1" "$args2" ;;
144
-        (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
145
-        (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
146
-        (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
147
-        (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
148
-        (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
149
-        (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
150
-    esac
151
-fi
152
-
153
-# Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules
154
-function splitJvmOpts() {
155
-    JVM_OPTS=("$@")
156
-}
157
-eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS
158
-JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME"
159
-
160
-exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@"

+ 0
- 90
android/gradlew.bat 查看文件

@@ -1,90 +0,0 @@
1
-@if "%DEBUG%" == "" @echo off
2
-@rem ##########################################################################
3
-@rem
4
-@rem  Gradle startup script for Windows
5
-@rem
6
-@rem ##########################################################################
7
-
8
-@rem Set local scope for the variables with windows NT shell
9
-if "%OS%"=="Windows_NT" setlocal
10
-
11
-@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
12
-set DEFAULT_JVM_OPTS=
13
-
14
-set DIRNAME=%~dp0
15
-if "%DIRNAME%" == "" set DIRNAME=.
16
-set APP_BASE_NAME=%~n0
17
-set APP_HOME=%DIRNAME%
18
-
19
-@rem Find java.exe
20
-if defined JAVA_HOME goto findJavaFromJavaHome
21
-
22
-set JAVA_EXE=java.exe
23
-%JAVA_EXE% -version >NUL 2>&1
24
-if "%ERRORLEVEL%" == "0" goto init
25
-
26
-echo.
27
-echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
28
-echo.
29
-echo Please set the JAVA_HOME variable in your environment to match the
30
-echo location of your Java installation.
31
-
32
-goto fail
33
-
34
-:findJavaFromJavaHome
35
-set JAVA_HOME=%JAVA_HOME:"=%
36
-set JAVA_EXE=%JAVA_HOME%/bin/java.exe
37
-
38
-if exist "%JAVA_EXE%" goto init
39
-
40
-echo.
41
-echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
42
-echo.
43
-echo Please set the JAVA_HOME variable in your environment to match the
44
-echo location of your Java installation.
45
-
46
-goto fail
47
-
48
-:init
49
-@rem Get command-line arguments, handling Windowz variants
50
-
51
-if not "%OS%" == "Windows_NT" goto win9xME_args
52
-if "%@eval[2+2]" == "4" goto 4NT_args
53
-
54
-:win9xME_args
55
-@rem Slurp the command line arguments.
56
-set CMD_LINE_ARGS=
57
-set _SKIP=2
58
-
59
-:win9xME_args_slurp
60
-if "x%~1" == "x" goto execute
61
-
62
-set CMD_LINE_ARGS=%*
63
-goto execute
64
-
65
-:4NT_args
66
-@rem Get arguments from the 4NT Shell from JP Software
67
-set CMD_LINE_ARGS=%$
68
-
69
-:execute
70
-@rem Setup the command line
71
-
72
-set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
73
-
74
-@rem Execute Gradle
75
-"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
76
-
77
-:end
78
-@rem End local scope for the variables with windows NT shell
79
-if "%ERRORLEVEL%"=="0" goto mainEnd
80
-
81
-:fail
82
-rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
83
-rem the _cmd.exe /c_ return code!
84
-if  not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
85
-exit /b 1
86
-
87
-:mainEnd
88
-if "%OS%"=="Windows_NT" endlocal
89
-
90
-:omega

+ 0
- 17
android/proguard-rules.pro 查看文件

@@ -1,17 +0,0 @@
1
-# Add project specific ProGuard rules here.
2
-# By default, the flags in this file are appended to flags specified
3
-# in /Users/iou90/Library/Android/sdk/tools/proguard/proguard-android.txt
4
-# You can edit the include path and order by changing the proguardFiles
5
-# directive in build.gradle.
6
-#
7
-# For more details, see
8
-#   http://developer.android.com/guide/developing/tools/proguard.html
9
-
10
-# Add any project specific keep options here:
11
-
12
-# If your project uses WebView with JS, uncomment the following
13
-# and specify the fully qualified class name to the JavaScript interface
14
-# class:
15
-#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
16
-#   public *;
17
-#}

+ 0
- 26
android/src/androidTest/java/com/dscj/autoheightwebview/ExampleInstrumentedTest.java 查看文件

@@ -1,26 +0,0 @@
1
-package com.iou90.autoheightwebview;
2
-
3
-import android.content.Context;
4
-import android.support.test.InstrumentationRegistry;
5
-import android.support.test.runner.AndroidJUnit4;
6
-
7
-import org.junit.Test;
8
-import org.junit.runner.RunWith;
9
-
10
-import static org.junit.Assert.*;
11
-
12
-/**
13
- * Instrumentation test, which will execute on an Android device.
14
- *
15
- * @see <a href="http://d.android.com/tools/testing">Testing documentation</a>
16
- */
17
-@RunWith(AndroidJUnit4.class)
18
-public class ExampleInstrumentedTest {
19
-    @Test
20
-    public void useAppContext() throws Exception {
21
-        // Context of the app under test.
22
-        Context appContext = InstrumentationRegistry.getTargetContext();
23
-
24
-        assertEquals("com.iou90.autoheightwebview.test", appContext.getPackageName());
25
-    }
26
-}

+ 0
- 10
android/src/main/AndroidManifest.xml 查看文件

@@ -1,10 +0,0 @@
1
-<manifest xmlns:android="http://schemas.android.com/apk/res/android"
2
-          package="com.iou90.autoheightwebview">
3
-
4
-    <application android:label="@string/app_name"
5
-                 android:supportsRtl="true"
6
-    >
7
-
8
-    </application>
9
-
10
-</manifest>

+ 0
- 64
android/src/main/java/com/iou90/autoheightwebview/AutoHeightWebViewManager.java 查看文件

@@ -1,64 +0,0 @@
1
-package com.iou90.autoheightwebview;
2
-
3
-import android.webkit.WebView;
4
-
5
-import com.facebook.react.bridge.ReadableArray;
6
-import com.facebook.react.uimanager.annotations.ReactProp;
7
-import com.facebook.react.uimanager.ThemedReactContext;
8
-import com.facebook.react.views.webview.ReactWebViewManager;
9
-
10
-import java.util.Map;
11
-import javax.annotation.Nullable;
12
-
13
-public class AutoHeightWebViewManager extends ReactWebViewManager {
14
-    private static final String REACT_CLASS = "RCTAutoHeightWebView";
15
-
16
-    public static final int COMMAND_SEND_TO_WEBVIEW = 101;
17
-
18
-    @Override
19
-    public String getName() {
20
-        return REACT_CLASS;
21
-    }
22
-
23
-    @Override
24
-    public
25
-    @Nullable
26
-    Map<String, Integer> getCommandsMap() {
27
-        Map<String, Integer> commandsMap = super.getCommandsMap();
28
-        commandsMap.put("sendToWebView", COMMAND_SEND_TO_WEBVIEW);
29
-
30
-        return commandsMap;
31
-    }
32
-
33
-    @Override
34
-    protected WebView createViewInstance(ThemedReactContext reactContext) {
35
-        WebView webview = super.createViewInstance(reactContext);
36
-        webview.setVerticalScrollBarEnabled(false);
37
-        webview.setHorizontalScrollBarEnabled(false);
38
-        webview.addJavascriptInterface(new JavascriptBridge(webview), "AutoHeightWebView");
39
-
40
-        return webview;
41
-    }
42
-
43
-    @Override
44
-    public void receiveCommand(WebView webView, int commandId, @Nullable ReadableArray args) {
45
-        super.receiveCommand(webView, commandId, args);
46
-
47
-        switch (commandId) {
48
-            case COMMAND_SEND_TO_WEBVIEW:
49
-                sendToWebView(webView, args.getString(0));
50
-                break;
51
-            default:
52
-                break;
53
-        }
54
-    }
55
-
56
-    private void sendToWebView(WebView webView, String message) {
57
-        String script = "AutoHeightWebView.onMessage('" + message + "');";
58
-        if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.KITKAT) {
59
-            webView.evaluateJavascript(script, null);
60
-        } else {
61
-            webView.loadUrl("javascript:" + script);
62
-        }
63
-    }
64
-}

+ 0
- 25
android/src/main/java/com/iou90/autoheightwebview/AutoHeightWebViewPackage.java 查看文件

@@ -1,25 +0,0 @@
1
-package com.iou90.autoheightwebview;
2
-
3
-import com.facebook.react.ReactPackage;
4
-import com.facebook.react.bridge.JavaScriptModule;
5
-import com.facebook.react.bridge.NativeModule;
6
-import com.facebook.react.bridge.ReactApplicationContext;
7
-import com.facebook.react.uimanager.ViewManager;
8
-
9
-import java.util.ArrayList;
10
-import java.util.Arrays;
11
-import java.util.List;
12
-
13
-public class AutoHeightWebViewPackage implements ReactPackage {
14
-    @Override
15
-    public List<NativeModule> createNativeModules(ReactApplicationContext reactApplicationContext) {
16
-        return new ArrayList<>();
17
-    }
18
-
19
-    @Override
20
-    public List<ViewManager> createViewManagers(ReactApplicationContext reactApplicationContext) {
21
-        return Arrays.<ViewManager>asList(
22
-                new AutoHeightWebViewManager()
23
-        );
24
-    }
25
-}

+ 0
- 29
android/src/main/java/com/iou90/autoheightwebview/JavascriptBridge.java 查看文件

@@ -1,29 +0,0 @@
1
-package com.iou90.autoheightwebview;
2
-
3
-import android.webkit.JavascriptInterface;
4
-import android.webkit.WebView;
5
-
6
-import com.facebook.react.bridge.Arguments;
7
-import com.facebook.react.bridge.ReactContext;
8
-import com.facebook.react.bridge.WritableMap;
9
-import com.facebook.react.modules.core.DeviceEventManagerModule;
10
-import com.facebook.react.uimanager.events.RCTEventEmitter;
11
-
12
-class JavascriptBridge {
13
-    private WebView webView;
14
-
15
-    public JavascriptBridge(WebView webView) {
16
-        this.webView = webView;
17
-    }
18
-
19
-    @JavascriptInterface
20
-    public void send(String message) {
21
-        WritableMap event = Arguments.createMap();
22
-        event.putString("message", message);
23
-        ReactContext reactContext = (ReactContext) this.webView.getContext();
24
-        reactContext.getJSModule(RCTEventEmitter.class).receiveEvent(
25
-                this.webView.getId(),
26
-                "topChange",
27
-                event);
28
-    }
29
-}

+ 0
- 3
android/src/main/res/values/strings.xml 查看文件

@@ -1,3 +0,0 @@
1
-<resources>
2
-    <string name="app_name">RCTAutoHeightWebView</string>
3
-</resources>

+ 0
- 17
android/src/test/java/com/dscj/autoheightwebview/ExampleUnitTest.java 查看文件

@@ -1,17 +0,0 @@
1
-package com.iou90.autoheightwebview;
2
-
3
-import org.junit.Test;
4
-
5
-import static org.junit.Assert.*;
6
-
7
-/**
8
- * Example local unit test, which will execute on the development machine (host).
9
- *
10
- * @see <a href="http://d.android.com/tools/testing">Testing documentation</a>
11
- */
12
-public class ExampleUnitTest {
13
-    @Test
14
-    public void addition_isCorrect() throws Exception {
15
-        assertEquals(4, 2 + 2);
16
-    }
17
-}

+ 271
- 0
autoHeightWebView/index.android.current.js 查看文件

@@ -0,0 +1,271 @@
1
+'use strict';
2
+
3
+import React, { PureComponent } from 'react';
4
+
5
+import { Animated, Easing, StyleSheet, WebView, Dimensions } from 'react-native';
6
+
7
+import PropTypes from 'prop-types';
8
+
9
+import { androidPropTypes } from 'react-native-autoheight-webview/autoHeightWebView/propTypes';
10
+
11
+import {
12
+  isEqual,
13
+  setState,
14
+  isSizeChanged,
15
+  handleSizeUpdated,
16
+  getWidth,
17
+  getScript,
18
+  domMutationObserveScript,
19
+  getCurrentSize
20
+} from 'react-native-autoheight-webview/autoHeightWebView/common';
21
+
22
+import momoize from 'react-native-autoheight-webview/autoHeightWebView/momoize';
23
+
24
+const getUpdatedState = momoize(setState, isEqual);
25
+
26
+function getRenderSize(enableAnimation, height, width, heightOffset, heightValue, widthValue) {
27
+  return {
28
+    height: enableAnimation ? heightValue : height ? height + heightOffset : 0,
29
+    width: enableAnimation ? widthValue : width
30
+  };
31
+}
32
+
33
+export default class AutoHeightWebView extends PureComponent {
34
+  static propTypes = {
35
+    ...androidPropTypes,
36
+    animationEasing: PropTypes.func
37
+  };
38
+
39
+  static defaultProps = {
40
+    baseUrl: 'file:///android_asset/web/',
41
+    scalesPageToFit: true,
42
+    enableAnimation: true,
43
+    animationDuration: 255,
44
+    heightOffset: 20,
45
+    animationEasing: Easing.out(Easing.quad)
46
+  };
47
+
48
+  constructor(props) {
49
+    super(props);
50
+    const { baseUrl, enableAnimation, style, source, heightOffset } = props;
51
+    this.webView = React.createRef();
52
+    this.finishInterval = true;
53
+    const initWidth = getWidth(style);
54
+    const initHeight = style ? (style.height ? style.height : 0) : 0;
55
+    let state = {
56
+      isSizeChanged: false,
57
+      isSizeMayChange: false,
58
+      height: initHeight,
59
+      width: initWidth,
60
+      script: getScript(props, getBaseScript),
61
+      source: Object.assign({}, source, { baseUrl })
62
+    };
63
+    if (enableAnimation) {
64
+      Object.assign(state, {
65
+        heightValue: new Animated.Value(initHeight ? initHeight + heightOffset : 0),
66
+        widthValue: new Animated.Value(initWidth)
67
+      });
68
+    }
69
+    this.state = state;
70
+  }
71
+
72
+  componentDidMount() {
73
+    this.startInterval();
74
+  }
75
+
76
+  static getDerivedStateFromProps(props, state) {
77
+    const { height: oldHeight, width: oldWidth, source: prevSource, script: prevScript } = state;
78
+    const { style } = props;
79
+    const { source, script } = getUpdatedState(props, getBaseScript);
80
+    const height = style ? style.height : null;
81
+    const width = style ? style.width : null;
82
+    if (source.html !== prevSource.html || source.uri !== prevSource.uri || script !== prevScript) {
83
+      return {
84
+        source,
85
+        script,
86
+        isSizeMayChange: true
87
+      };
88
+    }
89
+    if (isSizeChanged(height, oldHeight, width, oldWidth)) {
90
+      return {
91
+        height: height || oldHeight,
92
+        width: width || oldWidth,
93
+        isSizeChanged: true
94
+      };
95
+    }
96
+    return null;
97
+  }
98
+
99
+  componentDidUpdate() {
100
+    const { height, width, isSizeChanged, isSizeMayChange, heightValue, widthValue } = this.state;
101
+    if (isSizeMayChange) {
102
+      this.startInterval();
103
+      this.setState({ isSizeMayChange: false });
104
+    }
105
+    if (isSizeChanged) {
106
+      const { enableAnimation, animationDuration, animationEasing, onSizeUpdated, heightOffset } = this.props;
107
+      if (enableAnimation) {
108
+        Animated.parallel([
109
+          Animated.timing(heightValue, {
110
+            toValue: height ? height + heightOffset : 0,
111
+            easing: animationEasing,
112
+            duration: animationDuration
113
+          }),
114
+          Animated.timing(widthValue, {
115
+            toValue: width,
116
+            easing: animationEasing,
117
+            duration: animationDuration
118
+          })
119
+        ]).start(() => {
120
+          handleSizeUpdated(height, width, onSizeUpdated);
121
+        });
122
+      } else {
123
+        handleSizeUpdated(height, width, onSizeUpdated);
124
+      }
125
+      this.setState({ isSizeChanged: false });
126
+    }
127
+  }
128
+
129
+  componentWillUnmount() {
130
+    this.stopInterval();
131
+  }
132
+
133
+  startInterval() {
134
+    if (this.finishInterval === false) {
135
+      return;
136
+    }
137
+    this.finishInterval = false;
138
+    this.setState({
139
+      interval: setInterval(() => !this.finishInterval && this.webView.current.postMessage('getBodyHeight'), 205)
140
+    });
141
+  }
142
+
143
+  stopInterval() {
144
+    this.finishInterval = true;
145
+    clearInterval(this.state.interval);
146
+  }
147
+
148
+  onMessage = event => {
149
+    if (!event.nativeEvent) {
150
+      return;
151
+    }
152
+    let data = {};
153
+    // Sometimes the message is invalid JSON, so we ignore that case
154
+    try {
155
+      data = JSON.parse(event.nativeEvent.data);
156
+    } catch (error) {
157
+      console.error(error);
158
+      return;
159
+    }
160
+    const { height, width } = data;
161
+    const { height: oldHeight, width: oldWidth } = this.state;
162
+    if (isSizeChanged(height, oldHeight, width, oldWidth)) {
163
+      this.stopInterval();
164
+      this.setState({
165
+        isSizeChanged: true,
166
+        height,
167
+        width
168
+      });
169
+    }
170
+    const { onMessage } = this.props;
171
+    onMessage && onMessage(event);
172
+  };
173
+
174
+  render() {
175
+    const { height, width, script, source, heightValue, widthValue } = this.state;
176
+    const {
177
+      domStorageEnabled,
178
+      thirdPartyCookiesEnabled,
179
+      userAgent,
180
+      geolocationEnabled,
181
+      allowUniversalAccessFromFileURLs,
182
+      mixedContentMode,
183
+      onNavigationStateChange,
184
+      renderError,
185
+      originWhitelist,
186
+      mediaPlaybackRequiresUserAction,
187
+      scalesPageToFit,
188
+      style,
189
+      heightOffset,
190
+      enableAnimation,
191
+      onError,
192
+      onLoad,
193
+      onLoadStart,
194
+      onLoadEnd
195
+    } = this.props;
196
+    return (
197
+      <Animated.View
198
+        style={[
199
+          styles.container,
200
+          getRenderSize(enableAnimation, height, width, heightOffset, heightValue, widthValue),
201
+          style
202
+        ]}
203
+      >
204
+        <WebView
205
+          onNavigationStateChange={onNavigationStateChange}
206
+          domStorageEnabled={domStorageEnabled}
207
+          thirdPartyCookiesEnabled={thirdPartyCookiesEnabled}
208
+          userAgent={userAgent}
209
+          geolocationEnabled={geolocationEnabled}
210
+          allowUniversalAccessFromFileURLs={allowUniversalAccessFromFileURLs}
211
+          mixedContentMode={mixedContentMode}
212
+          renderError={renderError}
213
+          mediaPlaybackRequiresUserAction={mediaPlaybackRequiresUserAction}
214
+          originWhitelist={originWhitelist || ['*']}
215
+          ref={this.webView}
216
+          onMessage={this.onMessage}
217
+          onError={onError}
218
+          onLoad={onLoad}
219
+          onLoadStart={onLoadStart}
220
+          onLoadEnd={onLoadEnd}
221
+          style={styles.webView}
222
+          scalesPageToFit={scalesPageToFit}
223
+          javaScriptEnabled={true}
224
+          injectedJavaScript={script}
225
+          source={source}
226
+        />
227
+      </Animated.View>
228
+    );
229
+  }
230
+}
231
+
232
+const styles = StyleSheet.create({
233
+  container: {
234
+    height: 50,
235
+    width: Dimensions.get('window').width,
236
+    backgroundColor: 'transparent'
237
+  },
238
+  webView: {
239
+    flex: 1,
240
+    backgroundColor: 'transparent'
241
+  }
242
+});
243
+
244
+const commonScript = `
245
+    ${getCurrentSize}
246
+    var wrapper = document.createElement("div");
247
+    wrapper.id = "wrapper";
248
+    while (document.body.firstChild instanceof Node) {
249
+        wrapper.appendChild(document.body.firstChild);
250
+    }
251
+    document.body.appendChild(wrapper);
252
+    var height = 0;
253
+`;
254
+
255
+const getBaseScript = function(style) {
256
+  return `
257
+  ; 
258
+  ${commonScript}
259
+  var width = ${getWidth(style)};
260
+  function updateSize() {
261
+    var size = getSize(document.body.firstChild); 
262
+    height = size.height;
263
+    width = size.width;
264
+    window.postMessage(JSON.stringify({ width: width, height: height }), '*');
265
+  }
266
+  (function () {
267
+    document.addEventListener("message", updateSize);
268
+    ${domMutationObserveScript}
269
+  } ());
270
+`;
271
+};

+ 6
- 357
autoHeightWebView/index.android.js 查看文件

@@ -1,364 +1,13 @@
1 1
 'use strict';
2 2
 
3
-import React, { PureComponent } from 'react';
3
+import { Platform } from 'react-native';
4 4
 
5
-import {
6
-  findNodeHandle,
7
-  requireNativeComponent,
8
-  Animated,
9
-  DeviceEventEmitter,
10
-  Easing,
11
-  StyleSheet,
12
-  Platform,
13
-  UIManager,
14
-  ViewPropTypes,
15
-  WebView
16
-} from 'react-native';
5
+import AutoHeightWebViewOld from './index.android.old.js';
17 6
 
18
-import PropTypes from 'prop-types';
7
+import AutoHeightWebView from './index.android.current.js';
19 8
 
20
-import {
21
-  isEqual,
22
-  setState,
23
-  isSizeChanged,
24
-  handleSizeUpdated,
25
-  getWidth,
26
-  getScript,
27
-  domMutationObserveScript,
28
-  getCurrentSize,
29
-  getRenderSize
30
-} from './common.js';
9
+const isBelowMarshmallow = Platform.Version < 23;
31 10
 
32
-const RCTAutoHeightWebView = requireNativeComponent('RCTAutoHeightWebView', AutoHeightWebView, {
33
-  nativeOnly: {
34
-    nativeOnly: {
35
-      onLoadingStart: true,
36
-      onLoadingError: true,
37
-      onLoadingFinish: true,
38
-      messagingEnabled: PropTypes.bool
39
-    }
40
-  }
41
-});
11
+const webview = isBelowMarshmallow ? AutoHeightWebViewOld : AutoHeightWebView;
42 12
 
43
-import momoize from './momoize';
44
-
45
-const getUpdatedState = momoize(setState, isEqual);
46
-
47
-export default class AutoHeightWebView extends PureComponent {
48
-  static propTypes = {
49
-    onNavigationStateChange: PropTypes.func,
50
-    onMessage: PropTypes.func,
51
-    scrollEnabled: PropTypes.bool,
52
-    source: WebView.propTypes.source,
53
-    customScript: PropTypes.string,
54
-    customStyle: PropTypes.string,
55
-    enableAnimation: PropTypes.bool,
56
-    // either height or width updated will trigger this
57
-    onSizeUpdated: PropTypes.func,
58
-    // if set to false may cause some layout issues (width of container will be than width of screen)
59
-    scalesPageToFit: PropTypes.bool,
60
-    // only works on enable animation
61
-    animationDuration: PropTypes.number,
62
-    // only on android
63
-    animationEasing: PropTypes.func,
64
-    // offset of rn webView margin
65
-    heightOffset: PropTypes.number,
66
-    style: ViewPropTypes.style,
67
-    //  rn WebView callback
68
-    onError: PropTypes.func,
69
-    onLoad: PropTypes.func,
70
-    onLoadStart: PropTypes.func,
71
-    onLoadEnd: PropTypes.func,
72
-    // 'file:///android_asset/web/' by default, and baseUrl not work in android 4.3 or below version
73
-    baseUrl: PropTypes.string,
74
-    // add baseUrl/files... to android/app/src/assets/
75
-    files: PropTypes.arrayOf(
76
-      PropTypes.shape({
77
-        href: PropTypes.string,
78
-        type: PropTypes.string,
79
-        rel: PropTypes.string
80
-      })
81
-    )
82
-  };
83
-
84
-  static defaultProps = {
85
-    baseUrl: 'file:///android_asset/web/',
86
-    scalesPageToFit: true,
87
-    enableAnimation: true,
88
-    animationDuration: 255,
89
-    heightOffset: 20,
90
-    animationEasing: Easing.out(Easing.quad)
91
-  };
92
-
93
-  constructor(props) {
94
-    super(props);
95
-    const { baseUrl, enableAnimation, style, source, heightOffset } = props;
96
-    isBelowKitKat && DeviceEventEmitter.addListener('webViewBridgeMessage', this.listenWebViewBridgeMessage);
97
-    this.finishInterval = true;
98
-    const initWidth = getWidth(style);
99
-    const initHeight = style ? (style.height ? style.height : 0) : 0;
100
-    let state = {
101
-      isSizeChanged: false,
102
-      isSizeMayChange: false,
103
-      height: initHeight,
104
-      width: initWidth,
105
-      script: getScript(props, getBaseScript),
106
-      source: Object.assign({}, source, { baseUrl })
107
-    };
108
-    if (enableAnimation) {
109
-      Object.assign(state, {
110
-        heightValue: new Animated.Value(initHeight ? initHeight + heightOffset : 0),
111
-        widthValue: new Animated.Value(initWidth)
112
-      });
113
-    }
114
-    this.state = state;
115
-  }
116
-
117
-  componentDidMount() {
118
-    this.startInterval();
119
-  }
120
-
121
-  static getDerivedStateFromProps(props, state) {
122
-    const { height: oldHeight, width: oldWidth, source: prevSource, script: prevScript } = state;
123
-    const { style } = props;
124
-    const { source, script } = getUpdatedState(props, getBaseScript);
125
-    const height = style ? style.height : null;
126
-    const width = style ? style.width : null;
127
-    if (source.html !== prevSource.html || source.uri !== prevSource.uri || script !== prevScript) {
128
-      return {
129
-        source,
130
-        script,
131
-        isSizeMayChange: true
132
-      };
133
-    }
134
-    if (isSizeChanged(height, oldHeight, width, oldWidth)) {
135
-      return {
136
-        height: height || oldHeight,
137
-        width: width || oldWidth,
138
-        isSizeChanged: true
139
-      };
140
-    }
141
-    return null;
142
-  }
143
-
144
-  componentDidUpdate() {
145
-    const { height, width, isSizeChanged, isSizeMayChange, heightValue, widthValue } = this.state;
146
-    if (isSizeMayChange) {
147
-      this.startInterval();
148
-      this.setState({ isSizeMayChange: false });
149
-    }
150
-    if (isSizeChanged) {
151
-      const { enableAnimation, animationDuration, animationEasing, onSizeUpdated, heightOffset } = this.props;
152
-      if (enableAnimation) {
153
-        Animated.parallel([
154
-          Animated.timing(heightValue, {
155
-            toValue: height ? height + heightOffset : 0,
156
-            easing: animationEasing,
157
-            duration: animationDuration
158
-          }),
159
-          Animated.timing(widthValue, {
160
-            toValue: width,
161
-            easing: animationEasing,
162
-            duration: animationDuration
163
-          })
164
-        ]).start(() => {
165
-          handleSizeUpdated(height, width, onSizeUpdated);
166
-        });
167
-      } else {
168
-        handleSizeUpdated(height, width, onSizeUpdated);
169
-      }
170
-      this.setState({ isSizeChanged: false });
171
-    }
172
-  }
173
-
174
-  componentWillUnmount() {
175
-    this.stopInterval();
176
-    isBelowKitKat && DeviceEventEmitter.removeListener('webViewBridgeMessage', this.listenWebViewBridgeMessage);
177
-  }
178
-
179
-  // below kitkat
180
-  listenWebViewBridgeMessage = body => this.onMessage(body.message);
181
-
182
-  // below kitkat
183
-  sendToWebView(message) {
184
-    UIManager.dispatchViewManagerCommand(
185
-      findNodeHandle(this.webView),
186
-      UIManager.RCTAutoHeightWebView.Commands.sendToWebView,
187
-      [String(message)]
188
-    );
189
-  }
190
-
191
-  postMessage(data) {
192
-    UIManager.dispatchViewManagerCommand(
193
-      findNodeHandle(this.webView),
194
-      UIManager.RCTAutoHeightWebView.Commands.postMessage,
195
-      [String(data)]
196
-    );
197
-  }
198
-
199
-  startInterval() {
200
-    if (this.finishInterval === false) {
201
-      return;
202
-    }
203
-    this.finishInterval = false;
204
-    this.setState({
205
-      interval: setInterval(() => {
206
-        if (!this.finishInterval) {
207
-          isBelowKitKat ? this.sendToWebView('getBodyHeight') : this.postMessage('getBodyHeight');
208
-        }
209
-      }, 205)
210
-    });
211
-  }
212
-
213
-  stopInterval() {
214
-    this.finishInterval = true;
215
-    clearInterval(this.state.interval);
216
-  }
217
-
218
-  onMessage = e => {
219
-    if (!e.nativeEvent) {
220
-      return;
221
-    }
222
-    let data = {};
223
-    // Sometimes the message is invalid JSON, so we ignore that case
224
-    try {
225
-      data = JSON.parse(isBelowKitKat ? e.nativeEvent.message : e.nativeEvent.data);
226
-    } catch (error) {
227
-      console.error(error);
228
-      return;
229
-    }
230
-    const { height, width } = data;
231
-    const { height: oldHeight, width: oldWidth } = this.state;
232
-    if (isSizeChanged(height, oldHeight, width, oldWidth)) {
233
-      this.stopInterval();
234
-      this.setState({
235
-        isSizeChanged: true,
236
-        height,
237
-        width
238
-      });
239
-    }
240
-    const { onMessage } = this.props;
241
-    onMessage && onMessage(e);
242
-  };
243
-
244
-  onLoadingStart = event => {
245
-    const { onLoadStart, onNavigationStateChange } = this.props;
246
-    onLoadStart && onLoadStart(event);
247
-    onNavigationStateChange && onNavigationStateChange(event.nativeEvent);
248
-  };
249
-
250
-  onLoadingError = event => {
251
-    const { onError, onLoadEnd } = this.props;
252
-    onError && onError(event);
253
-    onLoadEnd && onLoadEnd(event);
254
-    console.warn('Encountered an error loading page', event.nativeEvent);
255
-  };
256
-
257
-  onLoadingFinish = event => {
258
-    const { onLoad, onLoadEnd, onNavigationStateChange } = this.props;
259
-    onLoad && onLoad(event);
260
-    onLoadEnd && onLoadEnd(event);
261
-    onNavigationStateChange && onNavigationStateChange(event.nativeEvent);
262
-  };
263
-
264
-  stopLoading() {
265
-    UIManager.dispatchViewManagerCommand(
266
-      findNodeHandle(this.webView),
267
-      UIManager.RCTAutoHeightWebView.Commands.stopLoading,
268
-      null
269
-    );
270
-  }
271
-
272
-  getWebView = webView => (this.webView = webView);
273
-
274
-  render() {
275
-    const { height, width, script, source, heightValue, widthValue } = this.state;
276
-    const { scalesPageToFit, style, scrollEnabled, heightOffset, enableAnimation } = this.props;
277
-    return (
278
-      <Animated.View
279
-        style={[
280
-          styles.container,
281
-          getRenderSize(enableAnimation, height, width, heightOffset, heightValue, widthValue),
282
-          style
283
-        ]}
284
-      >
285
-        <RCTAutoHeightWebView
286
-          onLoadingStart={this.onLoadingStart}
287
-          onLoadingFinish={this.onLoadingFinish}
288
-          onLoadingError={this.onLoadingError}
289
-          originWhitelist={['.*']}
290
-          ref={this.getWebView}
291
-          style={styles.webView}
292
-          javaScriptEnabled={true}
293
-          injectedJavaScript={script}
294
-          scalesPageToFit={scalesPageToFit}
295
-          scrollEnabled={!!scrollEnabled}
296
-          source={source}
297
-          onMessage={this.onMessage}
298
-          messagingEnabled={true}
299
-          // below kitkat
300
-          onChange={this.onMessage}
301
-        />
302
-      </Animated.View>
303
-    );
304
-  }
305
-}
306
-
307
-const isBelowKitKat = Platform.Version < 19;
308
-
309
-const styles = StyleSheet.create({
310
-  container: {
311
-    backgroundColor: 'transparent'
312
-  },
313
-  webView: {
314
-    flex: 1,
315
-    backgroundColor: 'transparent'
316
-  }
317
-});
318
-
319
-const commonScript = `
320
-    ${getCurrentSize}
321
-    var wrapper = document.createElement("div");
322
-    wrapper.id = "wrapper";
323
-    while (document.body.firstChild instanceof Node) {
324
-        wrapper.appendChild(document.body.firstChild);
325
-    }
326
-    document.body.appendChild(wrapper);
327
-    var height = 0;
328
-`;
329
-
330
-const getBaseScript = isBelowKitKat
331
-  ? function(style) {
332
-      return `
333
-    ; 
334
-    ${commonScript}
335
-    var width = ${getWidth(style)};
336
-    function updateSize() {
337
-      var size = getSize(document.body.firstChild); 
338
-      height = size.height;
339
-      width = size.width;
340
-      AutoHeightWebView.send(JSON.stringify({ width, height }));
341
-    }
342
-    (function () {
343
-      AutoHeightWebView.onMessage = updateSize;
344
-      ${domMutationObserveScript}
345
-    } ());
346
-  `;
347
-    }
348
-  : function(style) {
349
-      return `
350
-    ; 
351
-    ${commonScript}
352
-    var width = ${getWidth(style)};
353
-    function updateSize() {
354
-      var size = getSize(document.body.firstChild); 
355
-      height = size.height;
356
-      width = size.width;
357
-      window.postMessage(JSON.stringify({ width, height }), '*');
358
-    }
359
-    (function () {
360
-      document.addEventListener("message", updateSize);
361
-      ${domMutationObserveScript}
362
-    } ());
363
-  `;
364
-    };
13
+export default webview;

+ 194
- 0
autoHeightWebView/index.android.old.js 查看文件

@@ -0,0 +1,194 @@
1
+'use strict';
2
+
3
+import React, { PureComponent } from 'react';
4
+
5
+import { Animated, Dimensions, StyleSheet, WebView } from 'react-native';
6
+
7
+import { androidPropTypes } from './propTypes.js';
8
+
9
+import Immutable from 'immutable';
10
+
11
+import { handleSizeUpdated, domMutationObserveScript } from './common.js';
12
+
13
+export default class AutoHeightWebView extends PureComponent {
14
+  static propTypes = androidPropTypes;
15
+
16
+  static defaultProps = {
17
+    scalesPageToFit: true,
18
+    enableBaseUrl: false,
19
+    enableAnimation: true,
20
+    animationDuration: 555,
21
+    heightOffset: 20
22
+  };
23
+
24
+  constructor(props) {
25
+    super(props);
26
+    props.enableAnimation && (this.opacityAnimatedValue = new Animated.Value(0));
27
+    this.state = {
28
+      isChangingSource: false,
29
+      height: 0,
30
+      heightOffset: 0,
31
+      script: baseScript
32
+    };
33
+  }
34
+
35
+  componentDidMount() {
36
+    this.startInterval();
37
+  }
38
+
39
+  componentWillReceiveProps(nextProps) {
40
+    // injectedJavaScript only works when webView reload (source changed)
41
+    if (Immutable.is(Immutable.fromJS(this.props.source), Immutable.fromJS(nextProps.source))) {
42
+      return;
43
+    } else {
44
+      this.setState(
45
+        {
46
+          isChangingSource: true,
47
+          height: 0,
48
+          heightOffset: 0
49
+        },
50
+        () => {
51
+          this.startInterval();
52
+          this.setState({ isChangingSource: false });
53
+        }
54
+      );
55
+    }
56
+    this.setState({ script: baseScript });
57
+  }
58
+
59
+  componentWillUnmount() {
60
+    this.stopInterval();
61
+  }
62
+
63
+  startInterval() {
64
+    this.finishInterval = false;
65
+    this.interval = setInterval(() => !this.finishInterval && this.webView.postMessage('getBodyHeight'), 205);
66
+  }
67
+
68
+  stopInterval() {
69
+    this.finishInterval = true;
70
+    clearInterval(this.interval);
71
+  }
72
+
73
+  onMessage = event => {
74
+    const height = parseInt(event.nativeEvent.data);
75
+    if (height && height !== this.state.height) {
76
+      const { enableAnimation, animationDuration, heightOffset, onSizeUpdated, style } = this.props;
77
+      enableAnimation && this.opacityAnimatedValue.setValue(0);
78
+      this.stopInterval();
79
+      this.setState(
80
+        {
81
+          heightOffset,
82
+          height
83
+        },
84
+        () => {
85
+          const currentWidth = Object.assign(styles.container, style).width;
86
+          enableAnimation
87
+            ? Animated.timing(this.opacityAnimatedValue, {
88
+                toValue: 1,
89
+                duration: animationDuration
90
+              }).start(() => handleSizeUpdated(height, currentWidth, onSizeUpdated))
91
+            : handleSizeUpdated(height, currentWidth, onSizeUpdated);
92
+        }
93
+      );
94
+    }
95
+    const { onMessage } = this.props;
96
+    onMessage && onMessage(event);
97
+  };
98
+
99
+  getWebView = webView => (this.webView = webView);
100
+
101
+  render() {
102
+    const { height, script, isChangingSource, heightOffset } = this.state;
103
+    const {
104
+      thirdPartyCookiesEnabled,
105
+      domStorageEnabled,
106
+      userAgent,
107
+      geolocationEnabled,
108
+      allowUniversalAccessFromFileURLs,
109
+      mixedContentMode,
110
+      onNavigationStateChange,
111
+      renderError,
112
+      originWhitelist,
113
+      mediaPlaybackRequiresUserAction,
114
+      scalesPageToFit,
115
+      enableAnimation,
116
+      source,
117
+      customScript,
118
+      style,
119
+      enableBaseUrl,
120
+      onError,
121
+      onLoad,
122
+      onLoadStart,
123
+      onLoadEnd
124
+    } = this.props;
125
+    let webViewSource = source;
126
+    if (enableBaseUrl) {
127
+      webViewSource = Object.assign({}, source, {
128
+        baseUrl: 'file:///android_asset/web/'
129
+      });
130
+    }
131
+    return (
132
+      <Animated.View
133
+        style={[
134
+          styles.container,
135
+          {
136
+            opacity: enableAnimation ? this.opacityAnimatedValue : 1,
137
+            height: height + heightOffset
138
+          },
139
+          style
140
+        ]}
141
+      >
142
+        {isChangingSource ? null : (
143
+          <WebView
144
+            onNavigationStateChange={onNavigationStateChange}
145
+            domStorageEnabled={domStorageEnabled}
146
+            thirdPartyCookiesEnabled={thirdPartyCookiesEnabled}
147
+            userAgent={userAgent}
148
+            geolocationEnabled={geolocationEnabled}
149
+            allowUniversalAccessFromFileURLs={allowUniversalAccessFromFileURLs}
150
+            mixedContentMode={mixedContentMode}
151
+            renderError={renderError}
152
+            mediaPlaybackRequiresUserAction={mediaPlaybackRequiresUserAction}
153
+            originWhitelist={originWhitelist}
154
+            ref={this.getWebView}
155
+            onMessage={this.onMessage}
156
+            onError={onError}
157
+            onLoad={onLoad}
158
+            onLoadStart={onLoadStart}
159
+            onLoadEnd={onLoadEnd}
160
+            style={styles.webView}
161
+            scalesPageToFit={scalesPageToFit}
162
+            javaScriptEnabled={true}
163
+            injectedJavaScript={script + customScript}
164
+            source={webViewSource}
165
+            messagingEnabled={true}
166
+          />
167
+        )}
168
+      </Animated.View>
169
+    );
170
+  }
171
+}
172
+
173
+const screenWidth = Dimensions.get('window').width;
174
+
175
+const styles = StyleSheet.create({
176
+  container: {
177
+    height: 50,
178
+    width: screenWidth,
179
+    backgroundColor: 'transparent'
180
+  },
181
+  webView: {
182
+    flex: 1,
183
+    backgroundColor: 'transparent'
184
+  }
185
+});
186
+
187
+const baseScript = `
188
+; (function () {
189
+    document.addEventListener('message', function (e) {
190
+        window.postMessage(String(document.body.offsetHeight));
191
+    });
192
+    ${domMutationObserveScript}
193
+} ());
194
+`;

+ 0
- 1
demo/android/app/build.gradle 查看文件

@@ -137,7 +137,6 @@ android {
137 137
 }
138 138
 
139 139
 dependencies {
140
-    compile project(':react-native-autoheight-webview')
141 140
     compile fileTree(dir: "libs", include: ["*.jar"])
142 141
     compile "com.android.support:appcompat-v7:${rootProject.ext.supportLibVersion}"
143 142
     compile "com.facebook.react:react-native:+"  // From node_modules

+ 1
- 3
demo/android/app/src/main/java/com/demo/MainApplication.java 查看文件

@@ -3,7 +3,6 @@ package com.demo;
3 3
 import android.app.Application;
4 4
 
5 5
 import com.facebook.react.ReactApplication;
6
-import com.iou90.autoheightwebview.AutoHeightWebViewPackage;
7 6
 import com.facebook.react.ReactNativeHost;
8 7
 import com.facebook.react.ReactPackage;
9 8
 import com.facebook.react.shell.MainReactPackage;
@@ -23,8 +22,7 @@ public class MainApplication extends Application implements ReactApplication {
23 22
     @Override
24 23
     protected List<ReactPackage> getPackages() {
25 24
       return Arrays.<ReactPackage>asList(
26
-          new MainReactPackage(),
27
-            new AutoHeightWebViewPackage()
25
+          new MainReactPackage()
28 26
       );
29 27
     }
30 28
 

+ 0
- 2
demo/android/settings.gradle 查看文件

@@ -1,5 +1,3 @@
1 1
 rootProject.name = 'demo'
2
-include ':react-native-autoheight-webview'
3
-project(':react-native-autoheight-webview').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-autoheight-webview/android')
4 2
 
5 3
 include ':app'