2020-03-30 20:19:01 +00:00
|
|
|
import React, { useState } from 'react';
|
2021-09-13 20:41:05 +00:00
|
|
|
import { Text, View } from 'react-native';
|
|
|
|
import { BorderlessButton, ScrollView } from 'react-native-gesture-handler';
|
2020-03-30 20:19:01 +00:00
|
|
|
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';
|
|
|
|
|
2021-12-02 02:24:51 +00:00
|
|
|
interface IRoomBannerProps {
|
|
|
|
text: string;
|
|
|
|
title: string;
|
|
|
|
theme: string;
|
|
|
|
bannerClosed: boolean;
|
|
|
|
closeBanner(): void;
|
2021-12-07 00:30:49 +00:00
|
|
|
rid?: string; // TODO - verify if this props exist
|
2021-12-02 02:24:51 +00:00
|
|
|
}
|
|
|
|
|
2021-09-13 20:41:05 +00:00
|
|
|
const Banner = React.memo(
|
2021-12-02 02:24:51 +00:00
|
|
|
({ text, title, theme, bannerClosed, closeBanner }: IRoomBannerProps) => {
|
2021-09-13 20:41:05 +00:00
|
|
|
const [showModal, openModal] = useState(false);
|
|
|
|
|
|
|
|
const toggleModal = () => openModal(prevState => !prevState);
|
|
|
|
|
|
|
|
if (text && !bannerClosed) {
|
|
|
|
return (
|
|
|
|
<>
|
|
|
|
<BorderlessButton
|
|
|
|
style={[styles.bannerContainer, { backgroundColor: themes[theme].bannerBackground }]}
|
|
|
|
testID='room-view-banner'
|
|
|
|
onPress={toggleModal}>
|
2021-12-02 02:24:51 +00:00
|
|
|
{/* @ts-ignore*/}
|
2021-09-13 20:41:05 +00:00
|
|
|
<Markdown msg={text} theme={theme} numberOfLines={1} style={[styles.bannerText]} preview />
|
|
|
|
<BorderlessButton onPress={closeBanner}>
|
|
|
|
<CustomIcon color={themes[theme].auxiliaryText} name='close' size={20} />
|
|
|
|
</BorderlessButton>
|
2020-05-08 12:57:04 +00:00
|
|
|
</BorderlessButton>
|
2021-09-13 20:41:05 +00:00
|
|
|
<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}>
|
2021-12-02 02:24:51 +00:00
|
|
|
{/* @ts-ignore*/}
|
2021-09-13 20:41:05 +00:00
|
|
|
<Markdown msg={text} theme={theme} />
|
|
|
|
</ScrollView>
|
|
|
|
</View>
|
|
|
|
</Modal>
|
|
|
|
</>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
|
|
|
},
|
|
|
|
(prevProps, nextProps) =>
|
|
|
|
prevProps.text === nextProps.text && prevProps.theme === nextProps.theme && prevProps.bannerClosed === nextProps.bannerClosed
|
|
|
|
);
|
2020-03-30 20:19:01 +00:00
|
|
|
|
|
|
|
export default Banner;
|