-
Notifications
You must be signed in to change notification settings - Fork 1.3k
/
channel_nav_bar.js
136 lines (119 loc) · 4.4 KB
/
channel_nav_bar.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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
import React, {PureComponent} from 'react';
import PropTypes from 'prop-types';
import {Dimensions, Platform, View} from 'react-native';
import AsyncStorage from '@react-native-community/async-storage';
import EventEmitter from 'mattermost-redux/utils/event_emitter';
import {DeviceTypes, ViewTypes} from 'app/constants';
import mattermostManaged from 'app/mattermost_managed';
import {makeStyleSheetFromTheme} from 'app/utils/theme';
import ChannelDrawerButton from './channel_drawer_button';
import ChannelSearchButton from './channel_search_button';
import ChannelTitle from './channel_title';
import SettingDrawerButton from './settings_drawer_button';
import {paddingHorizontal as padding} from 'app/components/safe_area_view/iphone_x_spacing';
const {
ANDROID_TOP_LANDSCAPE,
ANDROID_TOP_PORTRAIT,
IOS_TOP_LANDSCAPE,
IOS_TOP_PORTRAIT,
STATUS_BAR_HEIGHT,
} = ViewTypes;
export default class ChannelNavBar extends PureComponent {
static propTypes = {
isLandscape: PropTypes.bool.isRequired,
openChannelDrawer: PropTypes.func.isRequired,
openSettingsDrawer: PropTypes.func.isRequired,
onPress: PropTypes.func.isRequired,
theme: PropTypes.object.isRequired,
};
state = {
isSplitView: false,
};
componentDidMount() {
this.mounted = true;
this.handleDimensions();
this.handlePermanentSidebar();
Dimensions.addEventListener('change', this.handleDimensions);
EventEmitter.on(DeviceTypes.PERMANENT_SIDEBAR_SETTINGS, this.handlePermanentSidebar);
}
componentWillUnmount() {
this.mounted = false;
Dimensions.removeEventListener('change', this.handleDimensions);
EventEmitter.off(DeviceTypes.PERMANENT_SIDEBAR_SETTINGS, this.handlePermanentSidebar);
}
handleDimensions = () => {
if (DeviceTypes.IS_TABLET && this.mounted) {
mattermostManaged.isRunningInSplitView().then((result) => {
const isSplitView = Boolean(result.isSplitView);
this.setState({isSplitView});
});
}
};
handlePermanentSidebar = () => {
if (DeviceTypes.IS_TABLET && this.mounted) {
AsyncStorage.getItem(DeviceTypes.PERMANENT_SIDEBAR_SETTINGS).then((enabled) => {
this.setState({permanentSidebar: enabled === 'true'});
});
}
};
render() {
const {isLandscape, onPress, theme} = this.props;
const {openChannelDrawer, openSettingsDrawer} = this.props;
const style = getStyleFromTheme(theme);
let height;
let canHaveSubtitle = true;
switch (Platform.OS) {
case 'android':
height = ANDROID_TOP_PORTRAIT;
if (DeviceTypes.IS_TABLET) {
height = ANDROID_TOP_LANDSCAPE;
}
break;
case 'ios':
height = IOS_TOP_PORTRAIT - STATUS_BAR_HEIGHT;
if (DeviceTypes.IS_TABLET && isLandscape) {
height -= 1;
} else if (isLandscape) {
height = IOS_TOP_LANDSCAPE;
canHaveSubtitle = false;
}
if (DeviceTypes.IS_IPHONE_X && isLandscape) {
canHaveSubtitle = false;
}
break;
}
let drawerButtonVisible = false;
if (!DeviceTypes.IS_TABLET || this.state.isSplitView || !this.state.permanentSidebar) {
drawerButtonVisible = true;
}
return (
<View style={[style.header, padding(isLandscape), {height}]}>
<ChannelDrawerButton
openDrawer={openChannelDrawer}
visible={drawerButtonVisible}
/>
<ChannelTitle
onPress={onPress}
canHaveSubtitle={canHaveSubtitle}
/>
<ChannelSearchButton
theme={theme}
/>
<SettingDrawerButton openDrawer={openSettingsDrawer}/>
</View>
);
}
}
const getStyleFromTheme = makeStyleSheetFromTheme((theme) => {
return {
header: {
backgroundColor: theme.sidebarHeaderBg,
flexDirection: 'row',
justifyContent: 'flex-start',
width: '100%',
zIndex: 10,
},
};
});