Przeglądaj źródła

add config to demo

iou90 6 lat temu
rodzic
commit
7d7638d503
2 zmienionych plików z 60 dodań i 19 usunięć
  1. 15
    19
      demo/App.js
  2. 45
    0
      demo/config.js

+ 15
- 19
demo/App.js Wyświetl plik

@@ -6,25 +6,22 @@ import { ScrollView, StyleSheet, Text, TouchableOpacity } from 'react-native';
6 6
 
7 7
 import AutoHeightWebView from 'react-native-autoheight-webview';
8 8
 
9
+import {
10
+  autoHeightHtml0,
11
+  autoHeightHtml1,
12
+  autoHeightScript,
13
+  autoHeightStyle0,
14
+  autoWidthHtml0,
15
+  autoWidthHtml1,
16
+  autoWidthScript,
17
+  autoWidthStyle0
18
+} from './config';
19
+
9 20
 export default class Explorer extends Component {
10 21
   constructor(props) {
11 22
     super(props);
12
-    this.html0 = `<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>`;
13
-    this.html1 = `Tags are great for describing the essence of your story in a single word or phrase, but stories are rarely about a single thing. 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”.`;
14
-    this.testStyle = `
15
-    p {
16
-      font-size: 25px !important;
17
-    }
18
-    `;
19
-    this.script0 = `
20
-    var styleElement = document.createElement('style');
21
-    styleElement.innerHTML = '${this.testStyle.replace(/\'/g, "\\'").replace(/\n/g, '\\n')}';
22
-    document.head.appendChild(styleElement)
23
-    `;
24
-    this.script1 = `document.body.style.background = 'cornflowerblue';`;
25
-    // this.script1 = null;
26 23
     this.state = {
27
-      html: this.html0,
24
+      html: autoHeightHtml0,
28 25
       script: null,
29 26
       webViewStyle: null,
30 27
       size: {
@@ -36,20 +33,19 @@ export default class Explorer extends Component {
36 33
 
37 34
   changeSource = () => {
38 35
     this.setState(prevState => ({
39
-      html: prevState.html === this.html0 ? this.html1 : this.html0
36
+      html: prevState.html === autoHeightHtml0 ? autoHeightHtml1 : autoHeightHtml0
40 37
     }));
41 38
   };
42 39
 
43 40
   changeStyle = () => {
44 41
     this.setState(prevState => ({
45
-      webViewStyle: prevState.webViewStyle == null ? this.testStyle : null
42
+      webViewStyle: prevState.webViewStyle == null ? autoHeightStyle0 : null
46 43
     }));
47 44
   };
48 45
 
49 46
   changeScript = () => {
50
-    // this.changeSource();
51 47
     this.setState(prevState => ({
52
-      script: prevState.script === this.script0 ? this.script1 : this.script0
48
+      script: prevState.script === null ? autoHeightScript : null
53 49
     }));
54 50
   };
55 51
 

+ 45
- 0
demo/config.js Wyświetl plik

@@ -0,0 +1,45 @@
1
+'use strict';
2
+
3
+const autoHeightHtml0 = `<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>`;
4
+
5
+const autoHeightHtml1 = `Tags are great for describing the essence of your story in a single word or phrase, but stories are rarely about a single thing. 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”.`;
6
+
7
+const autoHeightStyle0 = `
8
+    p {
9
+        font-size: 25px !important;
10
+    }
11
+`;
12
+
13
+const autoHeightStyle1 = `
14
+    p {
15
+        font-size: 12px !important;
16
+    }
17
+`;
18
+
19
+const autoHeightScript = `
20
+var styleElement = document.createElement('style');
21
+styleElement.innerHTML = '${autoHeightStyle1.replace(/\'/g, "\\'").replace(/\n/g, '\\n')}';
22
+document.head.appendChild(styleElement);
23
+document.body.style.background = 'cornflowerblue';
24
+`;
25
+
26
+const autoWidthHtml0 = ``;
27
+
28
+const autoWidthHtml1 = ``;
29
+
30
+const autoWidthStyle0 = ``;
31
+
32
+const autoWidthStyle1 = ``;
33
+
34
+const autoWidthScript = ``;
35
+
36
+export {
37
+  autoHeightHtml0,
38
+  autoHeightHtml1,
39
+  autoHeightStyle0,
40
+  autoHeightScript,
41
+  autoWidthHtml0,
42
+  autoWidthHtml1,
43
+  autoWidthScript,
44
+  autoWidthStyle0
45
+};