forked from chitezh/react-native-svg-image
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
69 lines (63 loc) · 1.66 KB
/
index.js
File metadata and controls
69 lines (63 loc) · 1.66 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
import React, { PureComponent } from 'react';
import { View, Platform, WebView, ActivityIndicator, StyleSheet } from 'react-native';
import PropTypes from 'prop-types';
export default class Html extends PureComponent {
static propTypes = {
style: PropTypes.any,
html: PropTypes.string,
showWebviewLoader: PropTypes.bool,
height: PropTypes.number,
};
static defaultProps = {
style: {},
html: '',
showWebviewLoader: Platform.OS === 'android',
height: null,
};
renderLoader = () => (
<View style={[this.props.style, { flex: 1, alignItems: 'center', justifyContent: 'center' }]}>
<ActivityIndicator />
</View>
);
render() {
const { showWebviewLoader, html, style, ...restOfProps } = this.props;
const { height, width } = StyleSheet.flatten(style || []);
const rawHtml = `
<!DOCTYPE html>\n
<html>
<head>
<style type="text/css">
div {
width: ${width ? width+'px' : 'auto'};
height: ${height ? height+'px' : 'auto'};
overflow: none;
}
div > * {
width: 100%;
height: 100%;
margin: 0 auto;
}
body {
margin: 0;
}
</style>
</head>
<body>
<div>
${html}
</div>
</body>
</html>
`;
return (
<WebView
startInLoadingState={showWebviewLoader}
renderLoading={showWebviewLoader ? this.renderLoader : null}
scalesPageToFit={false}
style={style}
{...restOfProps}
source={{ html: rawHtml }}
/>
);
}
}