Skip to content

Toast appears on previous screen when presentation: 'modal', in react navigation #576

Description

@chiefchief

Describe the bug
I'm using react navigation, here is my usage of ToastProvider

const App = () => {
  return (
    <ToastProvider>
      <StatusBar backgroundColor={'transparent'} translucent={true} barStyle={'dark-content'} />
      <Navigator
        ref={navigationRef}
        onReady={() => {
          Bootsplash.hide({ fade: true });
          navigationIntegration.registerNavigationContainer(navigationRef);
        }}
      />
    </ToastProvider>
  );
};

my ToastProvider:

import React, { memo, PropsWithChildren } from 'react';
import { useSafeAreaInsets } from 'react-native-safe-area-context';
import Toast, { ToastConfig } from 'react-native-toast-message';

import { ErrorToast } from './ErrorToast/ErrorToast';

export const toastConfig: ToastConfig = {
  error: ErrorToast,
};

export const ToastProvider = memo<PropsWithChildren>(({ children }) => {
  const { top } = useSafeAreaInsets();

  return (
    <>
      {children}
      <Toast config={toastConfig} topOffset={top} autoHide={false} />
    </>
  );
});

inside react navigation i have a screen which has option -

presentation: 'modal',

From the first screen i'm navigating to the second screen (with option: presentation: 'modal'), on the second screen, i call Toast.show, but the toast actually appears on previous screen and not visible on second

adding layout helps a little:

        SecondScreen: {
          screen: SecondScreen,
          options: ({ navigation }) => ({
            headerTransparent: true,
            title: 'SecondScreen',
            presentation: 'modal',
          }),
          layout: modalLayout,
        },
export const modalLayout = ({ children }: { children: React.ReactElement }) => {
  return (
    <>
      {children}
      <Toast config={toastConfig} topOffset={16} autoHide={false} />
    </>
  );
};

but the toast behind the header (title shows above the toast)

Expected behavior
Toast should appear above the current screen

Screenshots
If applicable, add screenshots to help explain your problem.

Code sample
To help debugging, please add a code sample that reproduces the issue.

Environment (please complete the following information):

  • OS: iOS
  • "react-native-toast-message": "^2.3.0"
  • "react-native": "0.80.0"
  • "@react-navigation/native": "^7.1.14"
  • "@react-navigation/native-stack": "^7.3.21"

Additional context
Add any other context about the problem here.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions