forked from uraway/react-native-mybrowser
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
102 lines (90 loc) · 2.48 KB
/
index.js
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
'use strict';
import React, {
Component,
View,
WebView,
Navigator,
} from 'react-native';
import AddressBar from './src/AddressBar';
import ToolBar from './src/ToolBar';
import styles from './src/styles';
const WEBVIEW_REF = 'webview';
export default class WebBrowser extends Component {
constructor(props) {
super(props);
this.state = {
url: this.props.url,
backButtonEnabled: false,
forwardButtonEnabled: false,
loading: true,
scalesPageToFit: true,
};
}
componentWillReceiveProps(nextProps) {
this.setState({
url: nextProps.url
});
}
goBack() {
this.refs[WEBVIEW_REF].goBack();
}
goForward() {
this.refs[WEBVIEW_REF].goForward();
}
load(url) {
this.setState({
url
});
}
reload() {
this.refs[WEBVIEW_REF].reload();
}
onNavigationStateChange(navigationState) {
this.setState({
backButtonEnabled: navigationState.canGoBack,
forwardButtonEnabled: navigationState.canGoForward,
url: navigationState.url,
title: navigationState.title,
loading: navigationState.loading,
scalesPageToFit: true
});
}
render() {
return (
<View style={styles.container} backgroundColor={this.props.backgroundColor}>
<View style={styles.header}>
<AddressBar
url={this.state.url}
title={this.state.title}
onBack={this.goBack.bind(this)}
backButtonEnabled={this.state.backButtonEnabled}
forwardButtonEnabled={this.state.forwardButtonEnabled}
onForward={this.goForward.bind(this)}
onReload={this.reload.bind(this)}
onLoad={(url)=>{this.load(url)}}
/>
</View>
<WebView
ref={WEBVIEW_REF}
automaticallyAdjustContentInsets={false}
style={styles.webView}
source={{ uri: this.state.url }}
javaScriptEnabled={true}
domStorageEnabled={true}
startInLoadingState={true}
decelerationRate="normal"
onNavigationStateChange={this.onNavigationStateChange.bind(this)}
/>
<ToolBar
url={this.state.url}
onBack={this.goBack.bind(this)}
backButtonEnabled={this.state.backButtonEnabled}
forwardButtonEnabled={this.state.forwardButtonEnabled}
onForward={this.goForward.bind(this)}
onReload={this.reload.bind(this)}
onLoad={(url)=>{this.load(url)}}
/>
</View>
);
}
}