2020-06-15 14:00:46 +00:00
|
|
|
import React, { useCallback } from 'react';
|
2019-11-25 20:01:17 +00:00
|
|
|
import { StyleSheet } from 'react-native';
|
2021-12-08 05:19:44 +00:00
|
|
|
import { HeaderBackButton, StackNavigationProp } from '@react-navigation/stack';
|
2019-11-25 20:01:17 +00:00
|
|
|
|
2021-04-07 18:31:25 +00:00
|
|
|
import { themes } from '../../constants/colors';
|
|
|
|
import Avatar from '../../containers/Avatar';
|
2021-12-08 05:19:44 +00:00
|
|
|
import { ChatsStackParamList } from '../../stacks/types';
|
2019-11-25 20:01:17 +00:00
|
|
|
|
|
|
|
const styles = StyleSheet.create({
|
|
|
|
avatar: {
|
|
|
|
borderRadius: 10,
|
|
|
|
marginHorizontal: 16
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2021-12-02 20:47:01 +00:00
|
|
|
interface IRoomLeftButtonsProps {
|
2021-12-07 00:30:49 +00:00
|
|
|
tmid?: string;
|
2021-12-16 02:27:19 +00:00
|
|
|
unreadsCount: number & string;
|
2021-12-08 05:19:44 +00:00
|
|
|
navigation: StackNavigationProp<ChatsStackParamList>;
|
2021-12-02 20:11:49 +00:00
|
|
|
baseUrl: string;
|
|
|
|
userId: string;
|
|
|
|
token: string;
|
|
|
|
title: string;
|
|
|
|
t: string;
|
|
|
|
theme: string;
|
|
|
|
goRoomActionsView: Function;
|
|
|
|
isMasterDetail: boolean;
|
|
|
|
}
|
|
|
|
|
2021-09-13 20:41:05 +00:00
|
|
|
const LeftButtons = React.memo(
|
2021-12-02 20:11:49 +00:00
|
|
|
({
|
|
|
|
tmid,
|
|
|
|
unreadsCount,
|
|
|
|
navigation,
|
|
|
|
baseUrl,
|
|
|
|
userId,
|
|
|
|
token,
|
|
|
|
title,
|
|
|
|
t,
|
|
|
|
theme,
|
|
|
|
goRoomActionsView,
|
|
|
|
isMasterDetail
|
2021-12-02 20:47:01 +00:00
|
|
|
}: IRoomLeftButtonsProps) => {
|
2021-09-13 20:41:05 +00:00
|
|
|
if (!isMasterDetail || tmid) {
|
2021-12-02 20:11:49 +00:00
|
|
|
const onPress = useCallback(() => navigation.goBack(), []);
|
2021-12-16 02:27:19 +00:00
|
|
|
const label = unreadsCount > 99 ? '+99' : unreadsCount || ' ';
|
2021-09-13 20:41:05 +00:00
|
|
|
const labelLength = label.length ? label.length : 1;
|
|
|
|
const marginLeft = -2 * labelLength;
|
|
|
|
const fontSize = labelLength > 1 ? 14 : 17;
|
|
|
|
return (
|
|
|
|
<HeaderBackButton
|
|
|
|
label={label}
|
|
|
|
onPress={onPress}
|
|
|
|
tintColor={themes[theme].headerTintColor}
|
|
|
|
labelStyle={{ fontSize, marginLeft }}
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
const onPress = useCallback(() => goRoomActionsView(), []);
|
2020-10-30 13:12:02 +00:00
|
|
|
|
2021-09-13 20:41:05 +00:00
|
|
|
if (baseUrl && userId && token) {
|
|
|
|
return <Avatar text={title} size={30} type={t} style={styles.avatar} onPress={onPress} />;
|
|
|
|
}
|
|
|
|
return null;
|
2019-11-25 20:01:17 +00:00
|
|
|
}
|
2021-09-13 20:41:05 +00:00
|
|
|
);
|
2019-11-25 20:01:17 +00:00
|
|
|
|
2020-07-06 20:56:28 +00:00
|
|
|
export default LeftButtons;
|