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';
|
2018-10-23 21:39:48 +00:00
|
|
|
import { TextInput } from 'react-native-gesture-handler';
|
2018-08-31 16:46:33 +00:00
|
|
|
|
2019-02-07 16:13:21 +00:00
|
|
|
import I18n from '../../../i18n';
|
2019-03-29 19:36:07 +00:00
|
|
|
import sharedStyles from '../../Styles';
|
|
|
|
import { COLOR_WHITE } 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
|
|
|
color: COLOR_WHITE,
|
|
|
|
...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
|
|
|
color: COLOR_WHITE,
|
|
|
|
...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 }]
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2018-10-23 21:39:48 +00:00
|
|
|
const Header = ({
|
2019-03-12 16:23:06 +00:00
|
|
|
isFetching, serverName, showServerDropdown, setSearchInputRef, showSearchHeader, onSearchChangeText, onPress
|
2018-10-23 21:39:48 +00:00
|
|
|
}) => {
|
|
|
|
if (showSearchHeader) {
|
|
|
|
return (
|
|
|
|
<View style={styles.container}>
|
|
|
|
<TextInput
|
|
|
|
ref={setSearchInputRef}
|
|
|
|
style={styles.server}
|
|
|
|
placeholder='Search'
|
|
|
|
placeholderTextColor='rgba(255, 255, 255, 0.5)'
|
|
|
|
onChangeText={onSearchChangeText}
|
|
|
|
/>
|
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}>
|
2018-10-23 21:39:48 +00:00
|
|
|
<TouchableOpacity onPress={onPress} testID='rooms-list-header-server-dropdown-button'>
|
2019-02-07 16:13:21 +00:00
|
|
|
{isFetching ? <Text style={styles.updating}>{I18n.t('Updating')}</Text> : null}
|
2018-10-23 21:39:48 +00:00
|
|
|
<View style={styles.button}>
|
2019-02-07 16:13:21 +00:00
|
|
|
<Text style={[styles.server, isFetching && styles.serverSmall]}>{serverName}</Text>
|
2018-10-23 21:39:48 +00:00
|
|
|
<Image style={[styles.disclosure, showServerDropdown && styles.upsideDown]} source={{ uri: 'disclosure_indicator_server' }} />
|
|
|
|
</View>
|
|
|
|
</TouchableOpacity>
|
|
|
|
</View>
|
|
|
|
);
|
|
|
|
};
|
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,
|
|
|
|
setSearchInputRef: PropTypes.func.isRequired,
|
2019-02-07 16:13:21 +00:00
|
|
|
isFetching: PropTypes.bool,
|
2019-03-12 16:23:06 +00:00
|
|
|
serverName: PropTypes.string
|
2018-08-31 16:46:33 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
Header.defaultProps = {
|
|
|
|
serverName: 'Rocket.Chat'
|
|
|
|
};
|
|
|
|
|
|
|
|
export default Header;
|