How to import and use this File in my App.js view

2019-08-10 22:28发布

问题:

I want to import this in my react native project's Appjs view.
I tried many ways but its not working.I mean i want to render it inside My view. How Can i Import and show this file in my Appjs. Can anyone can please help me, Its very important for me.

Here is my code:

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 ForwardRef from '../../constants/UI_login/Home_Landing_Page/BottomNavigationComponent'

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/>
                <ForwardRef/>
            );
        }
    }

Now i am getting a black blank space there

回答1:

You are using a default export and not a named one, so instead of

import {ForwardRef} from "..."

you have to write

import ForwardRef from "..."


回答2:

:)

Please try to do the following:

  1. open the AppContainer component file;
  2. in the head of the file add import your BackgroundComponent component;
  3. and add the <ForwardRef/> to the render return method: