|
@@ -10,21 +10,28 @@ import {
|
10
|
10
|
autoHeightHtml0,
|
11
|
11
|
autoHeightHtml1,
|
12
|
12
|
autoHeightScript,
|
13
|
|
- autoHeightStyle0,
|
14
|
13
|
autoWidthHtml0,
|
15
|
14
|
autoWidthHtml1,
|
16
|
15
|
autoWidthScript,
|
17
|
|
- autoWidthStyle0
|
|
16
|
+ style0,
|
|
17
|
+ inlineBodyStyle
|
18
|
18
|
} from './config';
|
19
|
19
|
|
20
|
20
|
export default class Explorer extends Component {
|
21
|
21
|
constructor(props) {
|
22
|
22
|
super(props);
|
23
|
23
|
this.state = {
|
24
|
|
- html: autoHeightHtml0,
|
25
|
|
- script: null,
|
26
|
|
- webViewStyle: null,
|
27
|
|
- size: {
|
|
24
|
+ heightHtml: autoHeightHtml0,
|
|
25
|
+ heightScript: null,
|
|
26
|
+ heightStyle: null,
|
|
27
|
+ heightSize: {
|
|
28
|
+ height: 0,
|
|
29
|
+ width: 0
|
|
30
|
+ },
|
|
31
|
+ widthHtml: autoWidthHtml0,
|
|
32
|
+ widthScript: null,
|
|
33
|
+ widthStyle: inlineBodyStyle,
|
|
34
|
+ widthSize: {
|
28
|
35
|
height: 0,
|
29
|
36
|
width: 0
|
30
|
37
|
}
|
|
@@ -33,27 +40,40 @@ export default class Explorer extends Component {
|
33
|
40
|
|
34
|
41
|
changeSource = () => {
|
35
|
42
|
this.setState(prevState => ({
|
36
|
|
- html: prevState.html === autoHeightHtml0 ? autoHeightHtml1 : autoHeightHtml0
|
|
43
|
+ widthHtml: prevState.widthHtml === autoWidthHtml0 ? autoWidthHtml1 : autoWidthHtml0,
|
|
44
|
+ heightHtml: prevState.heightHtml === autoHeightHtml0 ? autoHeightHtml1 : autoHeightHtml0
|
37
|
45
|
}));
|
38
|
46
|
};
|
39
|
47
|
|
40
|
48
|
changeStyle = () => {
|
41
|
49
|
this.setState(prevState => ({
|
42
|
|
- webViewStyle: prevState.webViewStyle == null ? autoHeightStyle0 : null
|
|
50
|
+ widthStyle: prevState.widthStyle == inlineBodyStyle ? style0 + inlineBodyStyle : inlineBodyStyle,
|
|
51
|
+ heightStyle: prevState.heightStyle == null ? style0 : null
|
43
|
52
|
}));
|
44
|
53
|
};
|
45
|
54
|
|
46
|
55
|
changeScript = () => {
|
47
|
56
|
this.setState(prevState => ({
|
48
|
|
- script: prevState.script === null ? autoHeightScript : null
|
|
57
|
+ widthScript: prevState.widthScript === null ? autoWidthScript : null,
|
|
58
|
+ heightScript: prevState.heightScript === null ? autoHeightScript : null
|
49
|
59
|
}));
|
50
|
60
|
};
|
51
|
61
|
|
52
|
62
|
render() {
|
53
|
|
- const { html, size, webViewStyle, script } = this.state;
|
|
63
|
+ const {
|
|
64
|
+ heightHtml,
|
|
65
|
+ heightSize,
|
|
66
|
+ heightStyle,
|
|
67
|
+ heightScript,
|
|
68
|
+ widthHtml,
|
|
69
|
+ widthSize,
|
|
70
|
+ widthStyle,
|
|
71
|
+ widthScript
|
|
72
|
+ } = this.state;
|
54
|
73
|
return (
|
55
|
74
|
<ScrollView
|
56
|
75
|
style={{
|
|
76
|
+ paddingTop: 45,
|
57
|
77
|
backgroundColor: 'lightyellow'
|
58
|
78
|
}}
|
59
|
79
|
contentContainerStyle={{
|
|
@@ -62,19 +82,42 @@ export default class Explorer extends Component {
|
62
|
82
|
}}
|
63
|
83
|
>
|
64
|
84
|
<AutoHeightWebView
|
65
|
|
- customStyle={webViewStyle}
|
66
|
|
- onError={() => console.log('on error')}
|
67
|
|
- onLoad={() => console.log('on load')}
|
68
|
|
- onLoadStart={() => console.log('on load start')}
|
69
|
|
- onLoadEnd={() => console.log('on load end')}
|
|
85
|
+ customStyle={heightStyle}
|
|
86
|
+ onError={() => console.log('height on error')}
|
|
87
|
+ onLoad={() => console.log('height on load')}
|
|
88
|
+ onLoadStart={() => console.log('height on load start')}
|
|
89
|
+ onLoadEnd={() => console.log('height on load end')}
|
70
|
90
|
onShouldStartLoadWithRequest={result => {
|
71
|
91
|
console.log(result);
|
72
|
92
|
return true;
|
73
|
93
|
}}
|
74
|
|
- onSizeUpdated={size => this.setState({ size })}
|
75
|
|
- source={{ html }}
|
76
|
|
- customScript={script}
|
|
94
|
+ onSizeUpdated={heightSize => this.setState({ heightSize })}
|
|
95
|
+ source={{ html: heightHtml }}
|
|
96
|
+ customScript={heightScript}
|
77
|
97
|
/>
|
|
98
|
+ <Text style={{ padding: 5 }}>
|
|
99
|
+ height: {heightSize.height}, width: {heightSize.width}
|
|
100
|
+ </Text>
|
|
101
|
+ <AutoHeightWebView
|
|
102
|
+ style={{
|
|
103
|
+ marginTop: 15
|
|
104
|
+ }}
|
|
105
|
+ customStyle={widthStyle}
|
|
106
|
+ onError={() => console.log('width on error')}
|
|
107
|
+ onLoad={() => console.log('width on load')}
|
|
108
|
+ onLoadStart={() => console.log('width on load start')}
|
|
109
|
+ onLoadEnd={() => console.log('width on load end')}
|
|
110
|
+ onShouldStartLoadWithRequest={result => {
|
|
111
|
+ console.log(result);
|
|
112
|
+ return true;
|
|
113
|
+ }}
|
|
114
|
+ onSizeUpdated={widthSize => this.setState({ widthSize })}
|
|
115
|
+ source={{ html: widthHtml }}
|
|
116
|
+ customScript={widthScript}
|
|
117
|
+ />
|
|
118
|
+ <Text style={{ padding: 5 }}>
|
|
119
|
+ height: {widthSize.height}, width: {widthSize.width}
|
|
120
|
+ </Text>
|
78
|
121
|
<TouchableOpacity onPress={this.changeSource} style={styles.button}>
|
79
|
122
|
<Text>change source</Text>
|
80
|
123
|
</TouchableOpacity>
|
|
@@ -82,11 +125,8 @@ export default class Explorer extends Component {
|
82
|
125
|
<Text>change style</Text>
|
83
|
126
|
</TouchableOpacity>
|
84
|
127
|
<TouchableOpacity onPress={this.changeScript} style={styles.button}>
|
85
|
|
- <Text>change script (have to change source to reload on android)</Text>
|
|
128
|
+ <Text>change heightScript</Text>
|
86
|
129
|
</TouchableOpacity>
|
87
|
|
- <Text style={{ padding: 5 }}>
|
88
|
|
- height: {size.height}, width: {size.width}
|
89
|
|
- </Text>
|
90
|
130
|
</ScrollView>
|
91
|
131
|
);
|
92
|
132
|
}
|