-
Notifications
You must be signed in to change notification settings - Fork 2.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Bug] Toast is not working within a Modal #985
Comments
@JLLLinn Check the latest of NativeBase i.e, v2.2.0 |
Was this verified that it was fixed? I think I'm experiencing it as well. My issue is that the Modal is covering the Toast so it isn't visible. I'm on RN 0.46.4 and native base 2.2.1 and using the ios emulator. Thanks! |
Same problem. I'm on RN 0.46.1 and native base 2.2.1 and using the ios emulator. |
Exactly the same problem using RN 0.47 and NativeBase 2.2.1. |
The Toast still appears behind the Modal (from React Native): the code is basically this: import React from 'react';
import {
Modal,
Toast,
Text,
View,
} from 'react-native';
export default class LoginScreen extends React.Component<Props, State> {
state = {
modalVisible: false,
}
onResetPassword() {
Toast.show({
text: message,
duration: 2000,
position: "top",
textStyle: { textAlign: "center" },
});
}
render() {
return (
<View>
<Modal
animationType="slide"
transparent={false}
visible={this.state.modalVisible}
>
<View>...</View>
</Modal>
</View>
)
}
} Any suggestions? I see there's something called zIndex as Layout Props - React Native Using:
Can something be done to the ToastContainer.js? |
@gianpaj Looks like you are using React-Native-Seed boilerplate. Nice! |
I just want to add that I’m having this issue too with v 2.3.3 |
FYI: this issue happens both on Android and iOS |
Still present on 2.3.5 |
I think I'm just going to use the My bad. Ant-Design Toast doesn't work. It also appears under the react-native Modal |
@gianpaj I'm also using antd-mobile for the datepicker. Perhaps I should take a look at their toast implementation too. |
@gianpaj What was the purpose of sharing graphs for commit-activity? |
Any hotfix for now with v2.3.10 ? |
Any chance this will be fixed anytime soon? |
Сталкивался с этой проблемой недавно, решил следующим способом. Просто добавляем в Modal элемент Root, а в него весь контент который вам нужен P.S. на английский переводить лень, главное ведь код translation : Faced this problem recently, I decided in the following way. Just add the Root element to the Modal, and all the content you need is in it
|
@Zeratyll Hey! It doesn't work for me at all, the toast still appears behind the Modal. |
@doreentseng Tried @Zeratyll 's solution of putting |
checked this issue after merging PR #1700. Placing Root inside a modal component as suggested by @Zeratyll #985 (comment) is working after merging. See attached Gif. Sample code
Gif Edit : As @gianpaj pointed out this may not be a viable option. Please see the below comment. |
This is not ideal or neither practical. The state of Modal(s) should not be at the Root of an application. It should be where the Modal needs to appear, i.e. inside a screen/component/container. If we had to do the way you suggest, the state of the Modal needs to pass down all the way to the Component in need (via props or in order ways). I have to say this is not a viable option for any decent size application. I don't know at the moment how to solve this, but pretty sure that's not it. Happy to be corrected if I'm wrong. |
@gianpaj updated my comment. |
Also having this problem. The Root workaround does work but also has an unwanted side-effect that windowed (non-fullscreen) modals no longer appear vertically centered, and no JSX adjustments appear to help. |
The above Root fix didn't work for me as I'd like it to, as it completely ruins the vertical centring of the Toast |
My workaround for modals. scene.js
ModalComponent.js
mypathto/Toast.js
|
Adding a blank Toast |
Neither |
Since I'm using the following workaround for version <RNModal
isVisible={modalVisible}
deviceWidth={deviceWidth}
deviceHeight={deviceHeight}
coverScreen={true}
style={styles.modal}
>
<NativeBaseProvider>
<View style={styles.modalHeader}>
<TouchableOpacity
style={{ marginTop: 48 }}
>
<Icon
name='close'
as={MaterialCommunityIcons}
onPress={onClose}
size={12}
style={{
right: 16,
alignSelf: 'flex-end',
}}
/>
</TouchableOpacity>
<View style={styles.modalBody}>
{children}
</View>
</View>
</NativeBaseProvider>
</RNModal> |
I'm reopening this issue, and we'll keep it on high priority. |
@md-rehman I would also love this feature to be back, ideally a separate API to configure Toast's root element. Have you guys started working on it already? I would love to help or take care of that issue, so that we can have it back on our project 💪🏻 |
Could you provide example to customize default theme of native base modal, action sheet and other overlay component so, toast will be appeared on the top of it |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
I have the same issue. The toast doesn’t appear on the modal. No solutions yet. |
+1 |
is there any solution now? |
Hi @zzyjiaxinmomo @iooi @Oct4Pie, Can you provide small snack example ? |
Hello, @Viraj-10. Here it is: import React from "react";
import {
Text,
HStack,
Center,
Switch,
useColorMode,
NativeBaseProvider,
extendTheme,
VStack,
Modal,
Input,
FormControl,
Button,
useToast,
} from "native-base";
const config = {
useSystemColorMode: false,
initialColorMode: "dark",
};
export const theme = extendTheme({ config });
export default function App() {
const [show, setShow] = React.useState(false);
const toast = useToast();
return (
<NativeBaseProvider>
<Center
_dark={{ bg: "blueGray.900" }}
_light={{ bg: "blueGray.50" }}
px={4}
flex={1}
>
<VStack space='3' >
<Modal onClose={() => setShow(false)} isOpen={show}>
<Modal.Content>
<Modal.CloseButton />
<Modal.Header>Sign In</Modal.Header>
<Modal.Body>
Please enter your credentials to proceed
<FormControl mt={{
'base': '3',
'lg': '4',
'2xl': '5',
}}>
<FormControl.Label>Email</FormControl.Label>
<Input />
</FormControl>
<FormControl mt={{
'base': '3',
'lg': '4',
'2xl': '5',
}}>
<FormControl.Label>Password</FormControl.Label>
<Input />
</FormControl>
</Modal.Body>
<Modal.Footer>
<Button onPress={() => {
toast.show({
// variant: "solid",
description: "You are signed in!",
})
// setShow(false);
}}>
Sign In
</Button>
</Modal.Footer>
</Modal.Content>
</Modal>
<VStack space={8} alignItems="center">
<Button w="104" onPress={() => {
setShow(!show);
}}>
Sign In Modal
</Button>
</VStack>
<ToggleDarkMode />
</VStack>
<SignInModal />
</Center>
</NativeBaseProvider>
);
}
const SignInModal = () => {
const [show, setShow] = React.useState(false);
const toast = useToast();
return <VStack space='3' >
<Modal onClose={() => setShow(false)} isOpen={show}>
<Modal.Content>
<Modal.CloseButton />
<Modal.Header>Sign In</Modal.Header>
<Modal.Body>
Please enter your credentials to proceed
<FormControl mt={{
'base': '3',
'lg': '4',
'2xl': '5',
}}>
<FormControl.Label>Email</FormControl.Label>
<Input />
</FormControl>
<FormControl mt={{
'base': '3',
'lg': '4',
'2xl': '5',
}}>
<FormControl.Label>Password</FormControl.Label>
<Input />
</FormControl>
</Modal.Body>
<Modal.Footer>
<Button onPress={() => {
toast.show({
variant: "solid",
description: "You are signed in!",
})
// setShow(false);
}}>
Sign In
</Button>
</Modal.Footer>
</Modal.Content>
</Modal>
<VStack space={8} alignItems="center">
<Button onPress={() => {
setShow(!show);
}}>
Sign In Modal (component)
</Button>
</VStack>
</VStack>;
}
function ToggleDarkMode() {
const { colorMode, toggleColorMode } = useColorMode();
return (
<HStack space={2} alignItems="center">
<Text>Dark</Text>
<Switch
isChecked={colorMode === "light"}
onToggle={toggleColorMode}
aria-label={
colorMode === "light" ? "switch to dark mode" : "switch to light mode"
}
/>
<Text>Light</Text>
</HStack>
);
} As you can see, |
Hi All, Let me explain what's going on internally. |
Is there any solution to this yet? |
that solution worked in my case |
I've been struggling with this for a while and found a pretty acceptable solution! 🥳
And the
const theme = extendTheme({
{...}
components: {
Toast: {
defaultProps: {
_overlay: { style: { zIndex: 999 } }
}
}
}
}); then, by passing a high zIndex, the toast is displayed above the Modal! 🎉 note: using |
"useRNModalOnAndroid: false", default for component "Modal" helped
|
your initial problem was in android or iOS? |
calintamas/react-native-toast-message it is very simple and easy to use. it's 2023, any updates to fix this bug? |
In short, no...they slowly (and quietly) moved on to another project - https://ui.gluestack.io/ |
After trying everything here and with no luck, I still kept struggling with this for a long time, and after checking how Toast works multiple times I've come across a workaround that finally worked for me. So under the hood it is using Here's a sample code: Container.tsx import { useState } from "react";
// components
import { Button, Center, VStack, useToast } from "native-base";
import ModalToast from "./ModalToast";
const Container = () => {
const toast = useToast();
const [isOpen, setIsOpen] = useState(false);
const closeModal = () => {
setIsOpen(false);
};
const openModal = () => {
setIsOpen(true);
};
const showToast = () => {
toast.show({ title: "A Regular Toast In App" });
};
return (
<Center flex={1}>
<VStack space={5}>
<Button onPress={openModal}>Open Modal</Button>
<Button onPress={showToast}>Show Outer Toast</Button>
</VStack>
<ModalToast isOpen={isOpen} onClose={closeModal} />
</Center>
);
};
export default Container; ModalToast.tsx import {
Button,
Center,
HStack,
Modal,
ToastProvider,
useToast,
} from "native-base";
const ModalContent = ({ onClose }: { onClose: () => void }) => {
const toast = useToast();
const showToast = () => {
toast.show({ title: "A Toast over the modal" });
};
return (
<Center flex={1}>
<HStack space={4}>
<Button onPress={showToast}>Show Toast</Button>
<Button onPress={onClose}>Close Modal</Button>
</HStack>
</Center>
);
};
interface ModalToastProps {
isOpen: boolean;
onClose: () => void;
}
const ModalToast = ({ isOpen, onClose }: ModalToastProps) => (
<Modal
isOpen={isOpen}
animationPreset="slide"
bg="gray.200"
onClose={onClose}
safeAreaBottom
>
<ToastProvider>
<ModalContent onClose={onClose} />
</ToastProvider>
</Modal>
);
export default ModalToast; The only issue is that the App toast still stays under the modal, as the one inside the modal is another provider so it displays whole other Toast. Screen.Recording.2023-10-16.at.13.35.34.movUsing both Hope this will be of help. |
A workaround is to set RNModal to false <Modal
_overlay={{
useRNModal: false,
useRNModalOnAndroid: false,
}}
> |
I mean, realistically, NativeBase is abandoned. I've just moved all Toast to react-native-toast-message. Bit by bit, I'm slowly removing native-base from my project. I'll never go to gluestack if this how they handle projects. They'll abandon gluestack too as soon as a new shiny thing coming down the line. |
Can we get the refund? |
I have my own separate context provider for toasters, which wraps the parts of my application I need. And as I see, everything now works as it should on iOS devices. And for Android, the setup that astaninivan1 suggested helped me. |
react-native, react and native-base version
RN: 0.45.1
React:16.0.0-alpha.12
native-base: 2.1.5
Expected behaviour
Toast to be shown in react native Modal
Actual behaviour
The toast is not shown in react native Modal
Steps to reproduce (code snippet or screenshot)
Do Toast.show() in a Modal
Is the bug present in both ios and android or in any one of them?
No that I know of. This was working with RN on 0.44 and native-base on a lower version (I can't remember exactly which one, either 2.1.4 or 2.1.3)
The text was updated successfully, but these errors were encountered: