vn-verdnaturachat/app/views/RoomsListView/Header/Header.android.js

96 lines
2.4 KiB
JavaScript
Raw Normal View History

import React from 'react';
import {
Text, View, TouchableOpacity, StyleSheet
} from 'react-native';
import PropTypes from 'prop-types';
2019-12-04 16:39:53 +00:00
import TextInput from '../../../presentation/TextInput';
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';
import { CustomIcon } from '../../../lib/Icons';
const styles = StyleSheet.create({
container: {
flex: 1,
justifyContent: 'center'
},
button: {
flexDirection: 'row',
alignItems: 'center',
marginRight: 64
},
server: {
fontSize: 20,
2019-03-29 19:36:07 +00:00
...sharedStyles.textRegular
},
serverSmall: {
fontSize: 16
},
updating: {
fontSize: 14,
2019-03-29 19:36:07 +00:00
...sharedStyles.textRegular
},
upsideDown: {
transform: [{ scaleY: -1 }]
}
});
const Header = React.memo(({
2019-12-04 16:39:53 +00:00
connecting, isFetching, serverName, showServerDropdown, showSearchHeader, theme, onSearchChangeText, onPress
}) => {
2019-12-04 16:39:53 +00:00
const titleColorStyle = { color: themes[theme].headerTitleColor };
const isLight = theme === 'light';
if (showSearchHeader) {
return (
<View style={styles.container}>
<TextInput
autoFocus
2019-12-04 16:39:53 +00:00
style={[styles.server, isLight && titleColorStyle]}
placeholder='Search'
onChangeText={onSearchChangeText}
2019-12-04 16:39:53 +00:00
theme={theme}
/>
</View>
);
}
return (
2019-03-12 16:23:06 +00:00
<View style={styles.container}>
<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}
<View style={styles.button}>
<Text style={[styles.server, isFetching && styles.serverSmall, titleColorStyle]} numberOfLines={1}>{serverName}</Text>
<CustomIcon
name='chevron-down'
color={themes[theme].headerTintColor}
style={[showServerDropdown && styles.upsideDown]}
size={18}
2019-12-04 16:39:53 +00:00
/>
</View>
</TouchableOpacity>
</View>
);
});
Header.propTypes = {
showServerDropdown: PropTypes.bool.isRequired,
showSearchHeader: PropTypes.bool.isRequired,
onPress: PropTypes.func.isRequired,
onSearchChangeText: PropTypes.func.isRequired,
connecting: PropTypes.bool,
isFetching: PropTypes.bool,
2019-12-04 16:39:53 +00:00
serverName: PropTypes.string,
theme: PropTypes.string
};
Header.defaultProps = {
serverName: 'Rocket.Chat'
};
export default Header;