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';
|
2019-02-07 16:13:21 +00:00
|
|
|
|
2018-08-31 16:46:33 +00:00
|
|
|
const styles = StyleSheet.create({
|
|
|
|
container: {
|
|
|
|
flex: 1,
|
|
|
|
justifyContent: 'center'
|
|
|
|
},
|
|
|
|
button: {
|
|
|
|
flexDirection: 'row',
|
2020-05-08 17:09:36 +00:00
|
|
|
alignItems: 'center',
|
|
|
|
marginRight: 64
|
2018-08-31 16:46:33 +00:00
|
|
|
},
|
|
|
|
server: {
|
|
|
|
fontSize: 20,
|
2019-03-29 19:36:07 +00:00
|
|
|
...sharedStyles.textRegular
|
2018-08-31 16:46:33 +00:00
|
|
|
},
|
2019-02-07 16:13:21 +00:00
|
|
|
serverSmall: {
|
|
|
|
fontSize: 16
|
|
|
|
},
|
|
|
|
updating: {
|
|
|
|
fontSize: 14,
|
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(({
|
2019-12-04 16:39:53 +00:00
|
|
|
connecting, isFetching, serverName, 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';
|
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
|
2019-12-04 16:39:53 +00:00
|
|
|
style={[styles.server, isLight && titleColorStyle]}
|
2018-10-23 21:39:48 +00:00
|
|
|
placeholder='Search'
|
|
|
|
onChangeText={onSearchChangeText}
|
2019-12-04 16:39:53 +00:00
|
|
|
theme={theme}
|
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
|
|
|
);
|
|
|
|
}
|
|
|
|
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'
|
|
|
|
disabled={connecting || isFetching}
|
|
|
|
>
|
2019-12-04 16:39:53 +00:00
|
|
|
{connecting ? <Text style={[styles.updating, titleColorStyle]}>{I18n.t('Connecting')}</Text> : null}
|
|
|
|
{isFetching ? <Text style={[styles.updating, titleColorStyle]}>{I18n.t('Updating')}</Text> : null}
|
2018-10-23 21:39:48 +00:00
|
|
|
<View style={styles.button}>
|
2020-05-08 17:09:36 +00:00
|
|
|
<Text style={[styles.server, isFetching && styles.serverSmall, titleColorStyle]} numberOfLines={1}>{serverName}</Text>
|
2020-06-05 13:28:58 +00:00
|
|
|
<CustomIcon
|
|
|
|
name='chevron-down'
|
|
|
|
color={themes[theme].headerTintColor}
|
|
|
|
style={[showServerDropdown && styles.upsideDown]}
|
|
|
|
size={18}
|
2019-12-04 16:39:53 +00:00
|
|
|
/>
|
2018-10-23 21:39:48 +00:00
|
|
|
</View>
|
|
|
|
</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,
|
2019-02-07 16:13:21 +00:00
|
|
|
isFetching: PropTypes.bool,
|
2019-12-04 16:39:53 +00:00
|
|
|
serverName: PropTypes.string,
|
|
|
|
theme: PropTypes.string
|
2018-08-31 16:46:33 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
Header.defaultProps = {
|
|
|
|
serverName: 'Rocket.Chat'
|
|
|
|
};
|
|
|
|
|
|
|
|
export default Header;
|