刚开始学英语,

我创建了一个单独的flexdemo文件.js并创建了如下组件:

import React, { Component } from 'react';
import { View } from 'react-native';

export default class FlexibleViews extends Component {
    render() {
        return (
            <View style={{ flex: 1 }}>
                <View style={{ flex: 1, backgroundColor: "powderblue" }}> </View>
                <View style={{ flex: 2, backgroundColor: "skyblue" }}> </View>
                <View style={{ flex: 3, backgroundColor: "steelblue" }}> </View>
            </View>

        );
    }
}

和应用程序.js文件如下:

import React, { Component } from 'react';
import {
  AppRegistry,
  Platform,
  StyleSheet,
  Text,
  View, Image
} from 'react-native';

// import Bananas from './src/banana';
// import LotsOfStyles from './src/styledemo'

import FlexibleViews from './src/flexdemo';

export default class App extends Component {
  render() {
    return (
      // <Bananas name = "Tapan"/>
      <View>
        <FlexibleViews />
      </View>

    );
  }
}

这给了我一个错误:

enter image description here

Now if I try to run the code by adding flexdemo.js code into App.js then everything works fine.

更改了应用程序.就像这样:

import React, { Component } from 'react';
import { AppRegistry, View } from 'react-native';

export default class FlexDimensionsBasics extends Component {
  render() {
    return (
      // Try removing the `flex: 1` on the parent View.
      // The parent will not have dimensions, so the children can't expand.
      // What if you add `height: 300` instead of `flex: 1`?
      <View style={{flex: 1}}>
        <View style={{flex: 1, backgroundColor: 'powderblue'}} />
        <View style={{flex: 2, backgroundColor: 'skyblue'}} />
        <View style={{flex: 3, backgroundColor: 'steelblue'}} />
      </View>
    );
  }
}

enter image description here

推荐答案

删除组件内部的注释.

React-native相关问答推荐

获取 TypeError:this.InnerNativeModule.configureProps 不是 mac 上 expo 中的函数

如何在 react native 中以 redux 形式设置隐藏字段?

你使用 react native 应该学习 react.js 吗?

如何停止在 textInput React Native 中输入空格?

从 .apk 到 .aab 的本地构建版本react,如何将应用程序发送给客户端?

Google SignIn SDK 因抛出错误而失败,发生不可恢复的登录失败 -catch 错误

'React native run android' 在模拟器中启动应用程序后立即停止

滚动到具有可变元素大小的 FlatList 中的某些索引的有效方法

React Native:约束 Animated.Value

react native foreach 循环

iPhone 6s plus 上的字体大小

如何在 React Navigation createStackNavigator 中更改字体系列

React Native 错误找不到模块metro-config/src/defaults/blacklist

如何从 React Native-App 中的 res/drawable-folder 加载图像?

等待模块失效的超时

React Native Image 不显示,我该如何解决?

Firebase 3.3 实时数据库坚持使用 React Native 0.32 Making a connection attempt

我可以从react-native元素中删除 tvOS 吗?

React Native font outline / textShadow

React Native:如何动态更改