2022-06-01 19:46:37 +00:00
|
|
|
import { HeaderBackButton } from '@react-navigation/elements';
|
2023-06-30 14:01:01 +00:00
|
|
|
import React, { useCallback } from 'react';
|
|
|
|
import { Platform, StyleSheet } from 'react-native';
|
2022-03-02 14:18:01 +00:00
|
|
|
|
|
|
|
import Avatar from '../../containers/Avatar';
|
2023-06-30 14:01:01 +00:00
|
|
|
import { themes } from '../../lib/constants';
|
|
|
|
import { useAppNavigation } from '../../lib/hooks/navigation';
|
2022-07-06 13:23:02 +00:00
|
|
|
import { isIOS } from '../../lib/methods/helpers';
|
2023-06-30 14:01:01 +00:00
|
|
|
import { TSupportedThemes } from '../../theme';
|
2022-03-02 14:18:01 +00:00
|
|
|
|
|
|
|
const styles = StyleSheet.create({
|
2022-07-06 13:23:02 +00:00
|
|
|
container: {
|
|
|
|
...Platform.select({
|
|
|
|
ios: {
|
|
|
|
minWidth: 60
|
|
|
|
}
|
|
|
|
})
|
|
|
|
},
|
2022-03-02 14:18:01 +00:00
|
|
|
avatar: {
|
|
|
|
borderRadius: 10,
|
2022-07-06 13:23:02 +00:00
|
|
|
marginHorizontal: 15
|
2022-03-02 14:18:01 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
interface ILeftButtonsProps {
|
2023-04-10 14:59:00 +00:00
|
|
|
rid?: string;
|
2022-03-02 14:18:01 +00:00
|
|
|
tmid?: string;
|
|
|
|
unreadsCount: number | null;
|
|
|
|
baseUrl: string;
|
|
|
|
userId?: string;
|
|
|
|
token?: string;
|
|
|
|
title?: string;
|
|
|
|
t: string;
|
2022-04-12 16:27:05 +00:00
|
|
|
theme: TSupportedThemes;
|
2022-03-02 14:18:01 +00:00
|
|
|
goRoomActionsView: Function;
|
|
|
|
isMasterDetail: boolean;
|
|
|
|
}
|
|
|
|
|
|
|
|
const LeftButtons = ({
|
2023-04-10 14:59:00 +00:00
|
|
|
rid,
|
2022-03-02 14:18:01 +00:00
|
|
|
tmid,
|
|
|
|
unreadsCount,
|
|
|
|
baseUrl,
|
|
|
|
userId,
|
|
|
|
token,
|
|
|
|
title,
|
|
|
|
t,
|
|
|
|
theme,
|
|
|
|
goRoomActionsView,
|
|
|
|
isMasterDetail
|
|
|
|
}: ILeftButtonsProps): React.ReactElement | null => {
|
2023-06-30 14:01:01 +00:00
|
|
|
const { goBack } = useAppNavigation();
|
2022-04-11 18:01:43 +00:00
|
|
|
const onPress = useCallback(() => goRoomActionsView(), []);
|
|
|
|
|
2022-03-02 14:18:01 +00:00
|
|
|
if (!isMasterDetail || tmid) {
|
|
|
|
let label = ' ';
|
|
|
|
let labelLength = 1;
|
|
|
|
let marginLeft = 0;
|
|
|
|
let fontSize = 0;
|
|
|
|
if (unreadsCount) {
|
|
|
|
label = unreadsCount > 99 ? '+99' : unreadsCount.toString() || ' ';
|
|
|
|
labelLength = label.length ? label.length : 1;
|
|
|
|
marginLeft = -2 * labelLength;
|
|
|
|
fontSize = labelLength > 1 ? 14 : 17;
|
|
|
|
}
|
|
|
|
return (
|
|
|
|
<HeaderBackButton
|
|
|
|
label={label}
|
2022-07-06 13:23:02 +00:00
|
|
|
labelVisible={isIOS}
|
2023-06-30 14:01:01 +00:00
|
|
|
onPress={goBack}
|
2022-03-02 14:18:01 +00:00
|
|
|
tintColor={themes[theme].headerTintColor}
|
|
|
|
labelStyle={{ fontSize, marginLeft }}
|
2022-07-06 13:23:02 +00:00
|
|
|
style={styles.container}
|
2022-11-16 13:26:37 +00:00
|
|
|
testID='header-back'
|
2022-03-02 14:18:01 +00:00
|
|
|
/>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (baseUrl && userId && token) {
|
2023-04-10 14:59:00 +00:00
|
|
|
return <Avatar rid={rid} text={title} size={30} type={t} style={styles.avatar} onPress={onPress} />;
|
2022-03-02 14:18:01 +00:00
|
|
|
}
|
|
|
|
return null;
|
|
|
|
};
|
|
|
|
|
|
|
|
export default LeftButtons;
|