React NativeBase not showing my imported components

前端 未结 2 1341
深忆病人
深忆病人 2020-12-22 03:38

I\'m fairly new to React and React Native and I\'m having a play with React NativeBase.

I\'ve managed to get the following working within a single file, but now I\'

相关标签:
2条回答
  • 2020-12-22 04:09

    NativeBase Container as of now mainly accepts Header, Content and Footer.

    NativeBase Content in-turn takes Image, View and ScrollView of React Native and not any other custom components.

    Thank you for bringing this into notice.

    My team will get back to you with the solution.

    0 讨论(0)
  • 2020-12-22 04:22

    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. Something like this works:

    code/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

    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!

    0 讨论(0)
提交回复
热议问题