2018-08-31 16:46:33 +00:00
|
|
|
import React from 'react';
|
2022-02-25 18:59:39 +00:00
|
|
|
import { StyleSheet, Text, TextInputProps, TouchableOpacity, TouchableOpacityProps, View } from 'react-native';
|
2018-08-31 16:46:33 +00:00
|
|
|
|
2022-05-18 19:17:42 +00:00
|
|
|
import TextInput from '../../../containers/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';
|
2022-04-07 14:10:03 +00:00
|
|
|
import { themes } from '../../../lib/constants';
|
2022-05-02 19:21:15 +00:00
|
|
|
import { CustomIcon } from '../../../containers/CustomIcon';
|
2021-09-13 20:41:05 +00:00
|
|
|
import { isIOS, isTablet } from '../../../utils/deviceInfo';
|
2020-07-06 20:56:28 +00:00
|
|
|
import { useOrientation } from '../../../dimensions';
|
2022-03-17 19:25:31 +00:00
|
|
|
import { useTheme } from '../../../theme';
|
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 }]
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2022-02-25 18:59:39 +00:00
|
|
|
interface IRoomHeader {
|
|
|
|
connecting: boolean;
|
|
|
|
connected: boolean;
|
|
|
|
isFetching: boolean;
|
|
|
|
serverName: string;
|
|
|
|
server: string;
|
|
|
|
showServerDropdown: boolean;
|
|
|
|
showSearchHeader: boolean;
|
|
|
|
onSearchChangeText: TextInputProps['onChangeText'];
|
|
|
|
onPress: TouchableOpacityProps['onPress'];
|
|
|
|
}
|
|
|
|
|
2021-09-13 20:41:05 +00:00
|
|
|
const Header = React.memo(
|
|
|
|
({
|
|
|
|
connecting,
|
|
|
|
connected,
|
|
|
|
isFetching,
|
2022-02-25 18:59:39 +00:00
|
|
|
serverName = 'Rocket.Chat',
|
2021-09-13 20:41:05 +00:00
|
|
|
server,
|
|
|
|
showServerDropdown,
|
|
|
|
showSearchHeader,
|
|
|
|
onSearchChangeText,
|
|
|
|
onPress
|
2022-02-25 18:59:39 +00:00
|
|
|
}: IRoomHeader) => {
|
2022-03-17 19:25:31 +00:00
|
|
|
const { theme } = useTheme();
|
2021-09-13 20:41:05 +00:00
|
|
|
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-09-13 20:41:05 +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-09-13 20:41:05 +00:00
|
|
|
<TouchableOpacity onPress={onPress} testID='rooms-list-header-server-dropdown-button'>
|
|
|
|
<View style={styles.button}>
|
2022-02-25 18:59:39 +00:00
|
|
|
<Text style={[styles.title, titleColorStyle, { fontSize: titleFontSize }]} numberOfLines={1}>
|
2021-09-13 20:41:05 +00:00
|
|
|
{serverName}
|
|
|
|
</Text>
|
|
|
|
<CustomIcon
|
|
|
|
name='chevron-down'
|
|
|
|
color={themes[theme].headerTintColor}
|
|
|
|
style={[showServerDropdown && styles.upsideDown]}
|
|
|
|
size={18}
|
|
|
|
/>
|
|
|
|
</View>
|
|
|
|
{subtitle ? (
|
|
|
|
<Text
|
|
|
|
testID='rooms-list-header-server-subtitle'
|
|
|
|
style={[styles.subtitle, { color: themes[theme].auxiliaryText, fontSize: subTitleFontSize }]}
|
|
|
|
numberOfLines={1}>
|
|
|
|
{subtitle}
|
|
|
|
</Text>
|
|
|
|
) : null}
|
|
|
|
</TouchableOpacity>
|
2018-08-31 16:46:33 +00:00
|
|
|
</View>
|
2018-10-23 21:39:48 +00:00
|
|
|
);
|
|
|
|
}
|
2021-09-13 20:41:05 +00:00
|
|
|
);
|
2018-08-31 16:46:33 +00:00
|
|
|
|
|
|
|
export default Header;
|