Browse Source

Hide webview header and tabs on landscape

keplyx 4 years ago
parent
commit
bb0ff390a9

+ 30
- 15
components/BaseContainer.js View File

18
     hasTabs: boolean,
18
     hasTabs: boolean,
19
     hasBackButton: boolean,
19
     hasBackButton: boolean,
20
     hasSideMenu: boolean,
20
     hasSideMenu: boolean,
21
+    isHeaderVisible: boolean
21
 }
22
 }
22
 
23
 
23
 type State = {
24
 type State = {
34
         hasTabs: false,
35
         hasTabs: false,
35
         hasBackButton: false,
36
         hasBackButton: false,
36
         hasSideMenu: true,
37
         hasSideMenu: true,
38
+        isHeaderVisible: true,
37
     };
39
     };
38
 
40
 
39
 
41
 
95
 
97
 
96
 
98
 
97
     render() {
99
     render() {
98
-        return (
99
-            <View style={{
100
-                backgroundColor: ThemeManager.getCurrentThemeVariables().sideMenuBgColor,
101
-                width: '100%',
102
-                height: '100%'
103
-            }}>
104
-                {this.props.hasSideMenu ?
105
-                    <CustomSideMenu
106
-                        navigation={this.props.navigation} isOpen={this.state.isOpen}
107
-                        onChange={(isOpen) => this.updateMenuState(isOpen)}>
108
-                        {this.getMainContainer()}
109
-                    </CustomSideMenu> :
110
-                    this.getMainContainer()}
111
-            </View>
112
-        );
100
+        if (this.props.isHeaderVisible) {
101
+            return (
102
+                <View style={{
103
+                    backgroundColor: ThemeManager.getCurrentThemeVariables().sideMenuBgColor,
104
+                    width: '100%',
105
+                    height: '100%'
106
+                }}>
107
+                    {this.props.hasSideMenu ?
108
+                        <CustomSideMenu
109
+                            navigation={this.props.navigation} isOpen={this.state.isOpen}
110
+                            onChange={(isOpen) => this.updateMenuState(isOpen)}>
111
+                            {this.getMainContainer()}
112
+                        </CustomSideMenu> :
113
+                        this.getMainContainer()}
114
+                </View>
115
+            );
116
+        } else {
117
+            return (
118
+                <View style={{
119
+                    backgroundColor: ThemeManager.getCurrentThemeVariables().sideMenuBgColor,
120
+                    width: '100%',
121
+                    height: '100%'
122
+                }}>
123
+                    {this.props.children}
124
+                </View>
125
+            );
126
+        }
127
+
113
     }
128
     }
114
 }
129
 }

+ 54
- 2
components/WebViewScreen.js View File

8
 import CustomMaterialIcon from "../components/CustomMaterialIcon";
8
 import CustomMaterialIcon from "../components/CustomMaterialIcon";
9
 import ThemeManager from "../utils/ThemeManager";
9
 import ThemeManager from "../utils/ThemeManager";
10
 import BaseContainer from "../components/BaseContainer";
10
 import BaseContainer from "../components/BaseContainer";
11
+import {ScreenOrientation} from 'expo';
12
+import {NavigationActions} from 'react-navigation';
11
 
13
 
12
 type Props = {
14
 type Props = {
13
     navigation: Object,
15
     navigation: Object,
23
     hasFooter: boolean,
25
     hasFooter: boolean,
24
 }
26
 }
25
 
27
 
