react-native - 如何在 React-Native 中设置 DrawerNavigator 的背景图像?

标签 react-native navigation-drawer react-native-android react-native-ios stack-navigator

我在我的项目中集成了 DrawerNavigator。它工作正常,但没有任何属性来设置背景图像。如何在 DrawerNavigator 中添加背景图像。

DrawerNavigator

DrawerNavigation代码

import { AppRegistry  , Dimensions} from 'react-native';

import Library from './ViewControllers/Library';
import Language from './ViewControllers/Language';
import AboutUS from './ViewControllers/AboutUS';
import Support from './ViewControllers/Support';
import { DrawerNavigator } from 'react-navigation';

const MyApp = DrawerNavigator({
  Library: {
    screen: Library,
  },
  Language: {
    screen: Language,
  },
  AboutUS: {
    screen: AboutUS,
  },
  Support: {
    screen: Support,
  },

},{
      initialRouteName:'Library',
      drawerWidth: Dimensions.get('window').width / 2.0,
      drawerPosition: 'left',
      useNativeAnimations : false,
      drawerBackgroundColor : 'white',
      contentOptions: {
        activeTintColor: 'black',
        activeBackgroundColor : 'transparent',
        inactiveTintColor : 'black',
        itemsContainerStyle: {
          marginVertical: 0,
        },
        iconContainerStyle: {
          opacity: 1
        },
        itemStyle :{
          height : 50,
        }

      },

  }
);



AppRegistry.registerComponent('Basair', () => MyApp);

enter image description here

最佳答案

我们可以提供定制 contentComponent用于 DrawerNavigator。请参阅下面的代码。

代码:

import { AppRegistry  , Dimensions , ScrollView , Image} from 'react-native';

import React, { Component } from 'react';

import Library from './ViewControllers/Library';
import Language from './ViewControllers/Language';
import AboutUS from './ViewControllers/AboutUS';
import Support from './ViewControllers/Support';

import { DrawerNavigator , DrawerItems, SafeAreaView  } from 'react-navigation';

const CustomDrawerContentComponent = (props) => (
  <ScrollView>
    <Image style={{flex: 1 , position : 'absolute' , top : 0 , height :Dimensions.get('window').height  , width : Dimensions.get('window').width}}source={require('./menuOverlay.png')}/>
    <SafeAreaView style={{flex: 1 , backgroundColor : 'transparent'}} forceInset={{ top: 'always', horizontal: 'never' }}>
      <DrawerItems {...props} />
    </SafeAreaView>
  </ScrollView>
);

const MyApp = DrawerNavigator({
  Library: {
    screen: Library,
  },
  Language: {
    screen: Language,
  },
  AboutUS: {
    screen: AboutUS,
  },
  Support: {
    screen: Support,
  },

},{
      initialRouteName:'Library',
      drawerWidth: Dimensions.get('window').width,
      drawerPosition: 'left',
      useNativeAnimations : false,
      drawerBackgroundColor : 'transparent',
      contentComponent: CustomDrawerContentComponent,
      contentOptions: {
        activeTintColor: 'black',
        activeBackgroundColor : 'transparent',
        inactiveTintColor : 'black',
        itemsContainerStyle: {
          marginVertical: 0,
        },
        iconContainerStyle: {
          opacity: 1,
        },
        itemStyle :{
          height : 50,
        }

      },

  }
);



AppRegistry.registerComponent('Basair', () => MyApp);

设置抽屉背景:

enter image description here

关于react-native - 如何在 React-Native 中设置 DrawerNavigator 的背景图像?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47904949/

相关文章:

react-native - react 本地 map 在 Google Play 的独立版本上崩溃

android - Android Studio 1.4 中的抽屉导航模板

java - 添加抽屉导航后,应用程序在启动时崩溃

react-native - 错误 : Could not find or load main class org. gradle.wrapper.GradleWrapperMain

react-native - React Native FlatList 嵌套在具有相同方向的 FlatList 中

reactjs - 将本地镜像路径作为两个功能组件之间的 prop 传递

javascript - 在 WebStorm 上的每个文件键上触发 React-native 热重载

react-native - 我有一个模式,在加载时可见设置为 true 时有效,但是如果它设置为 false 或者我关闭并重新打开它在 android 上不起作用

javascript - react native : Native Android UI component with JWPlayer shows no video image

android - 抽屉导航 fragment 中不显示汉堡包图标