2020-06-15 14:00:46 +00:00
|
|
|
import React, { useCallback } from 'react';
|
2019-11-25 20:01:17 +00:00
|
|
|
import PropTypes from 'prop-types';
|
|
|
|
import { StyleSheet } from 'react-native';
|
2020-06-15 14:00:46 +00:00
|
|
|
import { HeaderBackButton } 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';
|
2019-11-25 20:01:17 +00:00
|
|
|
|
|
|
|
const styles = StyleSheet.create({
|
|
|
|
avatar: {
|
|
|
|
borderRadius: 10,
|
|
|
|
marginHorizontal: 16
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2020-07-06 20:56:28 +00:00
|
|
|
const LeftButtons = React.memo(({
|
2020-06-15 14:00:46 +00:00
|
|
|
tmid, unreadsCount, navigation, baseUrl, userId, token, title, t, theme, goRoomActionsView, isMasterDetail
|
2019-11-25 20:01:17 +00:00
|
|
|
}) => {
|
2020-06-15 14:00:46 +00:00
|
|
|
if (!isMasterDetail || tmid) {
|
|
|
|
const onPress = useCallback(() => navigation.goBack());
|
2020-07-06 20:56:28 +00:00
|
|
|
const label = unreadsCount > 99 ? '+99' : unreadsCount || ' ';
|
|
|
|
const labelLength = label.length ? label.length : 1;
|
|
|
|
const marginLeft = -2 * labelLength;
|
|
|
|
const fontSize = labelLength > 1 ? 14 : 17;
|
2019-11-25 20:01:17 +00:00
|
|
|
return (
|
|
|
|
<HeaderBackButton
|
2020-07-06 20:56:28 +00:00
|
|
|
label={label}
|
2020-06-15 14:00:46 +00:00
|
|
|
onPress={onPress}
|
2019-12-04 16:39:53 +00:00
|
|
|
tintColor={themes[theme].headerTintColor}
|
2020-07-06 20:56:28 +00:00
|
|
|
labelStyle={{ fontSize, marginLeft }}
|
2019-11-25 20:01:17 +00:00
|
|
|
/>
|
|
|
|
);
|
|
|
|
}
|
2020-06-15 14:00:46 +00:00
|
|
|
const onPress = useCallback(() => goRoomActionsView(), []);
|
2020-10-30 13:12:02 +00:00
|
|
|
|
2019-11-25 20:01:17 +00:00
|
|
|
if (baseUrl && userId && token) {
|
|
|
|
return (
|
|
|
|
<Avatar
|
|
|
|
text={title}
|
|
|
|
size={30}
|
|
|
|
type={t}
|
|
|
|
style={styles.avatar}
|
2020-06-15 14:00:46 +00:00
|
|
|
onPress={onPress}
|
2019-11-25 20:01:17 +00:00
|
|
|
/>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
return null;
|
2020-06-15 14:00:46 +00:00
|
|
|
});
|
2019-11-25 20:01:17 +00:00
|
|
|
|
2020-07-06 20:56:28 +00:00
|
|
|
LeftButtons.propTypes = {
|
2019-11-25 20:01:17 +00:00
|
|
|
tmid: PropTypes.string,
|
|
|
|
unreadsCount: PropTypes.number,
|
|
|
|
navigation: PropTypes.object,
|
|
|
|
baseUrl: PropTypes.string,
|
|
|
|
userId: PropTypes.string,
|
|
|
|
token: PropTypes.string,
|
|
|
|
title: PropTypes.string,
|
|
|
|
t: PropTypes.string,
|
2019-12-04 16:39:53 +00:00
|
|
|
theme: PropTypes.string,
|
2019-11-25 20:01:17 +00:00
|
|
|
goRoomActionsView: PropTypes.func,
|
2020-06-15 14:00:46 +00:00
|
|
|
isMasterDetail: PropTypes.bool
|
2019-11-25 20:01:17 +00:00
|
|
|
};
|
|
|
|
|
2020-07-06 20:56:28 +00:00
|
|
|
export default LeftButtons;
|