标签: react-navigation-drawer

withNavigation只能用于导航器的视图层次结构

我收到错误:

不变违规:withNavigation只能用于导航器的视图层次结构.包装的组件无法从道具或上下文访问导航

我不知道为什么,因为我withNavigation在我的应用程序的其他组件中使用它,它的工作原理.我认为它所处理的组件与导致错误的组件没有区别.

码:

组件:

const mapStateToProps = (state: State): Object => ({
  alertModal: state.formControls.alertModal
})

const mapDispatchToProps = (dispatch: Dispatch<*>): Object => {
  return bindActionCreators(
    {
      updateAlertModalHeight: updateAlertModalHeight,
      updateAlertModalIsOpen: updateAlertModalIsOpen,
      updateHasYesNo: updateAlertModalHasYesNo
    },
    dispatch
  )
}

class AlertModalView extends Component<AlertModalProps, State> {
  render(): Node {
    return (
      <View style={alertModalStyle.container}>
        <PresentationalModal
          style={presentationalModalStyle}
          isOpen={this.props.alertModal.isOpen}
          title={this.props.alertModal.title}
          navigation={this.props.navigation}
          updateHasYesNo={this.props.updateHasYesNo}
          message={this.props.alertModal.message}
          updateAlertModalHeight={this.props.updateAlertModalHeight}
          viewHeight={this.props.alertModal.viewHeight}
          hasYesNo={this.props.alertModal.hasYesNo}
          yesClicked={this.props.alertModal.yesClicked}
          updateAlertModalIsOpen={this.props.updateAlertModalIsOpen}
        />
      </View>
    )
  }
}

// $FlowFixMe
const AlertModalViewComponent = connect(
  mapStateToProps,
  mapDispatchToProps
)(AlertModalView)

export default …
Run Code Online (Sandbox Code Playgroud)

react-native redux react-navigation react-navigation-drawer react-navigation-stack

7
推荐指数
2
解决办法
4376
查看次数

在 React 导航 v5 中突出显示当前活动抽屉菜单

我使用 react 导航版本创建了一个自定义抽屉导航器:5.X,但是当前活动选项卡没有在自定义抽屉菜单中突出显示。

  1. 我在 DrawerItem 元素中添加了“activeTintColor”,但它没有应用于活动项目。
  2. 我还在 drawerContentOptions 中添加了 activeTintColor。但也没有得到应用。他们有什么方法可以在自定义抽屉组件中使用这个常用选项吗?
  3. 我在 DrawerItem 元素中使用了“图标”,根据反应导航文档,我在其中添加了默认道具(颜色、焦点、大小)。因此,图标的颜色为“灰色”(可能是默认行为)。如何更改此默认道具值?
  4. “图标”中的默认道具“聚焦”也不起作用。所选选项卡的图标未更改。

请找到下面的代码图像。如果我犯了任何错误,请告诉我。

导航代码:

在此处输入图片说明

自定义抽屉组件:

在此处输入图片说明

当前活动标签:主页

在此处输入图片说明

react-native react-native-navigation react-navigation react-navigation-drawer react-navigation-v5

6
推荐指数
1
解决办法
5742
查看次数

抽屉式导航位于选项卡导航内但位于顶部(原生反应)

我正在编写一个类似于 Instagram 的 React Native 应用程序。我已经有一个包含 5 个项目的底部选项卡导航器,最后一个是配置文件选项卡。

在这个配置文件选项卡中,我想要一个抽屉导航器来管理配置文件设置,我希望这个抽屉只能在此选项卡中“可绘制”,而不是其他选项卡。但我也希望抽屉同时显示在选项卡导航器的顶部(就像 Instagram 的一样)。

我正在为此使用反应导航库。我的问题是:这可能吗?如果是,我该如何在我的代码上实现它?

谢谢

instagram reactjs react-native react-navigation react-navigation-drawer

6
推荐指数
1
解决办法
5491
查看次数

如何删除反应抽屉顶部的空间

我正在使用它,并且顶部有空白。任何人都可以向我提供详细信息以从顶部删除此空白。@react-navigation/抽屉在此输入图像描述

react-native react-navigation-drawer

6
推荐指数
2
解决办法
4387
查看次数

打开/关闭导航抽屉在本机反应中不起作用

在我的本机应用程序中,我使用 Drawer Navigator 创建了一个侧边菜单,当我通过滑动打开它时,它运行良好。但我想做的是点击按钮打开它。目前正在尝试做槽式导航道具,相关代码如下:

import { withNavigation } from 'react-navigation';

class HallsList extends React.Component {
  constructor(props){
    super(props);
    this.state = {
      isSideMenuOpen: false
    };
  } 

