2021-09-13 20:41:05 +00:00
|
|
|
import React, { useContext } from 'react';
|
|
|
|
|
|
|
|
import Touchable from './Touchable';
|
2022-05-02 19:21:15 +00:00
|
|
|
import { CustomIcon } from '../CustomIcon';
|
2021-09-13 20:41:05 +00:00
|
|
|
import styles from './styles';
|
|
|
|
import { BUTTON_HIT_SLOP } from './utils';
|
2022-04-07 14:10:03 +00:00
|
|
|
import { themes } from '../../lib/constants';
|
2021-09-13 20:41:05 +00:00
|
|
|
import MessageContext from './Context';
|
2022-04-01 21:52:38 +00:00
|
|
|
import { useTheme } from '../../theme';
|
2021-09-13 20:41:05 +00:00
|
|
|
|
|
|
|
const MessageError = React.memo(
|
2022-04-01 21:52:38 +00:00
|
|
|
({ hasError }: { hasError: boolean }) => {
|
|
|
|
const { theme } = useTheme();
|
2022-04-11 18:01:43 +00:00
|
|
|
const { onErrorPress } = useContext(MessageContext);
|
2022-04-01 21:52:38 +00:00
|
|
|
|
2021-09-13 20:41:05 +00:00
|
|
|
if (!hasError) {
|
|
|
|
return null;
|
|
|
|
}
|
2022-04-11 18:01:43 +00:00
|
|
|
|
2021-09-13 20:41:05 +00:00
|
|
|
return (
|
|
|
|
<Touchable onPress={onErrorPress} style={styles.errorButton} hitSlop={BUTTON_HIT_SLOP}>
|
|
|
|
<CustomIcon name='warning' color={themes[theme].dangerColor} size={18} />
|
|
|
|
</Touchable>
|
|
|
|
);
|
|
|
|
},
|
2022-04-01 21:52:38 +00:00
|
|
|
(prevProps, nextProps) => prevProps.hasError === nextProps.hasError
|
2021-09-13 20:41:05 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
MessageError.displayName = 'MessageError';
|
|
|
|
|
|
|
|
export default MessageError;
|