2019-04-08 12:35:28 +00:00
|
|
|
import React from 'react';
|
|
|
|
import PropTypes from 'prop-types';
|
|
|
|
import {
|
2019-11-25 20:01:17 +00:00
|
|
|
View, Text, StyleSheet, ScrollView, TouchableOpacity
|
2019-04-08 12:35:28 +00:00
|
|
|
} from 'react-native';
|
|
|
|
|
|
|
|
import I18n from '../../../i18n';
|
|
|
|
import sharedStyles from '../../Styles';
|
2019-12-04 16:39:53 +00:00
|
|
|
import { isAndroid, isTablet } from '../../../utils/deviceInfo';
|
2019-04-08 12:35:28 +00:00
|
|
|
import Icon from './Icon';
|
2019-12-04 16:39:53 +00:00
|
|
|
import { themes } from '../../../constants/colors';
|
2020-03-03 20:40:20 +00:00
|
|
|
import Markdown from '../../../containers/markdown';
|
2019-04-08 12:35:28 +00:00
|
|
|
|
2019-11-25 20:01:17 +00:00
|
|
|
const androidMarginLeft = isTablet ? 0 : 10;
|
|
|
|
|
2019-04-08 12:35:28 +00:00
|
|
|
const TITLE_SIZE = 16;
|
|
|
|
const styles = StyleSheet.create({
|
|
|
|
container: {
|
2019-08-22 19:15:30 +00:00
|
|
|
flex: 1,
|
|
|
|
height: '100%',
|
|
|
|
marginRight: isAndroid ? 15 : 5,
|
2019-11-25 20:01:17 +00:00
|
|
|
marginLeft: isAndroid ? androidMarginLeft : -12
|
2019-04-08 12:35:28 +00:00
|
|
|
},
|
|
|
|
titleContainer: {
|
|
|
|
flex: 6,
|
|
|
|
flexDirection: 'row'
|
|
|
|
},
|
2019-04-17 17:01:03 +00:00
|
|
|
threadContainer: {
|
|
|
|
marginRight: isAndroid ? 20 : undefined
|
|
|
|
},
|
2019-04-08 12:35:28 +00:00
|
|
|
title: {
|
|
|
|
...sharedStyles.textSemibold,
|
|
|
|
fontSize: TITLE_SIZE
|
|
|
|
},
|
|
|
|
scroll: {
|
|
|
|
alignItems: 'center'
|
|
|
|
},
|
|
|
|
typing: {
|
|
|
|
...sharedStyles.textRegular,
|
|
|
|
fontSize: 12,
|
|
|
|
flex: 4
|
|
|
|
},
|
|
|
|
typingUsers: {
|
|
|
|
...sharedStyles.textSemibold
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2019-12-04 16:39:53 +00:00
|
|
|
const Typing = React.memo(({ usersTyping, theme }) => {
|
2019-04-08 12:35:28 +00:00
|
|
|
let usersText;
|
2019-09-16 20:26:32 +00:00
|
|
|
if (!usersTyping.length) {
|
2019-04-08 12:35:28 +00:00
|
|
|
return null;
|
2019-09-16 20:26:32 +00:00
|
|
|
} else if (usersTyping.length === 2) {
|
|
|
|
usersText = usersTyping.join(` ${ I18n.t('and') } `);
|
2019-04-08 12:35:28 +00:00
|
|
|
} else {
|
2019-09-16 20:26:32 +00:00
|
|
|
usersText = usersTyping.join(', ');
|
2019-04-08 12:35:28 +00:00
|
|
|
}
|
|
|
|
return (
|
2019-12-04 16:39:53 +00:00
|
|
|
<Text style={[styles.typing, { color: themes[theme].headerTitleColor }]} numberOfLines={1}>
|
2019-04-08 12:35:28 +00:00
|
|
|
<Text style={styles.typingUsers}>{usersText} </Text>
|
2019-09-16 20:26:32 +00:00
|
|
|
{ usersTyping.length > 1 ? I18n.t('are_typing') : I18n.t('is_typing') }...
|
2019-04-08 12:35:28 +00:00
|
|
|
</Text>
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
|
|
|
Typing.propTypes = {
|
2019-12-04 16:39:53 +00:00
|
|
|
usersTyping: PropTypes.array,
|
|
|
|
theme: PropTypes.string
|
2019-04-08 12:35:28 +00:00
|
|
|
};
|
|
|
|
|
2019-04-30 19:31:51 +00:00
|
|
|
const HeaderTitle = React.memo(({
|
2019-12-04 16:39:53 +00:00
|
|
|
title, scale, connecting, theme
|
2019-04-30 19:31:51 +00:00
|
|
|
}) => {
|
|
|
|
if (connecting) {
|
|
|
|
title = I18n.t('Connecting');
|
|
|
|
}
|
|
|
|
return (
|
2020-03-03 20:40:20 +00:00
|
|
|
<Markdown
|
|
|
|
preview
|
|
|
|
msg={title}
|
2019-12-04 16:39:53 +00:00
|
|
|
style={[styles.title, { fontSize: TITLE_SIZE * scale, color: themes[theme].headerTitleColor }]}
|
2019-04-30 19:31:51 +00:00
|
|
|
numberOfLines={1}
|
|
|
|
testID={`room-view-title-${ title }`}
|
2020-03-03 20:40:20 +00:00
|
|
|
theme={theme}
|
|
|
|
/>
|
2019-04-30 19:31:51 +00:00
|
|
|
);
|
|
|
|
});
|
|
|
|
|
|
|
|
HeaderTitle.propTypes = {
|
|
|
|
title: PropTypes.string,
|
|
|
|
scale: PropTypes.number,
|
2019-12-04 16:39:53 +00:00
|
|
|
connecting: PropTypes.bool,
|
|
|
|
theme: PropTypes.string
|
2019-04-30 19:31:51 +00:00
|
|
|
};
|
|
|
|
|
2019-04-08 12:35:28 +00:00
|
|
|
const Header = React.memo(({
|
2019-12-04 16:39:53 +00:00
|
|
|
title, type, status, usersTyping, width, height, prid, tmid, widthOffset, connecting, goRoomActionsView, theme
|
2019-04-08 12:35:28 +00:00
|
|
|
}) => {
|
|
|
|
const portrait = height > width;
|
|
|
|
let scale = 1;
|
|
|
|
|
2019-11-25 20:01:17 +00:00
|
|
|
if (!portrait && !tmid) {
|
2019-04-08 12:35:28 +00:00
|
|
|
if (usersTyping.length > 0) {
|
|
|
|
scale = 0.8;
|
|
|
|
}
|
|
|
|
}
|
2019-04-17 17:01:03 +00:00
|
|
|
|
2019-11-25 20:01:17 +00:00
|
|
|
const onPress = () => {
|
|
|
|
if (!tmid) {
|
|
|
|
goRoomActionsView();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2019-04-08 12:35:28 +00:00
|
|
|
return (
|
2020-03-03 20:27:38 +00:00
|
|
|
<TouchableOpacity
|
|
|
|
testID='room-view-header-actions'
|
|
|
|
onPress={onPress}
|
|
|
|
style={[styles.container, { width: width - widthOffset }]}
|
|
|
|
>
|
2019-04-17 17:01:03 +00:00
|
|
|
<View style={[styles.titleContainer, tmid && styles.threadContainer]}>
|
2019-04-08 12:35:28 +00:00
|
|
|
<ScrollView
|
|
|
|
showsHorizontalScrollIndicator={false}
|
|
|
|
horizontal
|
|
|
|
bounces={false}
|
|
|
|
contentContainerStyle={styles.scroll}
|
|
|
|
>
|
2019-12-04 16:39:53 +00:00
|
|
|
<Icon type={prid ? 'discussion' : type} status={status} theme={theme} />
|
2019-04-30 19:31:51 +00:00
|
|
|
<HeaderTitle
|
|
|
|
title={title}
|
|
|
|
scale={scale}
|
|
|
|
connecting={connecting}
|
2019-12-04 16:39:53 +00:00
|
|
|
theme={theme}
|
2019-04-30 19:31:51 +00:00
|
|
|
/>
|
2019-04-08 12:35:28 +00:00
|
|
|
</ScrollView>
|
|
|
|
</View>
|
2019-12-04 16:39:53 +00:00
|
|
|
{type === 'thread' ? null : <Typing usersTyping={usersTyping} theme={theme} />}
|
2019-11-25 20:01:17 +00:00
|
|
|
</TouchableOpacity>
|
2019-04-08 12:35:28 +00:00
|
|
|
);
|
|
|
|
});
|
|
|
|
|
|
|
|
Header.propTypes = {
|
|
|
|
title: PropTypes.string.isRequired,
|
|
|
|
type: PropTypes.string.isRequired,
|
|
|
|
width: PropTypes.number.isRequired,
|
|
|
|
height: PropTypes.number.isRequired,
|
|
|
|
prid: PropTypes.string,
|
2019-04-17 17:01:03 +00:00
|
|
|
tmid: PropTypes.string,
|
2019-04-08 12:35:28 +00:00
|
|
|
status: PropTypes.string,
|
2019-12-04 16:39:53 +00:00
|
|
|
theme: PropTypes.string,
|
2019-04-17 17:01:03 +00:00
|
|
|
usersTyping: PropTypes.array,
|
2019-04-30 19:31:51 +00:00
|
|
|
widthOffset: PropTypes.number,
|
2019-11-25 20:01:17 +00:00
|
|
|
connecting: PropTypes.bool,
|
|
|
|
goRoomActionsView: PropTypes.func
|
2019-04-08 12:35:28 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
Header.defaultProps = {
|
|
|
|
usersTyping: []
|
|
|
|
};
|
|
|
|
|
|
|
|
export default Header;
|