2018-08-31 16:46:33 +00:00
|
|
|
import React from 'react';
|
2021-10-01 18:12:19 +00:00
|
|
|
import { StyleSheet, Text, View } 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';
|
2021-10-01 18:12:19 +00:00
|
|
|
// import { CustomIcon } from '../../../lib/Icons';
|
|
|
|
import { isIOS, isTablet } from '../../../utils/deviceInfo';
|
2020-07-06 20:56:28 +00:00
|
|
|
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 }]
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2021-10-01 18:12:19 +00:00
|
|
|
const Header = React.memo(
|
|
|
|
({ connecting, connected, isFetching, serverName, server, showSearchHeader, theme, onSearchChangeText }) => {
|
|
|
|
const titleColorStyle = { color: themes[theme].headerTitleColor };
|
|
|
|
const isLight = theme === 'light';
|
|
|
|
const { isLandscape } = useOrientation();
|
|
|
|
const scale = isIOS && isLandscape && !isTablet ? 0.8 : 1;
|
|
|
|
const titleFontSize = 16 * scale;
|
|
|
|
const subTitleFontSize = 14 * scale;
|
2020-07-06 20:56:28 +00:00
|
|
|
|
2021-10-01 18:12:19 +00:00
|
|
|
if (showSearchHeader) {
|
|
|
|
return (
|
|
|
|
<View style={styles.container}>
|
|
|
|
<TextInput
|
|
|
|
autoFocus
|
|
|
|
style={[styles.title, isLight && titleColorStyle, { fontSize: titleFontSize }]}
|
|
|
|
placeholder='Search'
|
|
|
|
onChangeText={onSearchChangeText}
|
|
|
|
theme={theme}
|
|
|
|
testID='rooms-list-view-search-input'
|
|
|
|
/>
|
|
|
|
</View>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
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 (
|
|
|
|
<View style={styles.container}>
|
2021-10-01 18:12:19 +00:00
|
|
|
<View style={styles.button}>
|
|
|
|
<Text
|
|
|
|
style={[styles.title, isFetching && styles.serverSmall, titleColorStyle, { fontSize: titleFontSize }]}
|
|
|
|
numberOfLines={1}>
|
|
|
|
{serverName}
|
|
|
|
</Text>
|
|
|
|
</View>
|
|
|
|
{subtitle ? (
|
|
|
|
<Text
|
|
|
|
testID='rooms-list-header-server-subtitle'
|
|
|
|
style={[styles.subtitle, { color: themes[theme].auxiliaryText, fontSize: subTitleFontSize }]}
|
|
|
|
numberOfLines={1}>
|
|
|
|
{subtitle}
|
|
|
|
</Text>
|
|
|
|
) : null}
|
2018-08-31 16:46:33 +00:00
|
|
|
</View>
|
2018-10-23 21:39:48 +00:00
|
|
|
);
|
|
|
|
}
|
2021-10-01 18:12:19 +00:00
|
|
|
);
|
2018-08-31 16:46:33 +00:00
|
|
|
|
|
|
|
Header.propTypes = {
|
2018-10-23 21:39:48 +00:00
|
|
|
showSearchHeader: PropTypes.bool.isRequired,
|
|
|
|
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;
|