简体   繁体   English

React NativeBase没有显示我导入的组件

[英]React NativeBase not showing my imported components

I'm fairly new to React and React Native and I'm having a play with React NativeBase. 我是React和React Native的新手,并且正在使用React NativeBase。

I've managed to get the following working within a single file, but now I'm simply trying to split up my code into multiple components in separate files. 我已经设法在单个文件中处理以下内容,但是现在我只是想将我的代码分成单独文件中的多个组件。

The problem is, my imported component does not show. 问题是,我的导入组件没有显示。 I've struggled with this for a while now and I can't see what I'm doing wrong... probably something really stupid. 我已经为此苦苦挣扎了一段时间,但我看不出自己在做错什么……可能真的很愚蠢。

Here is my code: 这是我的代码:

code/index.ios.js 代码/index.ios.js

import React, { Component } from 'react';
import {
  AppRegistry,
  StyleSheet,
  Text,
  View
} from 'react-native';
import {
  Container,
  Title,
  Header,
} from 'native-base';
import MainContent from './main';

class AwesomeNativeBase extends Component {
  render() {
    return (
      <Container>
        <Header>
          <Title>My awesome app</Title>
        </Header>
        <MainContent />
      </Container>
    );
  }
}
AppRegistry.registerComponent('AwesomeNativeBase', () => AwesomeNativeBase);

code/main.js 代码/ main.js

import React from 'react';
import { Text } from 'react-native';
import { Content } from 'native-base';

export default class MainContent extends React.Component {
  render() {
    return (
      <Content>
        <Text>Oh hello there!</Text>
      </Content>
    );
  }
}

I'm running this using: 我正在使用此运行:

rnpm link
react-native run-ios

So just to clarify, the code in index.ios.js shows fine and the header is displayed in the iPhone simulator, however, the text in main.js does not. 因此,为了澄清index.ios.jsindex.ios.js中的代码很好,标题显示在iPhone模拟器中,但是main.js中的文本却没有。

Any help is much appreciated! 任何帮助深表感谢!

NativeBase Container as of now mainly accepts Header , Content and Footer . 截至目前,NativeBase Container主要接受HeaderContentFooter

NativeBase Content in-turn takes Image, View and ScrollView of React Native and not any other custom components. NativeBase Content依次使用React Native的Image,View和ScrollView,而不需要其他任何自定义组件。

Thank you for bringing this into notice. 多谢您注意此事。

My team will get back to you with the solution. 我们的团队将与您联系并提供解决方案。

So I've figured out the issue... It seems like React NativeBase does not allow you to have the <Content> section outside of the main component. 所以我已经解决了这个问题。似乎React NativeBase不允许您将<Content>部分放在主要组件之外。 Something like this works: 像这样的作品:

code/index.ios.js 代码/index.ios.js

 import React, { Component } from 'react'; import { AppRegistry, StyleSheet, Text, View } from 'react-native'; import { Container, Title, Header, Content, } from 'native-base'; import MainContent from './main'; class AwesomeNativeBase extends Component { render() { return ( <Container> <Header> <Title>My awesome app</Title> </Header> <Content> <MainContent /> </Content> </Container> ); } } AppRegistry.registerComponent('AwesomeNativeBase', () => AwesomeNativeBase); 

code/main.js 代码/ main.js

 import React from 'react'; import { Text } from 'react-native'; export default class MainContent extends React.Component { render() { return ( <Text>Oh hello there!</Text> ); } } 

So now if you notice, I have just the <Text> tags in my main.js and not the <Content> tags... Not too sure why this makes a huge difference but it's good to know! 因此,现在,如果您注意到了,我的main.js只有<Text>标记,而没有<Content>标记...不太清楚为什么会有很大的不同,但是很高兴知道!

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM