Skip to content

Commit

Permalink
Merge pull request #28 from platformbuilders/feat/condition
Browse files Browse the repository at this point in the history
fix: condition show toast
  • Loading branch information
mdlucas authored Jul 10, 2024
2 parents ae93d12 + 15424da commit 6fc19b2
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 9 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@platformbuilders/react-native-toast",
"version": "1.4.1",
"version": "1.4.2",
"description": "",
"author": "Platform Builders <[email protected]>",
"repository": {
Expand Down Expand Up @@ -55,4 +55,4 @@
"styled-components": "^5.3.11",
"typescript": "^5.1.3"
}
}
}
14 changes: 8 additions & 6 deletions src/Toast.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,8 @@ export const Toast: FC<Props> = ({ data, config }) => {
type: 'success',
});

const isValidToast = !!toast.message?.trim() || toast.title?.trim();

const showCloseButton = config.showCloseButton[data.type];
const disabledAutoHide = config.autoHide[data.type];
const disabledGesture = !disabledAutoHide;
Expand Down Expand Up @@ -276,11 +278,11 @@ export const Toast: FC<Props> = ({ data, config }) => {
};

useEffect(() => {
if (!!toast.message) handleAnimation();
}, [toast.message, toastHeight]);
if (isValidToast) handleAnimation();
}, [toast.message, toast.title, toastHeight]);

useEffect(() => {
if (!!data.message.length) {
if (data.message || data.title) {
setToast({
title: data.title,
message: data.message,
Expand Down Expand Up @@ -315,7 +317,7 @@ export const Toast: FC<Props> = ({ data, config }) => {
},
});

return toast?.message?.length > 0 ? (
return isValidToast ? (
<PanGestureHandler onGestureEvent={panGestureEvent}>
<Container
onLayout={handleViewLayout}
Expand All @@ -335,7 +337,7 @@ export const Toast: FC<Props> = ({ data, config }) => {
config?.customIcon[toast.type]}

<TextContainer>
{!!data.title && (
{!!data.title?.trim() && (
<Title
fontFamily={config?.fontFamily}
textColor={
Expand All @@ -349,7 +351,7 @@ export const Toast: FC<Props> = ({ data, config }) => {
</Title>
)}

{data.message && (
{data.message?.trim() && (
<Message
fontFamily={config?.fontFamily}
textColor={
Expand Down
1 change: 0 additions & 1 deletion src/styles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ export const Title = styled.Text<TextProps>`
font-weight: ${fontWeight};
font-family: ${({ fontFamily }) => fontFamily ?? fontDefault};
color: ${({ textColor }) => textColor ?? '#fff'};
margin-bottom: 12px;
`;

export const Message = styled.Text<TextProps>`
Expand Down

0 comments on commit 6fc19b2

Please sign in to comment.