-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpageview.js
53 lines (47 loc) · 1.5 KB
/
pageview.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
import React from 'react';
import { WebView, BackHandler } from 'react-native';
//import { WebView } from 'react-native-yunpeng-webview';
import styles from './styles.js';
export default class PageView extends React.Component {
constructor(props) {
super(props);
this.homeURL = this.props.navigation.getParam('link', '');
this.canGo = false;
}
static navigationOptions = ({ navigation }) => {
return {
title: navigation.getParam('title', 'Page view'),
headerTitleStyle: {
fontSize: 9
}
};
};
async componentDidMount() {
this.backHandler = BackHandler.addEventListener('hardwareBackPress', () => {
if (!this.canGo) {
this.props.navigation.navigate('Home');
} else {
this.webview.goBack();
}
return true;
});
}
componentWillUnmount() {
this.backHandler.remove();
}
render() {
return (
<WebView
ref={r => this.webview = r}
source={{ uri: this.props.navigation.getParam('link', '') }}
startInLoadingState
scalesPageToFit
javaScriptEnabled
style={{ margin: 3, flex: 1 }}
onNavigationStateChange={({ canGoBack }) => {
this.canGo = canGoBack;
}}
/>
);
}
}