verdnatura-chat/app/views/RoomsListView/Header/Header.js

109 lines
3.0 KiB
JavaScript
Raw Permalink 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';
import { isTablet, isIOS } from '../../../utils/deviceInfo';
import { useOrientation } from '../../../dimensions';
const styles = StyleSheet.create({
container: {
flex: 1,
justifyContent: 'center',
marginLeft: isTablet ? 10 : 0
},
button: {
flexDirection: 'row',
alignItems: 'center'
},
title: {
...sharedStyles.textSemibold
},
subtitle: {
2019-03-29 19:36:07 +00:00
...sharedStyles.textRegular
},
upsideDown: {
transform: [{ scaleY: -1 }]
}
});
const Header = React.memo(({
connecting, connected, isFetching, serverName, server, showServerDropdown, showSearchHeader, theme, onSearchChangeText, onPress
}) => {
2019-12-04 16:39:53 +00:00
const titleColorStyle = { color: themes[theme].headerTitleColor };
const isLight = theme === 'light';
const { isLandscape } = useOrientation();
const scale = isIOS && isLandscape && !isTablet ? 0.8 : 1;
const titleFontSize = 16 * scale;
const subTitleFontSize = 14 * scale;
if (showSearchHeader) {
return (
<View style={styles.container}>
<TextInput
autoFocus
style={[styles.title, isLight && titleColorStyle, { fontSize: titleFontSize }]}
placeholder='Search'
onChangeText={onSearchChangeText}
2019-12-04 16:39:53 +00:00
theme={theme}
testID='rooms-list-view-search-input'
/>
</View>
);
}
let subtitle;
if (connecting) {
subtitle = I18n.t('Connecting');
} else if (isFetching) {
subtitle = I18n.t('Updating');
} else if (!connected) {
subtitle = I18n.t('Waiting_for_network');
} else {
subtitle = server?.replace(/(^\w+:|^)\/\//, '');
}
return (
2019-03-12 16:23:06 +00:00
<View style={styles.container}>
<TouchableOpacity
onPress={onPress}
testID='rooms-list-header-server-dropdown-button'
>
<View style={styles.button}>
<Text style={[styles.title, isFetching && styles.serverSmall, titleColorStyle, { fontSize: titleFontSize }]} 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>
{subtitle ? <Text style={[styles.subtitle, { color: themes[theme].auxiliaryText, fontSize: subTitleFontSize }]} numberOfLines={1}>{subtitle}</Text> : null}
</TouchableOpacity>
</View>
);
});
Header.propTypes = {
showServerDropdown: PropTypes.bool.isRequired,
showSearchHeader: PropTypes.bool.isRequired,
onPress: PropTypes.func.isRequired,
onSearchChangeText: PropTypes.func.isRequired,
connecting: PropTypes.bool,
connected: PropTypes.bool,
isFetching: PropTypes.bool,
2019-12-04 16:39:53 +00:00
serverName: PropTypes.string,
server: PropTypes.string,
2019-12-04 16:39:53 +00:00
theme: PropTypes.string
};
Header.defaultProps = {
serverName: 'Rocket.Chat'
};
export default Header;