修改index.js后黑屏 [英] Black screen after modifying index.js

查看:58
本文介绍了修改index.js后黑屏的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在学习如何使用 React 的在线教程.

I am following a tutorial online to learn how to use React.

老师让我创建了一个名为albums的项目,并修改了index.js的内容,但是我在ios模拟器上黑屏了.

The instructor made me create a project called albums and modify the content of index.js, however I get a black screen on the ios simulator.

我做了什么(遵循讲师的详细信息):

What I did (following the instructor's details):

1) 创建一个新项目 react-native init-albums

1) Create a new project react-native init-albums

2) 进入带有cd专辑

3) 运行 react-native run-ios

4) 我可以在模拟器屏幕上看到 App.js 文件中的内容(我假设是任何新的 React Native 项目的初始屏幕).按 Cmd+R 重新加载Cmd+D 或摇动开发菜单

4) I can see on the simulator screen what is inside the file App.js (The initial screen of - I assume - any new React Native project). Press Cmd+R to reload, Cmd+D or shake for dev menu etc.

5) 删除index.js里面的内容,替换为:

5) Delete the content inside index.js and replace it with:

import React from "react";
import { AppRegistry, Text } from "react-native";

const App = () => {
 return <Text>Some Text</Text>;
};

AppRegistry.registerComponent("albums", () => App);

它应该出现在模拟器的左上角Some Text,但它没有.屏幕是黑色的.我做错了什么?

It should appear Some Text on the top left of the simulator BUT it does not. The screen is black. What am I doing wrong?

推荐答案

您需要为您的应用程序定义背景颜色.您还应该从 react-native

You need to define a background color for you application. You should also import View from react-native

import { AppRegistry, Text, View } from "react-native";

const App = () => {
 return (
   <View style={{backgroundColor: 'white', flex:1}}>
     <Text>Some Text</Text>
   </View>
  );
};

之所以是黑色,是因为AppDelegate.m中rootView的backgroundColor在0.58.0

The reason that it is black is because the in the AppDelegate.m the rootView backgroundColor has been changed in version 0.58.0

在以前的版本中是

rootView.backgroundColor = [[UIColor alloc] initWithRed:1.0f green:1.0f blue:1.0f alpha:1];

现在是0.58.+

rootView.backgroundColor = [UIColor blackColor];

这篇关于修改index.js后黑屏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