2018-08-31 16:46:33 +00:00
|
|
|
import React from 'react';
|
2018-09-25 19:28:42 +00:00
|
|
|
import {
|
2020-06-05 13:28:58 +00:00
|
|
|
Text, View, TouchableOpacity, StyleSheet
|
2018-09-25 19:28:42 +00:00
|
|
|
} from 'react-native';
|
2018-08-31 16:46:33 +00:00
|
|
|
import PropTypes from 'prop-types';
|
|
|
|
|
2019-12-04 16:39:53 +00:00
|
|
|
import TextInput from '../../../presentation/TextInput';
|
2019-02-07 16:13:21 +00:00
|
|
|
import I18n from '../../../i18n';
|
2019-03-29 19:36:07 +00:00
|
|
|
import sharedStyles from '../../Styles';
|
2019-12-04 16:39:53 +00:00
|
|
|
import { themes } from '../../../constants/colors';
|
2020-06-05 13:28:58 +00:00
|
|
|
import { CustomIcon } from '../../../lib/Icons';
|
2020-07-06 20:56:28 +00:00
|
|
|
import { isTablet, isIOS } from '../../../utils/deviceInfo';
|
|
|
|
import { useOrientation } from '../../../dimensions';
|
2019-02-07 16:13:21 +00:00
|
|
|
|
2018-08-31 16:46:33 +00:00
|
|
|
const styles = StyleSheet.create({
|
|
|
|
container: {
|
|
|
|
flex: 1,
|
2020-07-06 20:56:28 +00:00
|
|
|
justifyContent: 'center',
|
|
|
|
marginLeft: isTablet ? 10 : 0
|
2018-08-31 16:46:33 +00:00
|
|
|
},
|
|
|
|
button: {
|
|
|
|
flexDirection: 'row',
|
2020-07-06 20:56:28 +00:00
|
|
|
alignItems: 'center'
|
2018-08-31 16:46:33 +00:00
|
|
|
},
|
2020-07-06 20:56:28 +00:00
|
|
|
title: {
|
|
|
|
...sharedStyles.textSemibold
|
2019-02-07 16:13:21 +00:00
|
|
|
},
|
2020-07-06 20:56:28 +00:00
|
|
|
subtitle: {
|
2019-03-29 19:36:07 +00:00
|
|
|
...sharedStyles.textRegular
|
2019-02-07 16:13:21 +00:00
|
|
|
},
|
2018-08-31 16:46:33 +00:00
|
|
|
upsideDown: {
|
|
|
|
transform: [{ scaleY: -1 }]
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2019-04-30 19:31:51 +00:00
|
|
|
const Header = React.memo(({
|
2020-07-06 20:56:28 +00:00
|
|
|
connecting, connected, isFetching, serverName, server, showServerDropdown, showSearchHeader, theme, onSearchChangeText, onPress
|
2018-10-23 21:39:48 +00:00
|
|
|
}) => {
|
2019-12-04 16:39:53 +00:00
|
|
|
const titleColorStyle = { color: themes[theme].headerTitleColor };
|
|
|
|
const isLight = theme === 'light';
|
2020-07-06 20:56:28 +00:00
|
|
|
const { isLandscape } = useOrientation();
|
|
|
|
const scale = isIOS && isLandscape && !isTablet ? 0.8 : 1;
|
|
|
|
const titleFontSize = 16 * scale;
|
2020-07-21 14:06:17 +00:00
|
|
|
const subTitleFontSize = 14 * scale;
|
2020-07-06 20:56:28 +00:00
|
|
|
|
2018-10-23 21:39:48 +00:00
|
|
|
if (showSearchHeader) {
|
|
|
|
return (
|
|
|
|
<View style={styles.container}>
|
|
|
|
<TextInput
|
2019-08-07 19:20:16 +00:00
|
|
|
autoFocus
|
2020-07-06 20:56:28 +00:00
|
|
|
style={[styles.title, isLight && titleColorStyle, { fontSize: titleFontSize }]}
|
2018-10-23 21:39:48 +00:00
|
|
|
placeholder='Search'
|
|
|
|
onChangeText={onSearchChangeText}
|
2019-12-04 16:39:53 +00:00
|
|
|
theme={theme}
|
2020-07-06 20:56:28 +00:00
|
|
|
testID='rooms-list-view-search-input'
|
2018-10-23 21:39:48 +00:00
|
|
|
/>
|
2018-08-31 16:46:33 +00:00
|
|
|
</View>
|
2018-10-23 21:39:48 +00:00
|
|
|
);
|
|
|
|
}
|
2020-07-06 20:56:28 +00:00
|
|
|
let subtitle;
|
|
|
|
if (connecting) {
|
|
|
|
subtitle = I18n.t('Connecting');
|
|
|
|
} else if (isFetching) {
|
|
|
|
subtitle = I18n.t('Updating');
|
|
|
|
} else if (!connected) {
|
|
|
|
subtitle = I18n.t('Waiting_for_network');
|
|
|
|
} else {
|
|
|
|
subtitle = server?.replace(/(^\w+:|^)\/\//, '');
|
|
|
|
}
|
2018-10-23 21:39:48 +00:00
|
|
|
return (
|
2019-03-12 16:23:06 +00:00
|
|
|
<View style={styles.container}>
|
2019-06-05 19:11:29 +00:00
|
|
|
<TouchableOpacity
|
|
|
|
onPress={onPress}
|
|
|
|
testID='rooms-list-header-server-dropdown-button'
|
|
|
|
>
|
2018-10-23 21:39:48 +00:00
|
|
|
<View style={styles.button}>
|
2020-07-06 20:56:28 +00:00
|
|
|
<Text style={[styles.title, isFetching && styles.serverSmall, titleColorStyle, { fontSize: titleFontSize }]} numberOfLines={1}>{serverName}</Text>
|
2020-06-05 13:28:58 +00:00
|
|
|
<CustomIcon
|
|
|
|
name='chevron-down'
|
|
|
|
color={themes[theme].headerTintColor}
|
2020-07-21 14:06:17 +00:00
|
|
|
style={[showServerDropdown && styles.upsideDown]}
|
2020-06-05 13:28:58 +00:00
|
|
|
size={18}
|
2019-12-04 16:39:53 +00:00
|
|
|
/>
|
2018-10-23 21:39:48 +00:00
|
|
|
</View>
|
2021-03-18 13:18:33 +00:00
|
|
|
{subtitle ? <Text testID='rooms-list-header-server-subtitle' style={[styles.subtitle, { color: themes[theme].auxiliaryText, fontSize: subTitleFontSize }]} numberOfLines={1}>{subtitle}</Text> : null}
|
2018-10-23 21:39:48 +00:00
|
|
|
</TouchableOpacity>
|
|
|
|
</View>
|
|
|
|
);
|
2019-04-30 19:31:51 +00:00
|
|
|
});
|
2018-08-31 16:46:33 +00:00
|
|
|
|
|
|
|
Header.propTypes = {
|
2018-10-23 21:39:48 +00:00
|
|
|
showServerDropdown: PropTypes.bool.isRequired,
|
|
|
|
showSearchHeader: PropTypes.bool.isRequired,
|
2018-08-31 16:46:33 +00:00
|
|
|
onPress: PropTypes.func.isRequired,
|
2018-10-23 21:39:48 +00:00
|
|
|
onSearchChangeText: PropTypes.func.isRequired,
|
2019-04-30 19:31:51 +00:00
|
|
|
connecting: PropTypes.bool,
|
2020-07-06 20:56:28 +00:00
|
|
|
connected: PropTypes.bool,
|
2019-02-07 16:13:21 +00:00
|
|
|
isFetching: PropTypes.bool,
|
2019-12-04 16:39:53 +00:00
|
|
|
serverName: PropTypes.string,
|
2020-07-06 20:56:28 +00:00
|
|
|
server: PropTypes.string,
|
2019-12-04 16:39:53 +00:00
|
|
|
theme: PropTypes.string
|
2018-08-31 16:46:33 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
Header.defaultProps = {
|
|
|
|
serverName: 'Rocket.Chat'
|
|
|
|
};
|
|
|
|
|
|
|
|
export default Header;
|