NativeBase
NativeBase copied to clipboard
Toast is placed out of position every time I call this.
Description
Toast is placed out of position every time I call this.
CodeSandbox/Snack link
I am sorry. I don't have it.
Steps to reproduce
- Create custom
Toast
like below.
export const useCustomToastHook = () => {
const toast = useToast()
const id = 'result'
const showToast = ({ variant, message }: ShowToastProps) => {
const styleMap: StyleMapObj = {
fontColor: '',
backgroundColor: '',
}
if (variant === 'error') {
styleMap.fontColor = 'Accent.Normal'
styleMap.backgroundColor = 'Accent.Light'
} else if (variant === 'success') {
styleMap.fontColor = 'Main.Normal'
styleMap.backgroundColor = 'Main.Light'
}
if (!toast.isActive(id)) {
toast.show({
placement: 'top',
render: () => (
<Box
bg={styleMap.backgroundColor}
borderRadius="2xl"
px="8"
py="4"
// top="16"
_text={{ color: styleMap.fontColor, fontWeight: 'normal' }}
>
{message}
</Box>
),
})
}
}
- Use
toast.show
, in my case,showToast()
method. - After checking
Toast
disappears, usetoast.show
again. - You can see
Toast
is placed under the position where theToast
which was called in Step2, is set
NativeBase Version
3.3.11
Platform
- [ ] Android
- [ ] CRA
- [X] Expo
- [X] iOS
- [ ] Next
Other Platform
No response
Additional Information
Hello. I am facing an error which is Toast is placed out of position. Let's say I use Toast multiple times while I use an app. A toast is placed on the right position at the first time. However, if I call that again, this is placed under the position where the previous Toast is set and this behavior is repeated every time I call Toast.
-
1st time
-
2nd times
-
3rd times
After a toast disappears, it still leaves on the screen according to React Native Debugger like that image.
I couldn't find solutions in issues and Discord. If it is not a bug, I would like you to tell me some solution. Thank you.
Hi @Toshiyuki023Hori, Thank you for reaching out to us. We will look into this issue.
@Krithikj20 Sure. Thank you.
I forgot to tell you my environtment.
Here is a part of my package.json
"expo": "~44.0.0",
"native-base": "^3.3.11",
"react": "17.0.1",
"react-dom": "17.0.1",
"react-native": "0.64.3",
"react-native-maps": "0.29.4",
"tailwind-rn": "^4.2.0",
"tailwindcss": "^3.0.23",
same issue 👀
same issue in v3.3.7
Hi, I'm facing the same issue if the toasts are displayed sequently within < 1s (the first one disappeared but the next one stayed at the lower position, not moved up) native-base: 3.4.9 react-native: 0.68.2
Same issue here!! Any workaround on this??
+1
+1
my workaround for this is using Toast component instead of useToast
I'm thinking we'll have to use react-native-toast-message
instead for now.
This is still an on going issue.
Each time a toast is called, it is added to the component tree, but not all of it is removed, there seems to be some cruft left behind.
+1
I was able to fix this by manually closing all toasts after a time-out. Specifically
Toast.show({
placement: 'top',
render: () => <View bg="white" borderColor={"light.300"} borderWidth={"1"} w="95%" flex={1} rounded={"md"} p="3">
<Text>Test</Text>
</View>
})
setTimeout(() => toast.closeAll(), 5000)
Pay attention to the fact that I'm using Toast
not toast
. It will not work with the useToast()
hook and requires the the global variable instead. The version of toast used to call closeAll
can either be the useToast()
or global variant. The important thing is that you don't change it as it will leave an artifact that pushes the view down.
Also if you have already instantiated any bad toasts with the useToast()
version, you'll need to kill the app and re-open as the bad artifacts will already be added to the view
toast.isActive(id)
also comes back as true
forever after displaying it once.
I've also found that Toast.show
was causing crashes when called in fairly rapid succession.
Error still there in version "native-base": "3.4.0",
+1
+1
This library is a mess. Still an issue.
if you want to use toast.isActive(),you must set the placement: 'bottom',maybe this is an bug