|
@@ -8,6 +8,8 @@ import Touchable from "react-native-platform-touchable";
|
8
|
8
|
import CustomMaterialIcon from "../components/CustomMaterialIcon";
|
9
|
9
|
import ThemeManager from "../utils/ThemeManager";
|
10
|
10
|
import BaseContainer from "../components/BaseContainer";
|
|
11
|
+import {ScreenOrientation} from 'expo';
|
|
12
|
+import {NavigationActions} from 'react-navigation';
|
11
|
13
|
|
12
|
14
|
type Props = {
|
13
|
15
|
navigation: Object,
|
|
@@ -23,10 +25,14 @@ type Props = {
|
23
|
25
|
hasFooter: boolean,
|
24
|
26
|
}
|
25
|
27
|
|
|
28
|
+type State = {
|
|
29
|
+ isLandscape: boolean,
|
|
30
|
+}
|
|
31
|
+
|
26
|
32
|
/**
|
27
|
33
|
* Class defining a webview screen.
|
28
|
34
|
*/
|
29
|
|
-export default class WebViewScreen extends React.Component<Props> {
|
|
35
|
+export default class WebViewScreen extends React.Component<Props, State> {
|
30
|
36
|
|
31
|
37
|
static defaultProps = {
|
32
|
38
|
hasBackButton: false,
|
|
@@ -34,7 +40,52 @@ export default class WebViewScreen extends React.Component<Props> {
|
34
|
40
|
hasFooter: true,
|
35
|
41
|
};
|
36
|
42
|
|
|
43
|
+ state = {
|
|
44
|
+ isLandscape: false,
|
|
45
|
+ };
|
|
46
|
+
|
37
|
47
|
webviewArray: Array<WebView> = [];
|
|
48
|
+ willFocusSubscription: function;
|
|
49
|
+ willBlurSubscription: function;
|
|
50
|
+
|
|
51
|
+ /**
|
|
52
|
+ * Register for blur event to close side menu on screen change
|
|
53
|
+ */
|
|
54
|
+ componentDidMount() {
|
|
55
|
+ this.willFocusSubscription = this.props.navigation.addListener(
|
|
56
|
+ 'willFocus',
|
|
57
|
+ payload => {
|
|
58
|
+ ScreenOrientation.unlockAsync();
|
|
59
|
+ ScreenOrientation.addOrientationChangeListener((OrientationChangeEvent) => {
|
|
60
|
+ let isLandscape = OrientationChangeEvent.orientationInfo.orientation === ScreenOrientation.Orientation.LANDSCAPE ||
|
|
61
|
+ OrientationChangeEvent.orientationInfo.orientation === ScreenOrientation.Orientation.LANDSCAPE_LEFT ||
|
|
62
|
+ OrientationChangeEvent.orientationInfo.orientation === ScreenOrientation.Orientation.LANDSCAPE_RIGHT;
|
|
63
|
+ this.setState({isLandscape: isLandscape});
|
|
64
|
+ const setParamsAction = NavigationActions.setParams({
|
|
65
|
+ params: {showTabBar: !isLandscape},
|
|
66
|
+ key: this.props.navigation.state.key,
|
|
67
|
+ });
|
|
68
|
+ this.props.navigation.dispatch(setParamsAction);
|
|
69
|
+ });
|
|
70
|
+ }
|
|
71
|
+ );
|
|
72
|
+ this.willBlurSubscription = this.props.navigation.addListener(
|
|
73
|
+ 'willBlur',
|
|
74
|
+ payload => {
|
|
75
|
+ ScreenOrientation.lockAsync(ScreenOrientation.Orientation.PORTRAIT);
|
|
76
|
+ }
|
|
77
|
+ );
|
|
78
|
+ }
|
|
79
|
+
|
|
80
|
+ /**
|
|
81
|
+ * Unregister from event when un-mounting components
|
|
82
|
+ */
|
|
83
|
+ componentWillUnmount() {
|
|
84
|
+ if (this.willBlurSubscription !== undefined)
|
|
85
|
+ this.willBlurSubscription.remove();
|
|
86
|
+ if (this.willFocusSubscription !== undefined)
|
|
87
|
+ this.willFocusSubscription.remove();
|
|
88
|
+ }
|
38
|
89
|
|
39
|
90
|
openWebLink(url: string) {
|
40
|
91
|
Linking.openURL(url).catch((err) => console.error('Error opening link', err));
|
|
@@ -138,7 +189,8 @@ export default class WebViewScreen extends React.Component<Props> {
|
138
|
189
|
headerTitle={this.props.headerTitle}
|
139
|
190
|
headerRightButton={this.getRefreshButton()}
|
140
|
191
|
hasBackButton={this.props.hasHeaderBackButton}
|
141
|
|
- hasSideMenu={this.props.hasSideMenu}>
|
|
192
|
+ hasSideMenu={this.props.hasSideMenu}
|
|
193
|
+ isHeaderVisible={!this.state.isLandscape}>
|
142
|
194
|
{this.props.data.length === 1 ?
|
143
|
195
|
this.getWebview(this.props.data[0]) :
|
144
|
196
|
<Tabs
|