-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.tsx
61 lines (53 loc) · 1.39 KB
/
index.tsx
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
import WebViewComponent from 'react-native-webview';
import React, { Component } from 'react';
import { ActivityIndicator, View, StyleSheet } from 'react-native';
import ScriptManager from './scripts';
import { GetScriptOptions } from './scripts';
interface Props {
[key: string]: any;
onRef?(ref: any): void;
source: any;
scriptOptions: GetScriptOptions;
scriptLoading?: {
style?: any;
color?: string;
}
}
export default class Webview extends Component<Props> {
state = {
injectedJavaScript: '',
}
componentDidMount() {
this.getScripts();
}
getScripts = async () => {
const scripts = await ScriptManager.getScripts(this.props.scriptOptions);
this.setState({
injectedJavaScript: ScriptManager.combineScripts(scripts),
});
}
render() {
if (!this.state.injectedJavaScript && this.props.scriptLoading) {
return (
<View style={[styles.loadingContainer, this.props.scriptLoading.style]}>
<ActivityIndicator color={this.props.scriptLoading.color || "black"} />
</View>
);
};
return (
<WebViewComponent
ref={this.props.onRef}
source={this.props.source}
injectedJavaScript={this.state.injectedJavaScript}
{...this.props}
/>
);
}
}
const styles = StyleSheet.create({
loadingContainer: {
flex: 1,
justifyContent: 'center',
alignItems: 'center',
}
});