Browse Source

enable animation by default; bump version number to 0.2.1

iou90 7 years ago
parent
commit
2c77738d36
4 changed files with 25 additions and 24 deletions
  1. 6
    1
      README.md
  2. 13
    18
      autoHeightWebView/index.android.js
  3. 5
    4
      autoHeightWebView/index.ios.js
  4. 1
    1
      package.json

+ 6
- 1
README.md View File

14
 
14
 
15
 ```javascript
15
 ```javascript
16
 <AutoHeightWebView
16
 <AutoHeightWebView
17
+    onHeightUpdated={height => console.log(height)},
18
+    // offset of rn webview margin 
19
+    heightOffset={5}
20
+    // default width is the width of screen
21
+    style={customStyle}
22
+    // enable animation by default
17
     enableAnimation={true},
23
     enableAnimation={true},
18
     // only works on enable animation
24
     // only works on enable animation
19
     animationDuration={255},
25
     animationDuration={255},
20
-    onHeightUpdated={height => console.log(height)}
21
     // or uri
26
     // or uri
22
     source={{ html: `<p style="font-weight: 400;font-style: normal;font-size: 21px;line-height: 1.58;letter-spacing: -.003em;">Tags are great for describing the essence of your story in a single word or phrase, but stories are rarely about a single thing. <span style="background-color: transparent !important;background-image: linear-gradient(to bottom, rgba(146, 249, 190, 1), rgba(146, 249, 190, 1));">If I pen a story about moving across the country to start a new job in a car with my husband, two cats, a dog, and a tarantula, I wouldn’t only tag the piece with “moving”. I’d also use the tags “pets”, “marriage”, “career change”, and “travel tips”.</span></p>` }}
27
     source={{ html: `<p style="font-weight: 400;font-style: normal;font-size: 21px;line-height: 1.58;letter-spacing: -.003em;">Tags are great for describing the essence of your story in a single word or phrase, but stories are rarely about a single thing. <span style="background-color: transparent !important;background-image: linear-gradient(to bottom, rgba(146, 249, 190, 1), rgba(146, 249, 190, 1));">If I pen a story about moving across the country to start a new job in a car with my husband, two cats, a dog, and a tarantula, I wouldn’t only tag the piece with “moving”. I’d also use the tags “pets”, “marriage”, “career change”, and “travel tips”.</span></p>` }}
23
     // use local or remote files
28
     // use local or remote files

+ 13
- 18
autoHeightWebView/index.android.js View File

74
         this.setState({ script: currentScript });
74
         this.setState({ script: currentScript });
75
     }
75
     }
76
 
76
 
77
-    // componentDidUpdate(prevProps, prevState) {
78
-    //     // redisplay webview when changing source
79
-    //     if (this.state.isChangingSource) {
80
-    //         this.startInterval();
81
-    //         this.setState({ isChangingSource: false });
82
-    //     }
83
-    // }
84
-
85
     componentWillUnmount() {
77
     componentWillUnmount() {
86
         this.stopInterval();
78
         this.stopInterval();
87
         if (IsBelowKitKat) {
79
         if (IsBelowKitKat) {
94
         this.onMessage(body.message);
86
         this.onMessage(body.message);
95
     }
87
     }
96
 
88
 
97
-    postMessage(data) {
98
-        UIManager.dispatchViewManagerCommand(
99
-            findNodeHandle(this.webview),
100
-            UIManager.RCTAutoHeightWebView.Commands.postMessage,
101
-            [String(data)]
102
-        );
103
-    };
104
-
105
     // below kitkat
89
     // below kitkat
106
     sendToWebView(message) {
90
     sendToWebView(message) {
107
         UIManager.dispatchViewManagerCommand(
91
         UIManager.dispatchViewManagerCommand(
111
         );
95
         );
112
     }
96
     }
113
 
97
 
98
+    postMessage(data) {
99
+        UIManager.dispatchViewManagerCommand(
100
+            findNodeHandle(this.webview),
101
+            UIManager.RCTAutoHeightWebView.Commands.postMessage,
102
+            [String(data)]
103
+        );
104
+    };
105
+
114
     startInterval() {
106
     startInterval() {
115
         this.finishInterval = false;
107
         this.finishInterval = false;
116
         this.interval = setInterval(() => {
108
         this.interval = setInterval(() => {
209
 }
201
 }
210
 
202
 
211
 AutoHeightWebView.propTypes = {
203
 AutoHeightWebView.propTypes = {
212
-    enableAnimation: PropTypes.bool,
213
     source: WebView.propTypes.source,
204
     source: WebView.propTypes.source,
214
     onHeightUpdated: PropTypes.func,
205
     onHeightUpdated: PropTypes.func,
215
     customScript: PropTypes.string,
206
     customScript: PropTypes.string,
216
-    // offset rn webview margin
207
+    enableAnimation: PropTypes.bool,
208
+    // only works on enable animation
209
+    animationDuration: PropTypes.number,
210
+    // offset of rn webview margin
217
     heightOffset: PropTypes.number,
211
     heightOffset: PropTypes.number,
218
     // baseUrl not work in android 4.3 or below version
212
     // baseUrl not work in android 4.3 or below version
219
     enableBaseUrl: PropTypes.bool,
213
     enableBaseUrl: PropTypes.bool,
227
 }
221
 }
228
 
222
 
229
 AutoHeightWebView.defaultProps = {
223
 AutoHeightWebView.defaultProps = {
224
+    enableAnimation: true,
230
     animationDuration: 555,
225
     animationDuration: 555,
231
     enableBaseUrl: false,
226
     enableBaseUrl: false,
232
     heightOffset: 20
227
     heightOffset: 20

+ 5
- 4
autoHeightWebView/index.ios.js View File

105
 }
105
 }
106
 
106
 
107
 AutoHeightWebView.propTypes = {
107
 AutoHeightWebView.propTypes = {
108
-    enableAnimation: PropTypes.bool,
109
-    // only works on enable animation
110
-    animationDuration: PropTypes.number,
111
     source: WebView.propTypes.source,
108
     source: WebView.propTypes.source,
112
     onHeightUpdated: PropTypes.func,
109
     onHeightUpdated: PropTypes.func,
113
     customScript: PropTypes.string,
110
     customScript: PropTypes.string,
114
-    // offset rn webview margin
111
+    enableAnimation: PropTypes.bool,
112
+    // only works on enable animation
113
+    animationDuration: PropTypes.number,
114
+    // offset of rn webview margin
115
     heightOffset: PropTypes.number,
115
     heightOffset: PropTypes.number,
116
     style: View.propTypes.style,
116
     style: View.propTypes.style,
117
     // add web/files... to project root
117
     // add web/files... to project root
123
 }
123
 }
124
 
124
 
125
 AutoHeightWebView.defaultProps = {
125
 AutoHeightWebView.defaultProps = {
126
+    enableAnimation: true,
126
     animationDuration: 555,
127
     animationDuration: 555,
127
     heightOffset: 12
128
     heightOffset: 12
128
 }
129
 }

+ 1
- 1
package.json View File

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