【问题标题】:Drawer Navigation background Image SVG抽屉导航背景图像 SVG
【发布时间】:2020-03-11 08:02:11
【问题描述】:

我正在研究抽屉导航。我正在渲染我的自定义 contentComponent 来编辑我的抽屉 导航但问题是当我调用我的 SVG 组件时,它不显示除 SVG 之外的任何内容。 我试过这种方式。

const CustomDrawerContentComponent = (props) => (

    <SafeAreaView>
      <Svg/>

     <DrawerItems {...props} /> 
    <Text>HI</Text>

  </SafeAreaView>


);

我还尝试使用我的 SVG 作为 ImageBackground,如下面的代码所示。

    import { createDrawerNavigator,DrawerItems  } from 'react-navigation-drawer';
    import { createAppContainer } from 'react-navigation';
    import { Dimensions, ScrollView, Image, View,Text,SafeAreaView,ImageBackground } from 'react-native';
    import React from 'react';
    import Svg from '../Common/svgMenuTranformer'

    import mainScreen from '../screens/main';


    const CustomDrawerContentComponent = (props) => (

        <SafeAreaView>
          <ImageBackground style={{width:'100%',height:'100%'}} source={()=> <Svg/>}>
         <DrawerItems {...props} /> 
        <Text>HI</Text>
        </ImageBackground>
      </SafeAreaView>


    );


    // drawer navigation options
    const RootDrawerNavigator = createDrawerNavigator({
      HomeScreen: {
        screen: mainScreen,
      },
      // About: {
      //   //screen: AboutStack,
      // },,

    },
      {
        //drawerPosition: 'right',
        //useNativeAnimations : true,
        drawerBackgroundColor: 'transparent',
        contentComponent: CustomDrawerContentComponent,
        // contentOptions: {
        //   activeTintColor: 'black',
        //   activeBackgroundColor: 'transparent',
        //   inactiveTintColor: 'black',
        //   itemsContainerStyle: {
        //     marginVertical: 0,
        //   },
        //   iconContainerStyle: {
        //     opacity: 1,
        //   },
        //   itemStyle: {
        //     height: 50,
        //   }

        // }
      });

    export default createAppContainer(RootDrawerNavigator);

import * as React from "react"
import Svg, { Defs, Path } from "react-native-svg"
/* SVGR has dropped some elements not supported by react-native-svg: filter */

function SvgComponent(props) {
  return (
    <Svg width={"100%"} height={"100%"} viewBox="0 0 454 1536" {...props}>
      <Defs></Defs>
      <Path
        d="M-128.13 904s707.552 181.69 512 804H-166z"
        fillRule="evenodd"
        fill="#2196f3"
        filter="url(#prefix__a)"
      />
      <Path
        d="M-84 1456s594-172 494-584c0 0-90.022-228.968-18-378 69.979-144.8 54-384-64-496H-84v1458z"
        fill="#fff"
        filter="url(#prefix__b)"
        fillRule="evenodd"
      />
    </Svg>
  )
}

export default SvgComponent

如何将我的 SVG 组件显示为背景图像并在 contentComponent 中添加内容,如文本、导航路线等?

【问题讨论】:

    标签: javascript react-native svg react-navigation react-navigation-drawer


    【解决方案1】:

    你不能在 ImageBackground 中使用 svg。

    您需要渲染 svg。以及具有绝对位置的内容

    
    const CustomDrawerContentComponent = (props) => (
    
            <SafeAreaView>
                <View>
                  <Svg style={{//passs your style here}}/>
                    <View style={{position:'absolute', top:0, left:0, right:0, bottom:0,}}>
                        <DrawerItems {...props} /> 
                        <Text>HI</Text>
                    </View>            
    
                </View>
    
          </SafeAreaView>
    );
    
    //.....
    
    
    
    

    【讨论】:

    • 在尝试您的代码后问题仍然存在。内容未显示
    • 有一个错字..不要把绝对视图放在svg里面..但是在svg之后。
    【解决方案2】:

    试试这个:

      return(
          <SafeAreaView style={{ flex:1 }}>
            <View style={{ position:'absolute', top:0, bottom:0, right:0, left:0 }}>
        <BGImage />
    
    </View>
            <Text>Testklasdmklasmdas</Text>
            <Text>Testklasdmklasmdas</Text>
            <Text>Testklasdmklasmdas</Text>
            <Text>Testklasdmklasmdas</Text>
            <Text>Testklasdmklasmdas</Text>
            <Text>Testklasdmklasmdas</Text>
          </SafeAreaView>
        );
    

    【讨论】:

      猜你喜欢
      • 2019-09-21
      • 2015-07-19
      • 2019-09-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-06-10
      相关资源
      最近更新 更多