标签: react-navigation-drawer

material-ui Drawer - findDOMNode is deprecated in StrictMode

I have a simple ReactJS app based on hooks (no classes) using StrictMode.

I am using React version 16.13.1 and Material-UI version 4.9.10.

In the Appbar I am using Drawer.

    <div className={classes.root}>
        <AppBar position="static">
            <Toolbar>
                <IconButton
                    edge="start"
                    className={classes.menuButton}
                    color="inherit"
                    aria-label="menu"
                    onClick={handleDrawerOpen}>
                    <MenuIcon />
                </IconButton>
                <Typography variant="h6" className={classes.title}>
                    Online Information
                </Typography>
            </Toolbar>
        </AppBar>
        <Drawer
            variant="persistent"
            anchor="left"
            open={open}
        ></Drawer>
    </div>
Run Code Online (Sandbox Code Playgroud)

I notice that when I open the Drawer, I get the following warning.

Warning: findDOMNode is deprecated in StrictMode. findDOMNode was passed …
Run Code Online (Sandbox Code Playgroud)

strict-mode reactjs deprecation-warning material-ui react-navigation-drawer

123
推荐指数
4
解决办法
6万
查看次数

React Navigation 6 隐藏抽屉项目

如何隐藏屏幕,使其不显示为 @react-navigation/drawer 版本 6 抽屉中的项目。

在 React Navigation 5 中,它是通过创建像这样的自定义抽屉内容来实现的

const CustomDrawerContent = (props: DrawerContentComponentProps) => {
  const { state, ...rest } = props;
  const includeNames = ["ScreenOne", "ScreenTwo"];
  const newState = { ...state }; //copy from state before applying any filter. do not change original state
  newState.routes = newState.routes.filter(
    (item) => includeNames.indexOf(item.name) !== -1
  );
  return (
    <DrawerContentScrollView {...props}>
      <DrawerItemList state={newState} {...rest} />
    </DrawerContentScrollView>
  );
};
Run Code Online (Sandbox Code Playgroud)

正如另一个答案中所述。TypeError: Cannot read property 'key' of undefined我刚刚升级到react-navigation 6,使用这种技术,当我尝试导航这些隐藏屏幕之一时,我收到错误。谁能帮我吗?

更新 - …

reactjs react-navigation react-navigation-drawer

19
推荐指数
1
解决办法
3114
查看次数

React(本机)导航中的“jumpTo”与“navigate”

使用 React Navigation,不同类型的导航器具有不同的操作(以编程方式)在屏幕之间导航。

例如,与常见的“导航”操作相比,StackNavigator 中的“弹出”、“推送”等具有详细记录的(不同)行为。

但对于 Drawer 和 TabNavigators,我们可以选择使用“jumpTo”。我无法理解“jumpTo”与“navigate”有何不同,以及何时使用什么?

文档只是说

JumpTo 操作可用于跳转到抽屉式导航器中的现有路线。

与“导航”相比,这有什么好处?

...允许导航到特定路线

更具体地说,使用 DrawerNavigation,这是如何实现的

props.navigation.navigate('Create meeting')
Run Code Online (Sandbox Code Playgroud)

...工作方式与此不同

props.navigation.jumpTo('Create meeting');
Run Code Online (Sandbox Code Playgroud)

...我什么时候应该使用哪个?

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

15
推荐指数
1
解决办法
2150
查看次数

如何解决安装版本 6 时的 React Native 导航错误

我刚刚安装了 React 导航版本 6,收到以下错误

尝试在空对象引用上调用接口方法 boolean com.swmansion.reanimated.layoutReanimation.NativeMethodsHolder.isLayoutAnimationEnabled()在此输入图像描述

下面是我的代码

/**
 * Sample React Native App
 * https://github.com/facebook/react-native
 *
 * @format
 * @flow strict-local
 */
import 'react-native-gesture-handler';
import React from 'react';

