2021-04-14 16:03:58 +00:00
|
|
|
import React, { useCallback } from 'react';
|
2019-04-08 12:35:28 +00:00
|
|
|
import PropTypes from 'prop-types';
|
2021-07-26 13:42:31 +00:00
|
|
|
import { View, Text, StyleSheet, TouchableOpacity } from 'react-native';
|
2019-04-08 12:35:28 +00:00
|
|
|
|
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;
|
|
|
|
|
2021-07-26 13:42:31 +00:00
|
|
|
const getSubTitleSize = (scale: number) => SUBTITLE_SIZE * scale;
|
2021-04-07 18:31:25 +00:00
|
|
|
|
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
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2021-07-26 13:42:31 +00:00
|
|
|
type TRoomHeaderSubTitle = {
|
|
|
|
usersTyping: [];
|
|
|
|
theme: string;
|
|
|
|
subtitle: string;
|
|
|
|
renderFunc: any;
|
|
|
|
scale: number;
|
|
|
|
};
|
|
|
|
|
|
|
|
type TRoomHeaderHeaderTitle = {
|
|
|
|
title: string;
|
|
|
|
tmid: string;
|
|
|
|
prid: string;
|
|
|
|
scale: number;
|
|
|
|
theme: string;
|
|
|
|
testID: string;
|
|
|
|
};
|
|
|
|
|
|
|
|
interface IRoomHeader {
|
|
|
|
title: string;
|
|
|
|
subtitle: string;
|
|
|
|
type: string;
|
|
|
|
width: number;
|
|
|
|
height: number;
|
|
|
|
prid: string;
|
|
|
|
tmid: string;
|
|
|
|
teamMain: boolean;
|
|
|
|
status: string;
|
|
|
|
theme: string;
|
|
|
|
usersTyping: [];
|
|
|
|
isGroupChat: boolean;
|
|
|
|
parentTitle: string;
|
|
|
|
onPress: Function;
|
|
|
|
testID: string;
|
|
|
|
}
|
|
|
|
|
|
|
|
const SubTitle = React.memo(({ usersTyping, subtitle, renderFunc, theme, scale }: TRoomHeaderSubTitle) => {
|
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 (
|
2021-07-26 13:42:31 +00:00
|
|
|
// @ts-ignore
|
2020-03-30 20:19:01 +00:00
|
|
|
<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
|
|
|
});
|
|
|
|
|
2021-07-26 13:42:31 +00:00
|
|
|
const HeaderTitle = React.memo(({ title, tmid, prid, scale, theme, testID }: TRoomHeaderHeaderTitle) => {
|
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 (
|
2021-07-26 13:42:31 +00:00
|
|
|
// @ts-ignore
|
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
|
|
|
);
|
|
|
|
});
|
|
|
|
|
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
|
2021-07-26 13:42:31 +00:00
|
|
|
}: IRoomHeader) => {
|
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>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2021-04-14 16:03:58 +00:00
|
|
|
const handleOnPress = useCallback(() => onPress(), []);
|
|
|
|
|
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}
|
2021-04-14 16:03:58 +00:00
|
|
|
onPress={handleOnPress}
|
2020-06-15 14:00:46 +00:00
|
|
|
style={styles.container}
|
2021-07-26 13:42:31 +00:00
|
|
|
// @ts-ignore
|
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
|
|
|
);
|
|
|
|
});
|
|
|
|
|
2021-04-07 18:31:25 +00:00
|
|
|
export default withTheme(Header);
|