Rocket.Chat.ReactNative/app/containers/Toast.js

54 lines
1.0 KiB
JavaScript
Raw Normal View History

2019-07-23 14:02:57 +00:00
import React from 'react';
import { StyleSheet } from 'react-native';
import EasyToast from 'react-native-easy-toast';
import { COLOR_TOAST, COLOR_WHITE } from '../constants/colors';
import sharedStyles from '../views/Styles';
import EventEmitter from '../utils/events';
const styles = StyleSheet.create({
toast: {
backgroundColor: COLOR_TOAST,
maxWidth: 300,
padding: 10
},
text: {
...sharedStyles.textRegular,
color: COLOR_WHITE,
fontSize: 14,
textAlign: 'center'
}
});
export const LISTENER = 'Toast';
export default class Toast extends React.Component {
componentDidMount() {
EventEmitter.addEventListener(LISTENER, this.showToast);
}
shouldComponentUpdate() {
return false;
}
componentWillUnmount() {
EventEmitter.removeListener(LISTENER);
}
showToast = ({ message }) => {
this.toast.show(message, 1000);
}
render() {
return (
<EasyToast
ref={toast => this.toast = toast}
position='center'
style={styles.toast}
textStyle={styles.text}
opacity={0.9}
/>
);
}
}