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';
|
2019-12-04 16:39:53 +00:00
|
|
|
import { themes } 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.textRegular
|
2018-08-31 16:46:33 +00:00
|
|
|
},
|
|
|
|
server: {
|
|
|
|
fontSize: 12,
|
2019-03-29 19:36:07 +00:00
|
|
|
...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-12-04 16:39:53 +00:00
|
|
|
const HeaderTitle = React.memo(({ connecting, isFetching, theme }) => {
|
2019-06-05 19:11:29 +00:00
|
|
|
let title = I18n.t('Messages');
|
2019-04-30 19:31:51 +00:00
|
|
|
if (connecting) {
|
2019-06-05 19:11:29 +00:00
|
|
|
title = I18n.t('Connecting');
|
2019-04-30 19:31:51 +00:00
|
|
|
}
|
2019-02-07 16:13:21 +00:00
|
|
|
if (isFetching) {
|
2019-06-05 19:11:29 +00:00
|
|
|
title = I18n.t('Updating');
|
2019-02-07 16:13:21 +00:00
|
|
|
}
|
2019-12-04 16:39:53 +00:00
|
|
|
return <Text style={[styles.title, { color: themes[theme].headerTitleColor }]}>{title}</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(({
|
2019-12-04 16:39:53 +00:00
|
|
|
connecting, isFetching, serverName, showServerDropdown, onPress, theme
|
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-06-05 19:11:29 +00:00
|
|
|
disabled={connecting || isFetching}
|
2018-09-05 18:15:03 +00:00
|
|
|
>
|
2019-12-04 16:39:53 +00:00
|
|
|
<HeaderTitle connecting={connecting} isFetching={isFetching} theme={theme} />
|
2018-08-31 16:46:33 +00:00
|
|
|
<View style={styles.button}>
|
2019-12-04 16:39:53 +00:00
|
|
|
<Text style={[styles.server, { color: themes[theme].headerTintColor }]}>{serverName}</Text>
|
2018-08-31 16:46:33 +00:00
|
|
|
<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-12-04 16:39:53 +00:00
|
|
|
theme: 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-12-04 16:39:53 +00:00
|
|
|
isFetching: PropTypes.bool,
|
|
|
|
theme: PropTypes.string
|
2019-02-07 16:13:21 +00:00
|
|
|
};
|
|
|
|
|
2018-08-31 16:46:33 +00:00
|
|
|
export default Header;
|