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';
|
|
|
|
|
|
|
|
import I18n from '../../../i18n';
|
|
|
|
import sharedStyles from '../../Styles';
|
|
|
|
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
|
|
|
|
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;
|
|
|
|
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: {
|
|
|
|
...sharedStyles.textSemibold,
|
|
|
|
fontSize: TITLE_SIZE
|
|
|
|
},
|
2020-03-30 20:19:01 +00:00
|
|
|
subtitle: {
|
2019-04-08 12:35:28 +00:00
|
|
|
...sharedStyles.textRegular,
|
2020-03-30 20:19:01 +00:00
|
|
|
fontSize: 12
|
2019-04-08 12:35:28 +00:00
|
|
|
},
|
|
|
|
typingUsers: {
|
|
|
|
...sharedStyles.textSemibold
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2020-10-30 17:35:07 +00:00
|
|
|
const SubTitle = React.memo(({
|
|
|
|
usersTyping, subtitle, renderFunc, theme
|
|
|
|
}) => {
|
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 (
|
|
|
|
<Text style={[styles.subtitle, { color: themes[theme].auxiliaryText }]} numberOfLines={1}>
|
|
|
|
<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}
|
|
|
|
style={[styles.subtitle, { color: themes[theme].auxiliaryText }]}
|
|
|
|
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,
|
|
|
|
renderFunc: PropTypes.func
|
2019-04-08 12:35:28 +00:00
|
|
|
};
|
|
|
|
|
2019-04-30 19:31:51 +00:00
|
|
|
const HeaderTitle = React.memo(({
|
2020-07-06 20:56:28 +00:00
|
|
|
title, tmid, prid, scale, theme
|
2019-04-30 19:31:51 +00:00
|
|
|
}) => {
|
2020-03-05 14:35:05 +00:00
|
|
|
if (!tmid && !prid) {
|
|
|
|
return (
|
|
|
|
<Text
|
|
|
|
style={[styles.title, { fontSize: TITLE_SIZE * scale, color: themes[theme].headerTitleColor }]}
|
|
|
|
numberOfLines={1}
|
|
|
|
testID={`room-view-title-${ title }`}
|
|
|
|
>
|
|
|
|
{title}
|
|
|
|
</Text>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2019-04-30 19:31:51 +00:00
|
|
|
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}
|
2020-03-03 20:40:20 +00:00
|
|
|
theme={theme}
|
2020-03-06 18:13:33 +00:00
|
|
|
testID={`room-view-title-${ title }`}
|
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,
|
2019-12-04 16:39:53 +00:00
|
|
|
theme: PropTypes.string
|
2019-04-30 19:31:51 +00:00
|
|
|
};
|
|
|
|
|
2019-04-08 12:35:28 +00:00
|
|
|
const Header = React.memo(({
|
2020-10-30 17:35:07 +00:00
|
|
|
title, subtitle, parentTitle, type, status, usersTyping, width, height, prid, tmid, connecting, goRoomActionsView, roomUserId, 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) {
|
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-03-30 20:19:01 +00:00
|
|
|
const onPress = () => goRoomActionsView();
|
2019-11-25 20:01:17 +00:00
|
|
|
|
2020-10-30 17:35:07 +00:00
|
|
|
let renderFunc;
|
|
|
|
if (tmid) {
|
|
|
|
renderFunc = () => (
|
|
|
|
<View style={styles.titleContainer}>
|
|
|
|
<Icon
|
|
|
|
type={prid ? 'discussion' : type}
|
|
|
|
tmid={tmid}
|
|
|
|
status={status}
|
|
|
|
roomUserId={roomUserId}
|
|
|
|
theme={theme}
|
|
|
|
/>
|
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
|
|
|
|
testID='room-view-header-actions'
|
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}>
|
2020-10-30 17:35:07 +00:00
|
|
|
{tmid ? null : <Icon type={prid ? 'discussion' : type} status={status} roomUserId={roomUserId} theme={theme} />}
|
2020-03-30 20:19:01 +00:00
|
|
|
<HeaderTitle
|
|
|
|
title={title}
|
|
|
|
tmid={tmid}
|
|
|
|
prid={prid}
|
|
|
|
scale={scale}
|
|
|
|
connecting={connecting}
|
|
|
|
theme={theme}
|
|
|
|
/>
|
2019-04-08 12:35:28 +00:00
|
|
|
</View>
|
2020-10-30 17:35:07 +00:00
|
|
|
<SubTitle usersTyping={usersTyping} subtitle={subtitle} theme={theme} renderFunc={renderFunc} />
|
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,
|
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-11-25 20:01:17 +00:00
|
|
|
connecting: PropTypes.bool,
|
2020-04-01 12:28:54 +00:00
|
|
|
roomUserId: PropTypes.string,
|
2020-10-30 17:35:07 +00:00
|
|
|
parentTitle: PropTypes.string,
|
2019-11-25 20:01:17 +00:00
|
|
|
goRoomActionsView: PropTypes.func
|
2019-04-08 12:35:28 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
Header.defaultProps = {
|
|
|
|
usersTyping: []
|
|
|
|
};
|
|
|
|
|
|
|
|
export default Header;
|