  renderTopView = () => {
      return(
        <View>
          <View style = {Styles.sideMenuButton}>
            <Button
              onPress = {()=> {
                if (this.state.isSideMenuOpen) {
                  {this.props.navigation.navigate('DrawerOpen')}
                }
                else {
                  {this.props.navigation.navigate('DrawerClose')}
                }
                this.setState({isSideMenuOpen: !this.state.isSideMenuOpen})
              }
            }
            title = {'Side Menu'}
            />
          </View> ..... 


export default withNavigation(HallsList);
Run Code Online (Sandbox Code Playgroud)

但是当我点击侧面菜单按钮时,它会被点击但之后没有任何反应。

react-native react-navigation side-menu react-navigation-drawer

5
推荐指数
1
解决办法
5791
查看次数

为什么路由对象有时有状态有时没有 - 在 react-navigation v5 中

开始:

<NavigationContainer>
      <Stack.Navigator>
        {
          isLoading ? <Stack.Screen name="AuthLoadingScreen" component={AuthLoadingScreen} />
          : (
          user ? (
            <Stack.Screen  name="AuthenticatedStack" component={AuthenticatedStack} options={{headerShown: false}} />
            ) : (
              <Stack.Screen  name="NotAuthenticatedStack" component={NotAuthenticatedStack} options={{headerShown: false}} />
            )
          )
        }
      </Stack.Navigator>
    </NavigationContainer>
Run Code Online (Sandbox Code Playgroud)

认证堆栈:

const AuthenticatedStack = () => {
  return (
    <Drawer.Navigator initialRouteName="MainStack" drawerContent={props => <SideBar {...props} />}>
        <Stack.Screen name="MainStack" component={MainStack} options={({route}) => ({
            headerShown: shouldHeaderBeShown(route),title: getHeaderTitle(route),
          })} />
      </Drawer.Navigator>
  );
};
Run Code Online (Sandbox Code Playgroud)

主堆栈包含带有选项卡导航器和其他导航器的主屏幕,我计划从侧面菜单按钮导航到这些导航器:

const MainStack = () => {
  return (
    <Stack.Navigator>
          <Stack.Screen name="main" component={MainTabNavigator} options={({route}) => …
Run Code Online (Sandbox Code Playgroud)

reactjs react-native react-navigation react-navigation-drawer react-navigation-stack

5
推荐指数
1
解决办法
1789
查看次数

如何将 StackNavigator 与 DrawerNavigator (ReactNavigation v5) 一起使用?我正在为每个屏幕使用类

PS:大多数 Youtube 视频或网络上的文章都没有使用 ReactNavigation v5,它们使用的是旧版本。当用户可以单击按钮导航到不同的屏幕(使用 StackNavigator)和 DrawerNavigator 以及在屏幕之间导航时,有人可以显示一个虚拟项目。屏幕必须有一个类和一个简单的文本,就是这样。谢谢!

react-native react-navigation expo react-navigation-drawer react-navigation-v5

5
推荐指数
1
解决办法
1643
查看次数

如何将反应本机抽屉标题图标(“汉堡包”)设置到右侧?

我将抽屉设置在右侧,但屏幕标题中的汉堡包图标保持默认左侧,是否有任何属性可以通过将位置更改为右侧?我知道应该通过配置自定义标头来完成,但我不想过度设计我的小项目。

navigation-drawer react-native react-native-navigation react-navigation-drawer

5
推荐指数
2
解决办法
1万
查看次数

React Navigation 6.x 按后退按钮将带您返回初始屏幕

我刚刚从 React Native 5.x 迁移到 6.x,现在我的导航堆栈出现了问题。当我在抽屉导航器深处导航几个屏幕,然后按 Android 上的后退按钮(没有尝试过 IOS)时,它会直接带我回到第一个屏幕。我的导航堆栈如下

 <NavigationContainer theme={MyTheme}>
        <Drawer.Navigator
          initialRouteName="NewsFeed"
          drawerContent={(props) => <SideNav {...props} />}
          screenOptions={{ headerShown: true, header: (options) => <TopNav options={options} /> }}
        >
          <Drawer.Screen name="NewsFeed" component={NewsFeedScreen} />
          <Drawer.Screen name="Post" component={PostScreen} />
          <Drawer.Screen name="Users" component={UsersScreen} />
          <Drawer.Screen name="User" component={UserScreen} />
    ...
        </Drawer.Navigator>
      </NavigationContainer> 
Run Code Online (Sandbox Code Playgroud)

我不确定问题是什么,也没有在任何地方找到任何答案。有人说将每个屏幕包裹在堆栈导航器中,其他人则说这是一个坏主意。

react-native react-navigation react-navigation-drawer react-navigation-stack

5
推荐指数
1
解决办法
1896
查看次数

React Native:无法解析模块。这些文件都不存在:

我是 React Native 的初学者,所以如果这是一个菜鸟问题,我深表歉意。我正在尝试使用这篇 React 导航文章这篇关于 React 登录示例来学习。第一篇文章将所有代码放在其中,App.js而第二篇文章则将代码放在单独的页面中,但稍微过时了。所以我的计划是集成这两个示例,使用第一篇文章的代码,但在不同的页面中,而不是将所有内容都放在App.js.

我的项目结构

我得到的错误:

None of these files exist:
  * Screen\drawerScreens\settingsScreen(.native|.android.js|.native.js|.js|.android.json|.native.json|.json|.android.ts|.native.ts|.ts|.android.tsx|.native.tsx|.tsx)
  * Screen\drawerScreens\settingsScreen\index(.native|.android.js|.native.js|.js|.android.json|.native.json|.json|.android.ts|.native.ts|.ts|.android.tsx|.native.tsx|.tsx)
   6 |
   7 | import HomeScreen from './Screen/drawerScreens/HomeScreen';
>  8 | import SettingsScreen from './Screen/drawerScreens/settingsScreen';
     |                             ^
Run Code Online (Sandbox Code Playgroud)

一些帮助和提示将不胜感激。如果需要更多信息,请告诉我。提前致谢。

javascript android react-native react-navigation-drawer

5
推荐指数
1
解决办法
3万
查看次数