|
@@ -11,12 +11,26 @@ export default class Explorer extends Component {
|
11
|
11
|
super(props);
|
12
|
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
|
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.script0 = '';
|
|
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
|
+ `;
|
15
|
24
|
this.script1 = `document.body.style.background = 'cornflowerblue';`;
|
|
25
|
+ // this.script1 = null;
|
16
|
26
|
this.state = {
|
17
|
27
|
html: this.html0,
|
18
|
|
- script: this.script0,
|
19
|
|
- height: 0
|
|
28
|
+ script: null,
|
|
29
|
+ webViewStyle: null,
|
|
30
|
+ size: {
|
|
31
|
+ height: 0,
|
|
32
|
+ width: 0
|
|
33
|
+ }
|
20
|
34
|
};
|
21
|
35
|
}
|
22
|
36
|
|
|
@@ -26,15 +40,21 @@ export default class Explorer extends Component {
|
26
|
40
|
}));
|
27
|
41
|
};
|
28
|
42
|
|
|
43
|
+ changeStyle = () => {
|
|
44
|
+ this.setState(prevState => ({
|
|
45
|
+ webViewStyle: prevState.webViewStyle == null ? this.testStyle : null
|
|
46
|
+ }));
|
|
47
|
+ };
|
|
48
|
+
|
29
|
49
|
changeScript = () => {
|
30
|
|
- this.changeSource();
|
|
50
|
+ // this.changeSource();
|
31
|
51
|
this.setState(prevState => ({
|
32
|
52
|
script: prevState.script === this.script0 ? this.script1 : this.script0
|
33
|
53
|
}));
|
34
|
54
|
};
|
35
|
55
|
|
36
|
56
|
render() {
|
37
|
|
- const { html, script, height } = this.state;
|
|
57
|
+ const { html, size, webViewStyle, script } = this.state;
|
38
|
58
|
return (
|
39
|
59
|
<ScrollView
|
40
|
60
|
style={{
|
|
@@ -46,6 +66,7 @@ export default class Explorer extends Component {
|
46
|
66
|
}}
|
47
|
67
|
>
|
48
|
68
|
<AutoHeightWebView
|
|
69
|
+ customStyle={webViewStyle}
|
49
|
70
|
onError={() => console.log('on error')}
|
50
|
71
|
onLoad={() => console.log('on load')}
|
51
|
72
|
onLoadStart={() => console.log('on load start')}
|
|
@@ -54,17 +75,22 @@ export default class Explorer extends Component {
|
54
|
75
|
console.log(result);
|
55
|
76
|
return true;
|
56
|
77
|
}}
|
57
|
|
- onHeightUpdated={height => this.setState({ height })}
|
|
78
|
+ onSizeUpdated={size => this.setState({ size })}
|
58
|
79
|
source={{ html }}
|
59
|
80
|
customScript={script}
|
60
|
81
|
/>
|
61
|
82
|
<TouchableOpacity onPress={this.changeSource} style={styles.button}>
|
62
|
83
|
<Text>change source</Text>
|
63
|
84
|
</TouchableOpacity>
|
|
85
|
+ <TouchableOpacity onPress={this.changeStyle} style={styles.button}>
|
|
86
|
+ <Text>change style</Text>
|
|
87
|
+ </TouchableOpacity>
|
64
|
88
|
<TouchableOpacity onPress={this.changeScript} style={styles.button}>
|
65
|
89
|
<Text>change script (have to change source to reload on android)</Text>
|
66
|
90
|
</TouchableOpacity>
|
67
|
|
- <Text style={{ padding: 5 }}>{height}</Text>
|
|
91
|
+ <Text style={{ padding: 5 }}>
|
|
92
|
+ height: {size.height}, width: {size.width}
|
|
93
|
+ </Text>
|
68
|
94
|
</ScrollView>
|
69
|
95
|
);
|
70
|
96
|
}
|