2020-03-30 20:19:01 +00:00
|
|
|
import React, { useState } from 'react';
|
|
|
|
import { View, Text } from 'react-native';
|
|
|
|
import PropTypes from 'prop-types';
|
|
|
|
import { ScrollView, BorderlessButton } from 'react-native-gesture-handler';
|
|
|
|
import Modal from 'react-native-modal';
|
|
|
|
|
|
|
|
import Markdown from '../../containers/markdown';
|
|
|
|
|
2020-05-08 12:57:04 +00:00
|
|
|
import { CustomIcon } from '../../lib/Icons';
|
2020-03-30 20:19:01 +00:00
|
|
|
import { themes } from '../../constants/colors';
|
|
|
|
import styles from './styles';
|
|
|
|
|
|
|
|
const Banner = React.memo(({
|
2020-05-08 12:57:04 +00:00
|
|
|
text, title, theme, bannerClosed, closeBanner
|
2020-03-30 20:19:01 +00:00
|
|
|
}) => {
|
|
|
|
const [showModal, openModal] = useState(false);
|
|
|
|
|
|
|
|
const toggleModal = () => openModal(prevState => !prevState);
|
|
|
|
|
2020-05-08 12:57:04 +00:00
|
|
|
if (text && !bannerClosed) {
|
2020-03-30 20:19:01 +00:00
|
|
|
return (
|
|
|
|
<>
|
|
|
|
<BorderlessButton
|
|
|
|
style={[styles.bannerContainer, { backgroundColor: themes[theme].bannerBackground }]}
|
|
|
|
testID='room-view-banner'
|
|
|
|
onPress={toggleModal}
|
|
|
|
>
|
|
|
|
<Markdown
|
|
|
|
msg={text}
|
|
|
|
theme={theme}
|
|
|
|
numberOfLines={1}
|
2020-05-08 12:57:04 +00:00
|
|
|
style={[styles.bannerText]}
|
2020-03-30 20:19:01 +00:00
|
|
|
preview
|
|
|
|
/>
|
2020-05-08 12:57:04 +00:00
|
|
|
<BorderlessButton onPress={closeBanner}>
|
|
|
|
<CustomIcon
|
|
|
|
color={themes[theme].auxiliaryText}
|
2020-07-27 19:53:33 +00:00
|
|
|
name='close'
|
2020-05-08 12:57:04 +00:00
|
|
|
size={20}
|
|
|
|
/>
|
|
|
|
</BorderlessButton>
|
2020-03-30 20:19:01 +00:00
|
|
|
</BorderlessButton>
|
|
|
|
<Modal
|
|
|
|
onBackdropPress={toggleModal}
|
|
|
|
onBackButtonPress={toggleModal}
|
|
|
|
useNativeDriver
|
|
|
|
isVisible={showModal}
|
|
|
|
animationIn='fadeIn'
|
|
|
|
animationOut='fadeOut'
|
|
|
|
>
|
|
|
|
<View style={[styles.modalView, { backgroundColor: themes[theme].bannerBackground }]}>
|
|
|
|
<Text style={[styles.bannerModalTitle, { color: themes[theme].auxiliaryText }]}>{title}</Text>
|
|
|
|
<ScrollView style={styles.modalScrollView}>
|
|
|
|
<Markdown
|
|
|
|
msg={text}
|
|
|
|
theme={theme}
|
|
|
|
/>
|
|
|
|
</ScrollView>
|
|
|
|
</View>
|
|
|
|
</Modal>
|
|
|
|
</>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
2020-05-08 12:57:04 +00:00
|
|
|
}, (prevProps, nextProps) => prevProps.text === nextProps.text && prevProps.theme === nextProps.theme && prevProps.bannerClosed === nextProps.bannerClosed);
|
2020-03-30 20:19:01 +00:00
|
|
|
|
|
|
|
Banner.propTypes = {
|
|
|
|
text: PropTypes.string,
|
|
|
|
title: PropTypes.string,
|
2020-05-08 12:57:04 +00:00
|
|
|
theme: PropTypes.string,
|
|
|
|
bannerClosed: PropTypes.bool,
|
|
|
|
closeBanner: PropTypes.func
|
2020-03-30 20:19:01 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
export default Banner;
|