简体   繁体   English

考虑到每个屏幕都有不同的 header,我如何修改抽屉导航器的 header 结构?

[英]How can i modify the header structure of Drawer Navigator, taking into account that each screen will have a different header?

 import * as React from "react";

import { SafeAreaView, useWindowDimensions } from "react-native";
import { createDrawerNavigator } from '@react-navigation/drawer';
import { NavigationContainer } from "@react-navigation/native";

import { RegistrationScreen } from './src/screens/Registration/RegistrationScreen';
import {LoginScreen} from './src/screens/Login/LoginScreen';
import {NewAnuncioScreen} from './src/screens/NewAnuncio/NewAnuncioScreen';
import { FeedScreen } from "./src/screens/Feed/FeedScreen";

import { FontAwesome, AntDesign, FontAwesome5, Entypo} from '@expo/vector-icons';


const Drawer = createDrawerNavigator()

const App = () => {

  const dimensions = useWindowDimensions();

  return (
    <SafeAreaView style={{ flex: 1 }}>
      <NavigationContainer>
        <Drawer.Navigator initialRouteName="Feed" screenOptions={{
          headerStyle: { backgroundColor: "#f2bc1b" , height: 55},
          drawerType: dimensions.width >= 821 ? 'permanent' : 'front',
          overlayColor: 'transparent',
          drawerContent:{CustomDrawerContent}
        }}>
          <Drawer.Screen name="Feed" component={FeedScreen}/>
          <Drawer.Screen name="Registration" component={RegistrationScreen} options={{ headerShown: false }} />
          <Drawer.Screen name="Login" component={LoginScreen} options={{ headerShown: false }} />
          {/* <Drawer.Screen name="Criar Anúncio" component={NewAnuncioScreen} /> */}
        </Drawer.Navigator>
      </NavigationContainer>
    </SafeAreaView>
  )

  
}

export default App;

**I want the header´s structures can vary like that: enter image description here enter image description here **我希望标题的结构可以像这样变化: enter image description here enter image description here

But i don´t know how to make this.但我不知道怎么做。 If someone help me i thanks.**如果有人帮助我,我感谢。**

You should pass the Drawer props to your custom drawer and retrieve the navigation index.您应该将 Drawer 道具传递给您的自定义抽屉并检索导航索引。

drawerContent = {(props) => <CustomDrawerContent {...props} />}

Then然后

const CustomDrawerContent = (props) => {
  const [index, setIndex] = useState(0)

useEffect(() => {
  setIndex(props.state.index);
}, [props])

...

Now according to this index you can change the appearance and the behavior your drawer content.现在,根据这个索引,您可以更改抽屉内容的外观和行为。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 标头在抽屉式导航器中不起作用 - header none is not working in drawer navigator react native 带有标题后退按钮的 React 导航抽屉导航器 - React navigation drawer navigator with header back button 如何将多个导航器相互嵌套? 即在抽屉导航器中嵌套底部选项卡并将抽屉导航器嵌套到堆栈导航器 - How to nest multiple navigator within each other? i.e. nesting bottom tab in drawer navigator and nesting drawer navigator to stack navigator 如何使用 resourceTimelineWeek header 修改持续时间 - How can i modify duration days with resourceTimelineWeek header 如何不卸载抽屉导航器以前打开的屏幕 - How not to unmount previously opened screen of Drawer Navigator TabNavigator从每个屏幕向StackNavigator标头传递不同的参数 - TabNavigator pass different param from each screen to StackNavigator header 如何在不同页面更改 header 颜色 - How can I change header color in different pages 当我在不同的时间间隔中有多个序列时,该如何解决highstock中的导航器问题? - How can I fix the navigator issue in highstock when I have more than 1 series in different time intervals? 如何仅对导航器屏幕之一禁用抽屉导航滑动? - How to disable drawer navigation swipe for one of navigator screen only? 我有问题 {useDrawerProgress} Hook in react drawer navigator 它不工作? - i have problem with {useDrawerProgress} Hook in react drawer navigator it is not working?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM