2020-04-30 20:05:59 +00:00
|
|
|
import React, { useContext } from 'react';
|
2019-05-20 20:43:50 +00:00
|
|
|
import PropTypes from 'prop-types';
|
|
|
|
|
2020-04-30 20:05:59 +00:00
|
|
|
import Touchable from './Touchable';
|
2019-05-20 20:43:50 +00:00
|
|
|
import { CustomIcon } from '../../lib/Icons';
|
|
|
|
import styles from './styles';
|
2019-07-17 14:06:39 +00:00
|
|
|
import { BUTTON_HIT_SLOP } from './utils';
|
2019-12-04 16:39:53 +00:00
|
|
|
import { themes } from '../../constants/colors';
|
2020-04-30 20:05:59 +00:00
|
|
|
import MessageContext from './Context';
|
2019-05-20 20:43:50 +00:00
|
|
|
|
2020-04-30 20:05:59 +00:00
|
|
|
const MessageError = React.memo(({ hasError, theme }) => {
|
2019-05-20 20:43:50 +00:00
|
|
|
if (!hasError) {
|
|
|
|
return null;
|
|
|
|
}
|
2020-04-30 20:05:59 +00:00
|
|
|
const { onErrorPress } = useContext(MessageContext);
|
2019-05-20 20:43:50 +00:00
|
|
|
return (
|
2019-07-17 14:06:39 +00:00
|
|
|
<Touchable onPress={onErrorPress} style={styles.errorButton} hitSlop={BUTTON_HIT_SLOP}>
|
2019-12-04 16:39:53 +00:00
|
|
|
<CustomIcon name='warning' color={themes[theme].dangerColor} size={18} />
|
2019-05-20 20:43:50 +00:00
|
|
|
</Touchable>
|
|
|
|
);
|
2019-12-04 16:39:53 +00:00
|
|
|
}, (prevProps, nextProps) => prevProps.hasError === nextProps.hasError && prevProps.theme === nextProps.theme);
|
2019-05-20 20:43:50 +00:00
|
|
|
|
|
|
|
MessageError.propTypes = {
|
|
|
|
hasError: PropTypes.bool,
|
2019-12-04 16:39:53 +00:00
|
|
|
theme: PropTypes.string
|
2019-05-20 20:43:50 +00:00
|
|
|
};
|
|
|
|
MessageError.displayName = 'MessageError';
|
|
|
|
|
|
|
|
export default MessageError;
|