import {
  SafeAreaView,
  ScrollView,
  StatusBar,
  StyleSheet,
  Text,
  useColorScheme,
  View,

} from 'react-native';

import { NavigationContainer } from '@react-navigation/native';
import { createStackNavigator } from '@react-navigation/stack';

import Upload from './Screens/Upload';
import Display from './Screens/Display';

const Stack = createStackNavigator()

function App() {

  return (
    <NavigationContainer>
      <Stack.Navigator>
        <Stack.Screen
        name='Screen_A'
        component={Upload}
        >


        </Stack.Screen>
        <Stack.Screen …
Run Code Online (Sandbox Code Playgroud)

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

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

React Navigation 5 隐藏抽屉项目

我试图隐藏在抽屉导航器中按下我的一个路线的能力,因为它是另一个导航器和应用程序中的默认位置。我希望抽屉仅用于导航到不适合其他地方的用户流程的无关路线。在 React Navigation 5 之前,我可以通过简单地设置drawerLabel: () => null. 但是现在有了变化,我无法弄清楚如何以相同的方式隐藏它。

以下是我当前的导航器代码:

const DrawerNavigator = () => {
    const dispatch = useDispatch();
    return (
    <MainDrawerNavigator.Navigator 
        drawerContent={props => customDrawerContent(props, dispatch)}
        drawerStyle={drawerStyle}
    >
        <MainDrawerNavigator.Screen 
            name="DrawerNav"
            component={MainTabNavigator}
            options={{
                drawerLabel: () => null,
                title: null,
                drawerIcon: () => null
            }}
        />

        <MainDrawerNavigator.Screen
            name="FAQNav"
            component={FAQStackNavigator}
            options={
                { 
                    drawerLabel: "FAQ", 
                    drawerIcon: ({tintColor}) => <EvilIcons name={'question'} size={30} color={tintColor} />
                }
            }
        />
    </MainDrawerNavigator.Navigator>
    )
}

const customDrawerContent = (props, dispatch) => {
    console.log(props.descriptors)
    return (
        <View style={{flex: …
Run Code Online (Sandbox Code Playgroud)

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

12
推荐指数
4
解决办法
2万
查看次数

将图标添加到抽屉 react-navigation v5

我正在尝试向我的 react-navigation 抽屉中的每个屏幕添加一个图标,但该图标没有出现。

这是我的代码:

function Drawer() {
  return (
      <Drawer.Navigator 
       drawerStyle={styles.drawer}
        initialRouteName="Home" 
        drawerPosition='right'
        drawerContentOptions={{
        activeTintColor: 'white',
        inactiveTintColor: 'white',
        itemStyle: { alignItems:'flex-end' },
       }}>
        <Drawer.Screen name="AppTab" component={AppTab1} options={{ headerStyleInterpolator: forFade ,title:"home" ,icon:<Image source={require('./images/icons/plumbing-b.png')} style={styles.drawerActive}/> }} />
        <Drawer.Screen name="News" component={NotificationsScreen} options={{ headerStyleInterpolator: forFade ,title:"new items" icon:<Image source={require('./images/icons/plumbing-b.png')} style={styles.drawerActive}/> }} />
        
      </Drawer.Navigator>
    
  );
}


export function App() {
  return (
    <NavigationContainer>
      <Stack.Navigator>
        <Stack.Screen
          options={{
            headerTitleAlign:"center",
            headerRight: ({}) => <HeaderRight />,
            headerLeft: ({}) => <Search />
          }}
          component={Drawer}
          name="Drawer"
        />
        <Stack.Screen name="Product" component={Product} options={{title:"product"}} …
Run Code Online (Sandbox Code Playgroud)

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

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

标题未显示在 react-navigation-drawer React-Native 中

我正在react-navigation-drawer从 React 导航库实现。但面临与标题相关的问题。标题栏未显示在任何屏幕中。

这是我的 App.js

import React from "react";
import { StyleSheet, ScrollView, View } from "react-native";
//import DrawerNavigator from "./navigation/DrawerNavigator";
import { Platform, Dimensions } from "react-native";
import { createAppContainer } from "react-navigation";
import { createDrawerNavigator } from "react-navigation-drawer";
import Home from "./components/home";
import Contact from "./components/contact";

const WIDTH = Dimensions.get("window").width;
const RouteConfigs = {
  Home: {
    screen: Home
  },
  Contact: {
    screen: Contact
  }
};
const DrawerNavigatorConfig = {
  drawerWidth: WIDTH * 0.75,
  drawerType: "both",
  initialRouteName: …
Run Code Online (Sandbox Code Playgroud)

react-native react-navigation react-navigation-drawer

9
推荐指数
3
解决办法
6644
查看次数

React Navigation(原生)V5:深色主题问题。抽屉导航器切换按钮与背景没有对比。包括屏幕截图

我正在像这样设置导航容器的主题

import {
  NavigationContainer,
  DefaultTheme,
  DarkTheme,
} from "@react-navigation/native";

export default function Navigation() {
  const colorScheme = useColorScheme();
  return (
    <NavigationContainer
      linking={LinkingConfiguration}
      theme={colorScheme === "dark" ? DarkTheme : DefaultTheme}
    >
      <RootNavigator />
    </NavigationContainer>
  );
}
Run Code Online (Sandbox Code Playgroud)

我有一个堆栈导航器,在堆栈导航器内我有一个抽屉式导航器,如下所示:

// Root Navigator
export default function RootNavigator() {
  return (
    <Stack.Navigator id="root-navigation-navigator" initialRouteName={initialRouteName}>
      <Stack.Screen
        name="Root"
        component={DrawerNavigator}
        options={{
          headerShown: false,
        }}
      />
      {/* Other Screens */}
    </Stack.Navigator>
  );
}
Run Code Online (Sandbox Code Playgroud)
// Drawer Navigator
export default function DrawerNavigator(props) {
  return (
    <Drawer.Navigator
      initialRouteName="UserSettings"
      drawerContent={(props) => <CustomDrawerContent {...props} …
Run Code Online (Sandbox Code Playgroud)

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

8
推荐指数
0
解决办法
847
查看次数

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
查看次数

反应导航-TabNavigator-&gt; StackNavigator中的Header Menu图标的DrawerNavigator

我想在所有屏幕中全局显示HeaderLeft菜单图标。当我单击菜单图标时,我需要显示抽屉菜单。我使用“ OpenDrawer”,“ CloseDrawer”方法打开/关闭抽屉菜单。

但是我总是在“ undefined is not a function (evaluating 'props.navigation.openDrawer()')"。我也尝试了以下

props.navigation.dispatch(DrawerActions.openDrawer())
props.navigation.navigate(openDrawer())
Run Code Online (Sandbox Code Playgroud)

但以上方法均无效。这是我的部分代码

const MenuButton = (props) => {
  return (
    <View>
      <TouchableOpacity onPress={() => { props.navigation.dispatch(DrawerActions.openDrawer())} }>
        <Text>Menu</Text>
      </TouchableOpacity>
    </View>
  )
};

const MyDrawerNavigator = createDrawerNavigator(
  {
    Wishist: {
      screen: wishlist
    },
  },
  {
    contentComponent: SideMenuScreen,
    drawerWidth: 200,
  }
);

const AppNavigator = createBottomTabNavigator({
  Home: {
    screen: createStackNavigator({
      Home: {
        screen: Home
      },
      Contact: {
        screen: Contact
      }
    },
    {
      defaultNavigationOptions: ({ navigation }) => ({
        headerStyle: …
Run Code Online (Sandbox Code Playgroud)

react-native react-navigation react-navigation-drawer

7
推荐指数
1
解决办法
552
查看次数