Chore: clean RoomHeader (#3923)

This commit is contained in:
Gleidson Daniel Silva 2022-03-31 19:29:14 -03:00 committed by GitHub
parent 4416f82665
commit 64b594f9ae
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 12 additions and 19 deletions

View File

@ -6,8 +6,8 @@ import sharedStyles from '../../views/Styles';
import { themes } from '../../constants/colors'; import { themes } from '../../constants/colors';
import { MarkdownPreview } from '../markdown'; import { MarkdownPreview } from '../markdown';
import RoomTypeIcon from '../RoomTypeIcon'; import RoomTypeIcon from '../RoomTypeIcon';
import { withTheme } from '../../theme';
import { TUserStatus } from '../../definitions'; import { TUserStatus } from '../../definitions';
import { useTheme } from '../../theme';
const HIT_SLOP = { const HIT_SLOP = {
top: 5, top: 5,
@ -44,9 +44,8 @@ const styles = StyleSheet.create({
type TRoomHeaderSubTitle = { type TRoomHeaderSubTitle = {
usersTyping: []; usersTyping: [];
theme: string;
subtitle: string; subtitle: string;
renderFunc: any; renderFunc?: () => React.ReactElement;
scale: number; scale: number;
}; };
@ -55,7 +54,6 @@ type TRoomHeaderHeaderTitle = {
tmid: string; tmid: string;
prid: string; prid: string;
scale: number; scale: number;
theme: string;
testID: string; testID: string;
}; };
@ -77,7 +75,8 @@ interface IRoomHeader {
testID: string; testID: string;
} }
const SubTitle = React.memo(({ usersTyping, subtitle, renderFunc, theme, scale }: TRoomHeaderSubTitle) => { const SubTitle = React.memo(({ usersTyping, subtitle, renderFunc, scale }: TRoomHeaderSubTitle) => {
const { theme } = useTheme();
const fontSize = getSubTitleSize(scale); const fontSize = getSubTitleSize(scale);
// typing // typing
if (usersTyping.length) { if (usersTyping.length) {
@ -108,7 +107,8 @@ const SubTitle = React.memo(({ usersTyping, subtitle, renderFunc, theme, scale }
return null; return null;
}); });
const HeaderTitle = React.memo(({ title, tmid, prid, scale, theme, testID }: TRoomHeaderHeaderTitle) => { const HeaderTitle = React.memo(({ title, tmid, prid, scale, testID }: TRoomHeaderHeaderTitle) => {
const { theme } = useTheme();
const titleStyle = { fontSize: TITLE_SIZE * scale, color: themes[theme].headerTitleColor }; const titleStyle = { fontSize: TITLE_SIZE * scale, color: themes[theme].headerTitleColor };
if (!tmid && !prid) { if (!tmid && !prid) {
return ( return (
@ -133,12 +133,12 @@ const Header = React.memo(
prid, prid,
tmid, tmid,
onPress, onPress,
theme,
isGroupChat, isGroupChat,
teamMain, teamMain,
testID, testID,
usersTyping = [] usersTyping = []
}: IRoomHeader) => { }: IRoomHeader) => {
const { theme } = useTheme();
const portrait = height > width; const portrait = height > width;
let scale = 1; let scale = 1;
@ -153,7 +153,7 @@ const Header = React.memo(
renderFunc = () => ( renderFunc = () => (
<View style={styles.titleContainer}> <View style={styles.titleContainer}>
<RoomTypeIcon type={prid ? 'discussion' : type} isGroupChat={isGroupChat} status={status} teamMain={teamMain} /> <RoomTypeIcon type={prid ? 'discussion' : type} isGroupChat={isGroupChat} status={status} teamMain={teamMain} />
<Text style={[styles.subtitle, { color: themes[theme!].auxiliaryText }]} numberOfLines={1}> <Text style={[styles.subtitle, { color: themes[theme].auxiliaryText }]} numberOfLines={1}>
{parentTitle} {parentTitle}
</Text> </Text>
</View> </View>
@ -168,25 +168,18 @@ const Header = React.memo(
accessibilityLabel={title} accessibilityLabel={title}
onPress={handleOnPress} onPress={handleOnPress}
style={styles.container} style={styles.container}
// @ts-ignore disabled={!!tmid}
disabled={tmid}
hitSlop={HIT_SLOP}> hitSlop={HIT_SLOP}>
<View style={styles.titleContainer}> <View style={styles.titleContainer}>
{tmid ? null : ( {tmid ? null : (
<RoomTypeIcon type={prid ? 'discussion' : type} isGroupChat={isGroupChat} status={status} teamMain={teamMain} /> <RoomTypeIcon type={prid ? 'discussion' : type} isGroupChat={isGroupChat} status={status} teamMain={teamMain} />
)} )}
<HeaderTitle title={title} tmid={tmid} prid={prid} scale={scale} theme={theme!} testID={testID} /> <HeaderTitle title={title} tmid={tmid} prid={prid} scale={scale} testID={testID} />
</View> </View>
<SubTitle <SubTitle usersTyping={tmid ? [] : usersTyping} subtitle={subtitle} renderFunc={renderFunc} scale={scale} />
usersTyping={tmid ? [] : usersTyping}
subtitle={subtitle}
theme={theme!}
renderFunc={renderFunc}
scale={scale}
/>
</TouchableOpacity> </TouchableOpacity>
); );
} }
); );
export default withTheme(Header); export default Header;