Skip to content

Commit 3ca3c90

Browse files
committed
Merge branch 'patch' of github.com:gluestack/gluestack-ui into patch
2 parents c45ec7c + a93b3b8 commit 3ca3c90

File tree

9 files changed

+284
-225
lines changed

9 files changed

+284
-225
lines changed

.changeset/few-rules-refuse.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
---
2+
'@gluestack-ui/toast': patch
3+
---
4+
5+
Multple fixes to toast
6+
7+
- Fixed `isActive` always returning false
8+
- Removed almost all instances of `any`, replaced with actual types
9+
- Fixed duplicate toasts when calling `show` with an existing id
10+
- Removed unnecessary `@ts-ignore` usages

example/storybook-nativewind/src/components/Toast/Toast.tsx

Lines changed: 39 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React from 'react';
1+
import React, { useState } from 'react';
22
import { Icon, CloseIcon } from '@/components/ui/icon';
33
import { VStack } from '@/components/ui/vstack';
44
import { Pressable } from '@/components/ui/pressable';
@@ -26,31 +26,46 @@ const ToastFigmaStory = ({ _placement = 'top', _colorMode, ...props }: any) => {
2626
);
2727
};
2828

29-
const ToastBasic = ({ placement = 'top', ...props }: any) => {
29+
const ToastBasic = ({ ...props }: any) => {
3030
const toast = useToast();
31+
const [toastId, setToastId] = useState<number>(0);
32+
33+
const handleToast = () => {
34+
if (!toast.isActive(toastId)) {
35+
showNewToast();
36+
}
37+
};
38+
39+
const showNewToast = () => {
40+
const newId = Math.random();
41+
setToastId(newId);
42+
43+
toast.show({
44+
id: newId,
45+
placement: props.placement,
46+
duration: 3000,
47+
// duration: null,
48+
render: ({ id }) => {
49+
const uniqueToastId = `toast-${id}`;
50+
return (
51+
<Toast nativeID={uniqueToastId} {...props} className="flex-row gap-3">
52+
<VStack space="xs">
53+
<ToastTitle>Hello World Toast</ToastTitle>
54+
<ToastDescription>
55+
Please create a support ticket from the support page
56+
</ToastDescription>
57+
</VStack>
58+
<Pressable onPress={() => toast.close(id)}>
59+
<Icon as={CloseIcon} className="stroke-background-200" />
60+
</Pressable>
61+
</Toast>
62+
);
63+
},
64+
});
65+
};
66+
3167
return (
32-
<Button
33-
onPress={() => {
34-
toast.show({
35-
placement: placement,
36-
duration: 3000,
37-
// duration: null,
38-
render: ({ id }) => {
39-
const toastId = `toast-${id}`;
40-
return (
41-
<>
42-
<Toast nativeID={toastId} {...props}>
43-
<ToastTitle>Toast Heading</ToastTitle>
44-
<ToastDescription>
45-
Lorem ipsum dolor sit amet consectetur.
46-
</ToastDescription>
47-
</Toast>
48-
</>
49-
);
50-
},
51-
});
52-
}}
53-
>
68+
<Button onPress={handleToast}>
5469
<ButtonText>Press Me</ButtonText>
5570
</Button>
5671
);

0 commit comments

Comments
 (0)