2019-04-08 12:35:28 +00:00
|
|
|
import React from 'react';
|
|
|
|
import PropTypes from 'prop-types';
|
|
|
|
import {
|
2020-03-30 20:19:01 +00:00
|
|
|
View, Text, StyleSheet, TouchableOpacity
|
2019-04-08 12:35:28 +00:00
|
|
|
} from 'react-native';
|
|
|
|
|
2021-04-07 18:31:25 +00:00
|
|
|
import I18n from '../../i18n';
|
|
|
|
import sharedStyles from '../../views/Styles';
|
|
|
|
import { themes } from '../../constants/colors';
|
|
|
|
import Markdown from '../markdown';
|
|
|
|
import RoomTypeIcon from '../RoomTypeIcon';
|
|
|
|
import { withTheme } from '../../theme';
|
2019-04-08 12:35:28 +00:00
|
|
|
|
2020-11-12 14:22:53 +00:00
|
|
|
const HIT_SLOP = {
|
|
|
|
top: 5, right: 5, bottom: 5, left: 5
|
|
|
|
};
|
2019-04-08 12:35:28 +00:00
|
|
|
const TITLE_SIZE = 16;
|
2021-04-07 18:31:25 +00:00
|
|
|
const SUBTITLE_SIZE = 12;
|
|
|
|
|
|
|
|
const getSubTitleSize = scale => SUBTITLE_SIZE * scale;
|
|
|
|
|
2019-04-08 12:35:28 +00:00
|
|
|
const styles = StyleSheet.create({
|
|
|
|
container: {
|
2019-08-22 19:15:30 +00:00
|
|
|
flex: 1,
|
2020-06-15 14:00:46 +00:00
|
|
|
justifyContent: 'center'
|
2019-04-08 12:35:28 +00:00
|
|
|
},
|
|
|
|
titleContainer: {
|
2020-03-30 20:19:01 +00:00
|
|
|
alignItems: 'center',
|
2019-04-08 12:35:28 +00:00
|
|
|
flexDirection: 'row'
|
|
|
|
},
|
|
|
|
title: {
|
2021-04-07 18:31:25 +00:00
|
|
|
flexShrink: 1,
|
|
|
|
...sharedStyles.textSemibold
|
2019-04-08 12:35:28 +00:00
|
|
|
},
|
2020-03-30 20:19:01 +00:00
|
|
|
subtitle: {
|
2021-04-07 18:31:25 +00:00
|
|
|
flexShrink: 1,
|
|
|
|
...sharedStyles.textRegular
|
2019-04-08 12:35:28 +00:00
|
|
|
},
|
|
|
|
typingUsers: {
|
|
|
|
...sharedStyles.textSemibold
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2020-10-30 17:35:07 +00:00
|
|
|
const SubTitle = React.memo(({
|
2021-04-07 18:31:25 +00:00
|
|
|
usersTyping, subtitle, renderFunc, theme, scale
|
2020-10-30 17:35:07 +00:00
|
|
|
}) => {
|
2021-04-07 18:31:25 +00:00
|
|
|
const fontSize = getSubTitleSize(scale);
|
2020-03-30 20:19:01 +00:00
|
|
|
// typing
|
|
|
|
if (usersTyping.length) {
|
|
|
|
let usersText;
|
|
|
|
if (usersTyping.length === 2) {
|
|
|
|
usersText = usersTyping.join(` ${ I18n.t('and') } `);
|
|
|
|
} else {
|
|
|
|
usersText = usersTyping.join(', ');
|
|
|
|
}
|
|
|
|
return (
|
2021-04-07 18:31:25 +00:00
|
|
|
<Text style={[styles.subtitle, { fontSize, color: themes[theme].auxiliaryText }]} numberOfLines={1}>
|
2020-03-30 20:19:01 +00:00
|
|
|
<Text style={styles.typingUsers}>{usersText} </Text>
|
|
|
|
{ usersTyping.length > 1 ? I18n.t('are_typing') : I18n.t('is_typing') }...
|
|
|
|
</Text>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2020-10-30 17:35:07 +00:00
|
|
|
// renderFunc
|
|
|
|
if (renderFunc) {
|
|
|
|
return renderFunc();
|
|
|
|
}
|
|
|
|
|
2020-03-30 20:19:01 +00:00
|
|
|
// subtitle
|
|
|
|
if (subtitle) {
|
|
|
|
return (
|
|
|
|
<Markdown
|
|
|
|
preview
|
|
|
|
msg={subtitle}
|
2021-04-07 18:31:25 +00:00
|
|
|
style={[styles.subtitle, { fontSize, color: themes[theme].auxiliaryText }]}
|
2020-03-30 20:19:01 +00:00
|
|
|
numberOfLines={1}
|
|
|
|
theme={theme}
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
}
|
2020-10-30 17:35:07 +00:00
|
|
|
|
|
|
|
return null;
|
2019-04-08 12:35:28 +00:00
|
|
|
});
|
|
|
|
|
2020-03-30 20:19:01 +00:00
|
|
|
SubTitle.propTypes = {
|
2019-12-04 16:39:53 +00:00
|
|
|
usersTyping: PropTypes.array,
|
2020-03-30 20:19:01 +00:00
|
|
|
theme: PropTypes.string,
|
2020-10-30 17:35:07 +00:00
|
|
|
subtitle: PropTypes.string,
|
2021-04-07 18:31:25 +00:00
|
|
|
renderFunc: PropTypes.func,
|
|
|
|
scale: PropTypes.number
|
2019-04-08 12:35:28 +00:00
|
|
|
};
|
|
|
|
|
2019-04-30 19:31:51 +00:00
|
|
|
const HeaderTitle = React.memo(({
|
2021-04-07 18:31:25 +00:00
|
|
|
title, tmid, prid, scale, theme, testID
|
2019-04-30 19:31:51 +00:00
|
|
|
}) => {
|
2021-04-07 18:31:25 +00:00
|
|
|
const titleStyle = { fontSize: TITLE_SIZE * scale, color: themes[theme].headerTitleColor };
|
2020-03-05 14:35:05 +00:00
|
|
|
if (!tmid && !prid) {
|
|
|
|
return (
|
|
|
|
<Text
|
2021-04-07 18:31:25 +00:00
|
|
|
style={[styles.title, titleStyle]}
|
2020-03-05 14:35:05 +00:00
|
|
|
numberOfLines={1}
|
2021-04-07 18:31:25 +00:00
|
|
|
testID={testID}
|
2020-03-05 14:35:05 +00:00
|
|
|
>
|
|
|
|
{title}
|
|
|
|
</Text>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2019-04-30 19:31:51 +00:00
|
|
|
return (
|
2020-03-03 20:40:20 +00:00
|
|
|
<Markdown
|
|
|
|
preview
|
|
|
|
msg={title}
|
2021-04-07 18:31:25 +00:00
|
|
|
style={[styles.title, titleStyle]}
|
2019-04-30 19:31:51 +00:00
|
|
|
numberOfLines={1}
|
2020-03-03 20:40:20 +00:00
|
|
|
theme={theme}
|
2021-04-07 18:31:25 +00:00
|
|
|
testID={testID}
|
2020-03-03 20:40:20 +00:00
|
|
|
/>
|
2019-04-30 19:31:51 +00:00
|
|
|
);
|
|
|
|
});
|
|
|
|
|
|
|
|
HeaderTitle.propTypes = {
|
|
|
|
title: PropTypes.string,
|
2020-03-05 14:35:05 +00:00
|
|
|
tmid: PropTypes.string,
|
|
|
|
prid: PropTypes.string,
|
2019-04-30 19:31:51 +00:00
|
|
|
scale: PropTypes.number,
|
2021-04-07 18:31:25 +00:00
|
|
|
theme: PropTypes.string,
|
|
|
|
testID: PropTypes.string
|
2019-04-30 19:31:51 +00:00
|
|
|
};
|
|
|
|
|
2019-04-08 12:35:28 +00:00
|
|
|
const Header = React.memo(({
|
2021-04-07 18:31:25 +00:00
|
|
|
title, subtitle, parentTitle, type, status, usersTyping, width, height, prid, tmid, onPress, theme, isGroupChat, teamMain, testID
|
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) {
|
2020-03-30 20:19:01 +00:00
|
|
|
if (usersTyping.length > 0 || subtitle) {
|
2019-04-08 12:35:28 +00:00
|
|
|
scale = 0.8;
|
|
|
|
}
|
|
|
|
}
|
2019-04-17 17:01:03 +00:00
|
|
|
|
2020-10-30 17:35:07 +00:00
|
|
|
let renderFunc;
|
|
|
|
if (tmid) {
|
|
|
|
renderFunc = () => (
|
|
|
|
<View style={styles.titleContainer}>
|
2021-04-07 18:31:25 +00:00
|
|
|
<RoomTypeIcon type={prid ? 'discussion' : type} isGroupChat={isGroupChat} status={status} teamMain={teamMain} />
|
2020-11-12 14:17:32 +00:00
|
|
|
<Text style={[styles.subtitle, { color: themes[theme].auxiliaryText }]} numberOfLines={1}>{parentTitle}</Text>
|
2020-10-30 17:35:07 +00:00
|
|
|
</View>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2019-04-08 12:35:28 +00:00
|
|
|
return (
|
2020-03-03 20:27:38 +00:00
|
|
|
<TouchableOpacity
|
2021-04-07 18:31:25 +00:00
|
|
|
testID='room-header'
|
2020-08-26 19:28:16 +00:00
|
|
|
accessibilityLabel={title}
|
2020-03-03 20:27:38 +00:00
|
|
|
onPress={onPress}
|
2020-06-15 14:00:46 +00:00
|
|
|
style={styles.container}
|
2020-03-30 20:19:01 +00:00
|
|
|
disabled={tmid}
|
2020-11-12 14:22:53 +00:00
|
|
|
hitSlop={HIT_SLOP}
|
2020-03-03 20:27:38 +00:00
|
|
|
>
|
2020-07-06 20:56:28 +00:00
|
|
|
<View style={styles.titleContainer}>
|
2021-04-07 18:31:25 +00:00
|
|
|
{tmid ? null : <RoomTypeIcon type={prid ? 'discussion' : type} isGroupChat={isGroupChat} status={status} teamMain={teamMain} />}
|
2020-03-30 20:19:01 +00:00
|
|
|
<HeaderTitle
|
|
|
|
title={title}
|
|
|
|
tmid={tmid}
|
|
|
|
prid={prid}
|
|
|
|
scale={scale}
|
|
|
|
theme={theme}
|
2021-04-07 18:31:25 +00:00
|
|
|
testID={testID}
|
2020-03-30 20:19:01 +00:00
|
|
|
/>
|
2019-04-08 12:35:28 +00:00
|
|
|
</View>
|
2021-04-07 18:31:25 +00:00
|
|
|
<SubTitle
|
|
|
|
usersTyping={tmid ? [] : usersTyping}
|
|
|
|
subtitle={subtitle}
|
|
|
|
theme={theme}
|
|
|
|
renderFunc={renderFunc}
|
|
|
|
scale={scale}
|
|
|
|
/>
|
2019-11-25 20:01:17 +00:00
|
|
|
</TouchableOpacity>
|
2019-04-08 12:35:28 +00:00
|
|
|
);
|
|
|
|
});
|
|
|
|
|
|
|
|
Header.propTypes = {
|
|
|
|
title: PropTypes.string.isRequired,
|
2020-03-30 20:19:01 +00:00
|
|
|
subtitle: PropTypes.string,
|
2019-04-08 12:35:28 +00:00
|
|
|
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,
|
2021-04-07 18:31:25 +00:00
|
|
|
teamMain: PropTypes.bool,
|
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,
|
2021-03-31 17:47:17 +00:00
|
|
|
isGroupChat: PropTypes.bool,
|
2020-10-30 17:35:07 +00:00
|
|
|
parentTitle: PropTypes.string,
|
2021-04-07 18:31:25 +00:00
|
|
|
onPress: PropTypes.func,
|
|
|
|
testID: PropTypes.string
|
2019-04-08 12:35:28 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
Header.defaultProps = {
|
|
|
|
usersTyping: []
|
|
|
|
};
|
|
|
|
|
2021-04-07 18:31:25 +00:00
|
|
|
export default withTheme(Header);
|