2018-08-31 16:46:33 +00:00
|
|
|
import React from 'react';
|
2018-09-25 19:28:42 +00:00
|
|
|
import {
|
|
|
|
Text, View, TouchableOpacity, Image, StyleSheet
|
|
|
|
} from 'react-native';
|
2018-08-31 16:46:33 +00:00
|
|
|
import PropTypes from 'prop-types';
|
|
|
|
|
2019-12-11 23:01:12 +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-11 23:01:12 +00:00
|
|
|
import { themes } from '../../../constants/colors';
|
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',
|
|
|
|
alignItems: 'center'
|
|
|
|
},
|
|
|
|
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
|
|
|
disclosure: {
|
|
|
|
marginLeft: 9,
|
|
|
|
marginTop: 1,
|
|
|
|
width: 10,
|
|
|
|
height: 5
|
|
|
|
},
|
|
|
|
upsideDown: {
|
|
|
|
transform: [{ scaleY: -1 }]
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2019-04-30 19:31:51 +00:00
|
|
|
const Header = React.memo(({
|
2019-12-11 23:01:12 +00:00
|
|
|
connecting, isFetching, serverName, showServerDropdown, showSearchHeader, theme, onSearchChangeText, onPress
|
2018-10-23 21:39:48 +00:00
|
|
|
}) => {
|
2019-12-11 23:01:12 +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-20 19:24:22 +00:00
|
|
|
autoFocus
|
2019-12-11 23:01:12 +00:00
|
|
|
style={[styles.server, isLight && titleColorStyle]}
|
2018-10-23 21:39:48 +00:00
|
|
|
placeholder='Search'
|
|
|
|
onChangeText={onSearchChangeText}
|
2019-12-11 23:01:12 +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-11 23:01:12 +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}>
|
2019-12-11 23:01:12 +00:00
|
|
|
<Text style={[styles.server, isFetching && styles.serverSmall, titleColorStyle]}>{serverName}</Text>
|
|
|
|
<Image
|
|
|
|
style={[
|
|
|
|
styles.disclosure,
|
|
|
|
showServerDropdown && styles.upsideDown,
|
|
|
|
{ tintColor: themes[theme].headerTitleColor }
|
|
|
|
]}
|
|
|
|
source={{ uri: 'disclosure_indicator_server' }}
|
|
|
|
/>
|
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-11 23:01:12 +00:00
|
|
|
serverName: PropTypes.string,
|
|
|
|
theme: PropTypes.string
|
2018-08-31 16:46:33 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
Header.defaultProps = {
|
|
|
|
serverName: 'Rocket.Chat'
|
|
|
|
};
|
|
|
|
|
|
|
|
export default Header;
|