【问题标题】:Drawer.Navigator Props not working on iOSDrawer.Navigator 道具在 iOS 上不起作用
【发布时间】:2021-10-29 01:27:59
【问题描述】:

我只是在上 React Native 的课程,并且无法使用 Drawer Navigator 获得任何道具。我在 Mac M1 上使用 iOS Simulator (14.3) 和 WebStorm IDE。我也在使用裸 React Native,而不是 Expo。

我在下面附上了我的 App.js 代码。正如您将看到的,它非常基本,但 initialRouteName 是唯一有效的道具。其他人都没有做他们应该做的事情。应用不会崩溃,道具只是不会按预期改变行为。

据我了解,iOS 支持这些道具。

有人可以帮忙吗?提前致谢。

import React from 'react';
import { StyleSheet } from "react-native";
import { NavigationContainer } from "@react-navigation/native";

// screen code held in separate .js files
import ScreenA from "./ScreenA";
import ScreenB from "./ScreenB";
import { createDrawerNavigator } from "@react-navigation/drawer";

const Drawer = createDrawerNavigator();

function App() {
  return(
    <NavigationContainer>
      <Drawer.Navigator
        
        initialRouteName={'Screen B'} // works fine
        drawerPosition={"right"} // not working
        drawerType={'front'} // not working
        edgeWidth={800} // not working
        hideStatusBar={true} // not working
        overlayColor={'#000000'} // not working
        drawerStyle={{
          backgroundColor: '#56cb6a' // not working
        }}
      >
        <Drawer.Screen name={'Screen A'}
                       component={ScreenA}
        />
        <Drawer.Screen name={'Screen B'}
                       component={ScreenB}
        />
      </Drawer.Navigator>
    </NavigationContainer>
  )
}

【问题讨论】:

    标签: javascript ios react-native navigation-drawer webstorm


    【解决方案1】:

    更新:我似乎使用 screenOptions 而不是 Drawer.Navigator 道具来完成这项工作。也许 Drawer.Navigator 道具自教程以来已被弃用?

    screenOptions={{
              drawerPosition: 'right',
              drawerType: 'front', 
              swipeEdgeWidth: 200, 
              headerShown: false, 
              overlayColor: '#00000050', 
              drawerStyle: {
                backgroundColor: '#dee0e8',
                width: 225
              },
              swipeEnabled: true, 
            }}
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2016-07-03
      • 2012-05-29
      • 2015-07-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-06-19
      相关资源
      最近更新 更多