如何在App.js视图中导入和使用SVG文件

时间:2019-02-03 13:46:15

标签: android reactjs react-native

我想将其导入我的React Native项目的Appjs视图中。 我尝试了很多方法,但是没有用。我的意思是我想在我的视图中渲染它。如何在Appjs中导入并显示此文件?

这是我的代码:

import ForwardRef from '../../constants/UI_login/Home_Landing_Page/BackgroundComponent'
import React from "react";
import Svg, { Defs, LinearGradient, Stop, Rect } from "react-native-svg";
/* Adobe XD React Exporter has dropped some elements not supported by react-native-svg: style */

const BackgroundComponent = ({ svgRef }) => (
  <Svg width={375} height={247} viewBox="0 0 375 247" ref={svgRef}>
    <Defs>
      <LinearGradient
        id="a"
        x1={0.5}
        y1={0.807}
        x2={0.5}
        y2={1}
        gradientUnits="objectBoundingBox"
      >
        <Stop offset={0} stopColor="#fff" />
        <Stop offset={1} stopColor="#fff" stopOpacity={0} />
      </LinearGradient>
    </Defs>
    <Rect className="a" width={375} height={247} />
  </Svg>
);

const ForwardRef = React.forwardRef((props, ref) => (
  <BackgroundComponent svgRef={ref} {...props} />
));
export default ForwardRef;

App.js

import React from 'react';
import { StyleSheet} from 'react-native';
//import {Actions} from 'react-native-router-flux';
import Routes from './components/Routes';
import {firebaseConfig} from "./constants/ApiKeys";


import {AppContainer} from './components/Navigation'

import * as firebase from 'firebase';

if (!firebase.apps.length) { firebase.initializeApp(firebaseConfig); }

console.ignoredYellowBox = ['Setting a timer'];
export default class App extends React.Component {

  render() {
    return (

      <AppContainer/>

    );
  }
}

0 个答案:

没有答案