Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

React Native Stack Navigation Modal Not Sliding

I'm new to React Native and I'm trying to navigate to one of my screens. I would like the screen to open as a modal. Apparently, you should apply the screenOptions={{ presentation: 'modal'}} to the Stack.Navigator. The screen is opening but not as a modal i.e it does not slide from bottom to top and does not function like a modal does. It just opens the default way. I've added my Navigator code below. I'm also nesting navigators? Could the nesting be the issue?

import React from 'react';
import { createNativeStackNavigator } from "@react-navigation/native-stack";

import ListingsScreen from '../screens/ListingsScreen';
import ListingDetailsScreen from '../screens/ListingDetailsScreen';

const Stack = createNativeStackNavigator()
const FeedNavigator = () => (
  <Stack.Navigator screenOptions={{ presentation: 'modal' }}>
    <Stack.Screen name="Listings" component={ListingsScreen} />
    <Stack.Screen name="Listing Details" component={ListingDetailsScreen} options={{ headerShown: false }} />
  </Stack.Navigator>
)

export default FeedNavigator;
like image 768
Ashraf Lobo Avatar asked May 17 '26 19:05

Ashraf Lobo


2 Answers

I figured out my problem.

I was using

import { createNativeStackNavigator } from "@react-navigation/native-stack";

I changed it to

import { createStackNavigator } from "@react-navigation/stack";

I don't know why it worked for createStackNavigator and not createNativeStackNavigator.

I'm not going to question it, too much to do, too little time

like image 101
Ashraf Lobo Avatar answered May 23 '26 19:05

Ashraf Lobo


this worked for me:

import { TransitionPresets } from '@react-navigation/stack';

// ...

<Stack.Navigator
  screenOptions={({ route, navigation }) => ({
    gestureEnabled: true,
    ...TransitionPresets.ModalPresentationIOS,
  })}
>
  <Stack.Screen name="Home" component={Home} />
  <Stack.Screen name="Profile" component={Profile} />
</Stack.Navigator>;
like image 26
Rojin Gharooni Avatar answered May 23 '26 19:05

Rojin Gharooni



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!