瀏覽代碼

use stylesheet; bump version number to 0.2.3

iou90 7 年之前
父節點
當前提交
41cd08a3fb
共有 3 個檔案被更改,包括 29 行新增15 行删除
  1. 14
    7
      autoHeightWebView/index.android.js
  2. 14
    7
      autoHeightWebView/index.ios.js
  3. 1
    1
      package.json

+ 14
- 7
autoHeightWebView/index.android.js 查看文件

@@ -11,6 +11,7 @@ import {
11 11
     Animated,
12 12
     DeviceEventEmitter,
13 13
     Dimensions,
14
+    StyleSheet,
14 15
     Platform,
15 16
     UIManager,
16 17
     View,
@@ -172,20 +173,15 @@ export default class AutoHeightWebView extends ImmutableComponent {
172 173
             webViewSource = Object.assign({}, source, { baseUrl: 'file:///android_asset/web/' });
173 174
         }
174 175
         return (
175
-            <Animated.View style={[{
176
+            <Animated.View style={[Styles.container, {
176 177
                 opacity: enableAnimation ? this.opacityAnimatedValue : 1,
177
-                width: ScreenWidth,
178 178
                 height: height + heightOffset,
179
-                backgroundColor: 'transparent'
180 179
             }, style]}>
181 180
                 {
182 181
                     isChangingSource ? null :
183 182
                         <RCTAutoHeightWebView
184 183
                             ref={webview => this.webview = webview}
185
-                            style={{
186
-                                flex: 1,
187
-                                backgroundColor: 'transparent'
188
-                            }}
184
+                            style={Styles.webView}
189 185
                             javaScriptEnabled={true}
190 186
                             injectedJavaScript={script + customScript}
191 187
                             scrollEnabled={false}
@@ -231,6 +227,17 @@ const ScreenWidth = Dimensions.get('window').width;
231 227
 
232 228
 const IsBelowKitKat = Platform.Version < 19;
233 229
 
230
+const Styles = StyleSheet.create({
231
+    container: {
232
+        width: ScreenWidth,
233
+        backgroundColor: 'transparent'
234
+    },
235
+    webView: {
236
+        flex: 1,
237
+        backgroundColor: 'transparent'
238
+    }
239
+});
240
+
234 241
 const BaseScript =
235 242
     IsBelowKitKat ?
236 243
         `

+ 14
- 7
autoHeightWebView/index.ios.js 查看文件

@@ -8,6 +8,7 @@ import React, {
8 8
 import {
9 9
     Animated,
10 10
     Dimensions,
11
+    StyleSheet,
11 12
     View,
12 13
     WebView
13 14
 } from 'react-native';
@@ -84,17 +85,12 @@ export default class AutoHeightWebView extends ImmutableComponent {
84 85
         const { enableAnimation, source, heightOffset, customScript, style } = this.props;
85 86
         const webViewSource = Object.assign({}, source, { baseUrl: 'web/' });
86 87
         return (
87
-            <Animated.View style={[{
88
+            <Animated.View style={[Styles.container, {
88 89
                 opacity: enableAnimation ? this.opacityAnimatedValue : 1,
89
-                width: ScreenWidth,
90 90
                 height: height + heightOffset,
91
-                backgroundColor: 'transparent'
92 91
             }, style]}>
93 92
                 <WebView
94
-                    style={{
95
-                        flex: 1,
96
-                        backgroundColor: 'transparent'
97
-                    }}
93
+                    style={Styles.webView}
98 94
                     injectedJavaScript={script + customScript}
99 95
                     scrollEnabled={false}
100 96
                     source={webViewSource}
@@ -130,6 +126,17 @@ AutoHeightWebView.defaultProps = {
130 126
 
131 127
 const ScreenWidth = Dimensions.get('window').width;
132 128
 
129
+const Styles = StyleSheet.create({
130
+    container: {
131
+        width: ScreenWidth,
132
+        backgroundColor: 'transparent'
133
+    },
134
+    webView: {
135
+        flex: 1,
136
+        backgroundColor: 'transparent'
137
+    }
138
+});
139
+
133 140
 // note that it can not get height when there are only text objects in a html body which does not make any sense 
134 141
 const BaseScript =
135 142
     `

+ 1
- 1
package.json 查看文件

@@ -1,6 +1,6 @@
1 1
 {
2 2
   "name": "react-native-autoheight-webview",
3
-  "version": "0.2.2",
3
+  "version": "0.2.3",
4 4
   "description": "An auto height webview for React Native",
5 5
   "main": "autoHeightWebView",
6 6
   "files": [