在stackNavigator中打开单个屏幕作为模态,其他作为卡片打开

问题描述 投票:0回答:1

我在我的react-navigation应用程序中使用react-native v3。

我有一个不同屏幕的stackNavigator

const CarsListStack = createStackNavigator({
  CarsListScreen: { screen: CarsListScreen },
  FiltersScreen: { screen: FiltersScreen },
  CardDetailScreen: { screen: CardDetailScreen },
},
{
  initialRouteName: 'CarsListScreen',
});

我知道在mode: 'modal选项中添加:createStackNavigator会使堆栈中的所有屏幕从底部打开。

我怎样才能让CardDetailScreen从底部打开并像往常一样打开堆叠中的其他屏幕?

react-native react-navigation
1个回答
0
投票

你需要为CardDetailScreen制作另一个堆栈,所以;

    // Main Card-Style Navigator

      const MainStack = createStackNavigator({
      CarsListScreen: { screen: CarListScreen },
      FiltersScreen: { screen: FiltersScreen },
      CardDetailScreen: { screen: ModalStack },
    },
     { 
       initialRouteName:'CarsListScreen' 
   }); 

    // Modal-Style Navigator

     const ModalStack = StackNavigator({
      Home: { screen: MainStack },
      Modal: { screen: CarDetailScreen },
    }, {
      mode: 'modal',
     headerMode:'none',
    });
© www.soinside.com 2019 - 2024. All rights reserved.