Skip to content

Commit

Permalink
Merge pull request #27 from platformbuilders/fix/reload
Browse files Browse the repository at this point in the history
fix: reload toast
  • Loading branch information
mdlucas authored Jul 4, 2024
2 parents b9286a0 + 83eb7a4 commit ae93d12
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 24 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@platformbuilders/react-native-toast",
"version": "1.4.0",
"version": "1.4.1",
"description": "",
"author": "Platform Builders <[email protected]>",
"repository": {
Expand Down
46 changes: 23 additions & 23 deletions src/Toast.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -156,10 +156,7 @@ type Props = {
config: ToastConfig;
};

export const Toast: FC<Props> = ({
data: { message, type, duration = 2500, title },
config,
}) => {
export const Toast: FC<Props> = ({ data, config }) => {
const [toastHeight, setToastHeight] = useState(0);

const [toast, setToast] = useState<ToastProps>({
Expand All @@ -168,8 +165,8 @@ export const Toast: FC<Props> = ({
type: 'success',
});

const showCloseButton = config.showCloseButton[type];
const disabledAutoHide = config.autoHide[type];
const showCloseButton = config.showCloseButton[data.type];
const disabledAutoHide = config.autoHide[data.type];
const disabledGesture = !disabledAutoHide;

const handleBackgroundColor = () => {
Expand All @@ -178,10 +175,13 @@ export const Toast: FC<Props> = ({
const error = '#ff726b';
const custom = '#4794ff';

if (type === 'success') return config?.backgroundColor?.success || success;
if (type === 'warning') return config?.backgroundColor?.warning || warning;
if (type === 'error') return config?.backgroundColor?.error || error;
if (type === 'custom') return config?.backgroundColor?.custom || custom;
if (data.type === 'success')
return config?.backgroundColor?.success || success;
if (data.type === 'warning')
return config?.backgroundColor?.warning || warning;
if (data.type === 'error') return config?.backgroundColor?.error || error;
if (data.type === 'custom')
return config?.backgroundColor?.custom || custom;
return config?.backgroundColor?.success || success;
};

Expand Down Expand Up @@ -263,7 +263,7 @@ export const Toast: FC<Props> = ({

const handleDismiss = () => {
if (disabledAutoHide) {
timeout = setTimeout(() => dismissToast(), duration);
timeout = setTimeout(() => dismissToast(), data.duration);
return () => resetTimeout();
}

Expand All @@ -280,14 +280,14 @@ export const Toast: FC<Props> = ({
}, [toast.message, toastHeight]);

useEffect(() => {
if (!!message) {
if (!!data.message.length) {
setToast({
title: title,
message: message,
type: type,
title: data.title,
message: data.message,
type: data.type,
});
}
}, [message]);
}, [data]);

const panGestureEvent = useAnimatedGestureHandler<
PanGestureHandlerGestureEvent,
Expand Down Expand Up @@ -335,31 +335,31 @@ export const Toast: FC<Props> = ({
config?.customIcon[toast.type]}

<TextContainer>
{!!title && (
{!!data.title && (
<Title
fontFamily={config?.fontFamily}
textColor={
typeof config?.textColor === 'string'
? config?.textColor
: config?.textColor?.[type]
: config?.textColor?.[data.type]
}
size={config?.titleSize}
>
{title?.trim()}
{data.title?.trim()}
</Title>
)}

{message && (
{data.message && (
<Message
fontFamily={config?.fontFamily}
textColor={
typeof config?.textColor === 'string'
? config?.textColor
: config?.textColor?.[type]
: config?.textColor?.[data.type]
}
size={config?.messageSize}
>
{message?.trim()}
{data.message?.trim()}
</Message>
)}
</TextContainer>
Expand All @@ -371,7 +371,7 @@ export const Toast: FC<Props> = ({
textColor={
typeof config?.textColor === 'string'
? config?.textColor
: config?.textColor?.[type]
: config?.textColor?.[data.type]
}
>
{config.closeButtonText?.trim()}
Expand Down

0 comments on commit ae93d12

Please sign in to comment.