28
+type State = {
29
+    isLandscape: boolean,
30
+}
31
+
26
 /**
32
 /**
27
  * Class defining a webview screen.
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
     static defaultProps = {
37
     static defaultProps = {
32
         hasBackButton: false,
38
         hasBackButton: false,
34
         hasFooter: true,
40
         hasFooter: true,
35
     };
41
     };
36
 
42
 
43
+    state = {
44
+        isLandscape: false,
45
+    };
46
+
37
     webviewArray: Array<WebView> = [];
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
     openWebLink(url: string) {
90
     openWebLink(url: string) {
40
         Linking.openURL(url).catch((err) => console.error('Error opening link', err));
91
         Linking.openURL(url).catch((err) => console.error('Error opening link', err));
138
                 headerTitle={this.props.headerTitle}
189
                 headerTitle={this.props.headerTitle}
139
                 headerRightButton={this.getRefreshButton()}
190
                 headerRightButton={this.getRefreshButton()}
140
                 hasBackButton={this.props.hasHeaderBackButton}
191
                 hasBackButton={this.props.hasHeaderBackButton}
141
-                hasSideMenu={this.props.hasSideMenu}>
192
+                hasSideMenu={this.props.hasSideMenu}
193
+                isHeaderVisible={!this.state.isLandscape}>
142
                 {this.props.data.length === 1 ?
194
                 {this.props.data.length === 1 ?
143
                     this.getWebview(this.props.data[0]) :
195
                     this.getWebview(this.props.data[0]) :
144
                     <Tabs
196
                     <Tabs

+ 10
- 2
navigation/MainTabNavigator.js View File

24
         Planning: {screen: PlanningScreen,},
24
         Planning: {screen: PlanningScreen,},
25
         Proxiwash: {screen: ProxiwashScreen,},
25
         Proxiwash: {screen: ProxiwashScreen,},
26
         Proximo: {screen: ProximoMainScreen,},
26
         Proximo: {screen: ProximoMainScreen,},
27
-        Planex: {screen: PlanexScreen},
27
+        Planex: {
28
+            screen: PlanexScreen,
29
+            navigationOptions: ({ navigation }) => {
30
+                const showTabBar = navigation.state && navigation.state.params ? navigation.state.params.showTabBar : true;
31
+                return {
32
+                    tabBarVisible: showTabBar,
33
+                };
34
+            },},
28
     }, {
35
     }, {
29
         defaultNavigationOptions: ({navigation}) => ({
36
         defaultNavigationOptions: ({navigation}) => ({
30
             tabBarIcon: ({focused, horizontal, tintColor}) => {
37
             tabBarIcon: ({focused, horizontal, tintColor}) => {
31
                 let icon = TAB_ICONS[navigation.state.routeName];
38
                 let icon = TAB_ICONS[navigation.state.routeName];
32
 
39
 
33
                 return <CustomMaterialIcon icon={icon} color={tintColor}/>;
40
                 return <CustomMaterialIcon icon={icon} color={tintColor}/>;
34
-            }
41
+            },
42
+            tabBarVisible: true,
35
         }),
43
         }),
36
         order: ['Proximo', 'Planning', 'Home', 'Proxiwash', 'Planex'],
44
         order: ['Proximo', 'Planning', 'Home', 'Proxiwash', 'Planex'],
37
         initialRouteName: initialRoute,
45
         initialRouteName: initialRoute,

+ 2
- 2
screens/AvailableRoomScreen.js View File

30
             'document.querySelector(\'head\').innerHTML += \'<meta name="viewport" content="width=device-width, initial-scale=1.0">\';' +
30
             'document.querySelector(\'head\').innerHTML += \'<meta name="viewport" content="width=device-width, initial-scale=1.0">\';' +
31
             'document.querySelector(\'head\').innerHTML += \'<link rel="stylesheet" href="' + CUSTOM_CSS_GENERAL + '" type="text/css"/>\';' +
31
             'document.querySelector(\'head\').innerHTML += \'<link rel="stylesheet" href="' + CUSTOM_CSS_GENERAL + '" type="text/css"/>\';' +
32
             'let header = $(".table tbody tr:first");' +
32
             'let header = $(".table tbody tr:first");' +
33
-            '$("table").prepend("<thead></thead>");' +
34
-            '$("thead").append(header);';
33
+            '$("table").prepend("<thead></thead>");true;' + // Fix for crash on ios
34
+            '$("thead").append(header);true;';
35
 
35
 
36
         this.customBibInjectedJS =
36
         this.customBibInjectedJS =
37
             'document.querySelector(\'head\').innerHTML += \'<meta name="viewport" content="width=device-width, initial-scale=1.0">\';' +
37
             'document.querySelector(\'head\').innerHTML += \'<meta name="viewport" content="width=device-width, initial-scale=1.0">\';' +

Loading…
Cancel
Save