首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >反应导航远离TabNavigator导航

反应导航远离TabNavigator导航
EN

Stack Overflow用户
提问于 2018-11-01 22:02:00
回答 2查看 2.5K关注 0票数 2

我正在使用React导航作为我的for本机应用程序。

我的根堆栈如下:

代码语言:javascript
复制
const AuthStack = createStackNavigator({
  Authentication: {
    screen: Authentication,
  },
  Login: {
    screen: Login,
  },
  Register: {
    screen: Register,
  },
});

const AppStack = createStackNavigator({
  Main: {
    screen: Main,
  },
});

export const RootNav = createSwitchNavigator(
  {
    AuthLoading: {
      screen: AuthLoadingScreen,
    },
    App: {
      screen: AppStack,
    },
    Auth: {
      screen: AuthStack,
    },
  },
  {
    initialRouteName: 'AuthLoading',
  }
);

Main是一个包含3个堆栈导航器的选项卡导航器,如下所示:

代码语言:javascript
复制
const FeedStack = createStackNavigator({
  Feed: {
    screen: Feed,
  },
});

const ExploreStack = createStackNavigator({
  Explore: {
    screen: Explore,
  },
});

const AccountStack = createStackNavigator({
  Account: {
    screen: Account,
  },
});

const NavBar = createBottomTabNavigator(
  {
    Feed: {
      screen: FeedStack,
    },
    Explore: {
      screen: ExploreStack,
    },
    Account: {
      screen: AccountStack,
    },
  }
}

我的问题是账户栈。在帐户屏幕下找到的注销按钮,但是当我调用this.props.navigation.navigate('Auth')时,什么都不会发生。

我试过使用this.props.navigation.reset()this.props.navigation.dispatch(),但它们都不起作用。

有人知道在用户注销时如何切换回身份验证堆栈吗?

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2019-05-23 18:18:20

我认为我的情况是相似的,最近有一个被记录在代码中的特性,但是这个函数并没有被导出,而这个功能在5天前才被修复--它似乎对我有用。

进口SwitchActions..。

代码语言:javascript
复制
import { SwitchActions } from 'react-navigation;

...and使用jumpTo方法:

代码语言:javascript
复制
this.props.navigation.dispatch(SwitchActions.jumpTo({ routeName: 'Auth' }));

我在嵌套在堆栈导航器中的组件中这样做,以便回到父开关导航器中的前一个屏幕,所以它可能对您有用。

参考:https://reactnavigation.org/docs/en/switch-actions.html#jumpto

票数 1
EN

Stack Overflow用户

发布于 2021-10-04 12:19:26

我的情况类似,当我试图直接从主屏幕上的嵌套导航导航时,抽屉也是如此。按下“主页”按钮后,它将停留在同一个屏幕上,我如何在这里实现这一点?

代码语言:javascript
复制
import bottomnavigation from 'bottomnavigation_file' //bottomtap file code in drawer index file 

    <Drawer.Navigator 
    drawerContent={props => <DrawerContain {...props} />} //DrawerContain 
    different file
       drawerContentOptions={
        {
        // activeTintColor: "#e91e63",
      // itemStyle: { marginVertical: 5 },
    }
    }>
     <Drawer.Screen name="Home" component={bottomnavigation} />

  <Drawer.Navigator >

 //DrawerContain file
 function DrawerContain (){
  const [homenavigation, sethomenavigation] = useState(false)

   const homeNavigation =  (homenavigation)=>{
    sethomenavigation(!homenavigation)
     console.log('navigation home state drawer fun????-------',!homenavigation)
    dispatch(bottom_navigation(!homenavigation))
  // props.navigation.jumpTo('Home')
      homenavigation ? props.navigation.jumpTo('Home') : 
 props.navigation.jumpTo('Home')
  }
  return(
  <DrawerContentScrollView {...props}>
      {/* <DrawerItemList {...props} /> */}
    <Drawer.Section>
    
    
      <Drawer.Item
        icon={home}
        label="Home"
        onPress={() => homeNavigation(homenavigation)}
      />
 </Drawer.Section>
  </DrawerContentScrollView>
 )
  }

 and finally in stack navigatore file where all navigation defined
// StackNavigatore file
 import Home from '../bottomNavigation/index'; //bottom tap define here
 import Home2 from '../bottomNavigation/index1'; // bottom tap duplicate file same

function StackNavigatore({ navigation }) {
  const Bottom_navigation = useSelector(state => state.user.bottom_navigation);

  return <>
     {!Bottom_navigation ? <Stack.Screen
      name="Manijment"
      component={Home} //bottom navigation file
      options={{
        title: '',
        headerShown: false,
      }}
    /> :
    <Stack.Screen
      name="Home2"
      component={Home2 } // duplicate file of bottom navigation render 
  conditionally 
      options={{
        title: '',
        headerShown: false,
      }}
    />}
  </>
 }
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/53109996

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档