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';
|
|
|
|
|
|
|
|
import I18n from '../../../i18n';
|
2019-03-29 19:36:07 +00:00
|
|
|
import sharedStyles from '../../Styles';
|
|
|
|
import { COLOR_PRIMARY } from '../../../constants/colors';
|
2018-08-31 16:46:33 +00:00
|
|
|
|
|
|
|
const styles = StyleSheet.create({
|
|
|
|
container: {
|
|
|
|
flex: 1,
|
2018-09-11 16:32:52 +00:00
|
|
|
alignItems: 'center',
|
|
|
|
justifyContent: 'center'
|
2018-08-31 16:46:33 +00:00
|
|
|
},
|
|
|
|
button: {
|
|
|
|
flexDirection: 'row'
|
|
|
|
},
|
|
|
|
title: {
|
|
|
|
fontSize: 14,
|
2019-03-29 19:36:07 +00:00
|
|
|
...sharedStyles.textColorTitle,
|
|
|
|
...sharedStyles.textRegular
|
2018-08-31 16:46:33 +00:00
|
|
|
},
|
|
|
|
server: {
|
|
|
|
fontSize: 12,
|
2019-03-29 19:36:07 +00:00
|
|
|
color: COLOR_PRIMARY,
|
|
|
|
...sharedStyles.textRegular
|
2018-08-31 16:46:33 +00:00
|
|
|
},
|
|
|
|
disclosure: {
|
|
|
|
marginLeft: 3,
|
2018-09-19 14:18:32 +00:00
|
|
|
marginTop: 1,
|
2018-08-31 16:46:33 +00:00
|
|
|
width: 12,
|
|
|
|
height: 9
|
|
|
|
},
|
|
|
|
upsideDown: {
|
2018-09-19 14:18:32 +00:00
|
|
|
transform: [{ scaleY: -1 }],
|
|
|
|
marginTop: 4
|
2018-08-31 16:46:33 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2019-04-30 19:31:51 +00:00
|
|
|
const HeaderTitle = React.memo(({ connecting, isFetching }) => {
|
|
|
|
if (connecting) {
|
|
|
|
return <Text style={styles.title}>{I18n.t('Connecting')}</Text>;
|
|
|
|
}
|
2019-02-07 16:13:21 +00:00
|
|
|
if (isFetching) {
|
|
|
|
return <Text style={styles.title}>{I18n.t('Updating')}</Text>;
|
|
|
|
}
|
|
|
|
return <Text style={styles.title}>{I18n.t('Messages')}</Text>;
|
2019-04-30 19:31:51 +00:00
|
|
|
});
|
2019-02-07 16:13:21 +00:00
|
|
|
|
2019-04-30 19:31:51 +00:00
|
|
|
const Header = React.memo(({
|
|
|
|
connecting, isFetching, serverName, showServerDropdown, onPress
|
2019-02-07 16:13:21 +00:00
|
|
|
}) => (
|
2018-08-31 16:46:33 +00:00
|
|
|
<View style={styles.container}>
|
2018-09-05 18:15:03 +00:00
|
|
|
<TouchableOpacity
|
|
|
|
onPress={onPress}
|
|
|
|
testID='rooms-list-header-server-dropdown-button'
|
|
|
|
style={styles.container}
|
|
|
|
>
|
2019-04-30 19:31:51 +00:00
|
|
|
<HeaderTitle connecting={connecting} isFetching={isFetching} />
|
2018-08-31 16:46:33 +00:00
|
|
|
<View style={styles.button}>
|
|
|
|
<Text style={styles.server}>{serverName}</Text>
|
|
|
|
<Image style={[styles.disclosure, showServerDropdown && styles.upsideDown]} source={{ uri: 'disclosure_indicator_server' }} />
|
|
|
|
</View>
|
|
|
|
</TouchableOpacity>
|
|
|
|
</View>
|
2019-04-30 19:31:51 +00:00
|
|
|
));
|
2018-08-31 16:46:33 +00:00
|
|
|
|
|
|
|
Header.propTypes = {
|
2019-04-30 19:31:51 +00:00
|
|
|
connecting: PropTypes.bool,
|
2019-02-07 16:13:21 +00:00
|
|
|
isFetching: PropTypes.bool,
|
2018-08-31 16:46:33 +00:00
|
|
|
serverName: PropTypes.string,
|
2019-02-07 16:13:21 +00:00
|
|
|
showServerDropdown: PropTypes.bool.isRequired,
|
|
|
|
onPress: PropTypes.func.isRequired
|
2018-08-31 16:46:33 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
Header.defaultProps = {
|
|
|
|
serverName: 'Rocket.Chat'
|
|
|
|
};
|
|
|
|
|
2019-02-07 16:13:21 +00:00
|
|
|
HeaderTitle.propTypes = {
|
2019-04-30 19:31:51 +00:00
|
|
|
connecting: PropTypes.bool,
|
2019-02-07 16:13:21 +00:00
|
|
|
isFetching: PropTypes.bool
|
|
|
|
};
|
|
|
|
|
2018-08-31 16:46:33 +00:00
|
|
|
export default Header;
|