在已有的项目中引入react native
如果新建一个 Prepare your app首先在你的app中的 compile "com.facebook.react:react-native:+"
在项目的 repositories {
jcenter()
maven {
// All of React Native (JS,Android binaries) is installed from npm
url "$projectDir/../../node_modules/react-native/android"
}
}
然后在app中的 <uses-permission android:name="android.permission.INTERNET" />
Add native code添加本地代码确保 public class RNTestActivity extends ReactActivity {
@Override
protected String getMainComponentName() {
return "MyAwesomeApp";
}
@Override
protected boolean getUseDeveloperSupport() {
return BuildConfig.DEBUG;
}
@Override
protected List<ReactPackage> getPackages() {
return Arrays.<ReactPackage>asList(
new MainReactPackage()
);
}
}
Add JS to your app在项目根文件执行一下命令: $ npm init
$ npm install --save react-native
$ curl -o .flowconfig https://raw.githubusercontent.com/facebook/react-native/master/.flowconfig
创建了 "start": "node node_modules/react-native/local-cli/cli.js start"
然后在index.android.js中写入相关代码 import React from 'react';
import {
AppRegistry,StyleSheet,Text,View
} from 'react-native';
class MyAwesomeApp extends React.Component {
render() {
return (
<View style={styles.container}>
<Text style={styles.hello}>Hello,World</Text>
</View>
)
}
}
var styles = StyleSheet.create({
container: {
flex: 1,justifyContent: 'center',},hello: {
fontSize: 20,textAlign: 'center',margin: 10,});
AppRegistry.registerComponent('MyAwesomeApp',() => MyAwesomeApp);
吐槽: 如果你遇到了 将 如果你遇到了更多的奇葩问题,那就是 (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
- c# – 单元使用Dns.GetHostEntry(hostNameOrIp)依赖项测试代
- c# – NHibernate无法将MySQL日期/时间值转换为System.Date
- Ruby – 检查block_given之间有什么区别?和!block.nil?
- ruby – 比较两个图像,其中一个略微裁剪(缩放)
- ThoughtWorks TDD open-workshop第三季总结
- vb与数据库(二)之迟到的学生信息管理系统总结
- ruby-on-rails – 有没有办法使用HashWithIndifferentAcces
- 设计模式-OOD的设计原则(1)-"开-闭原则"
- flex 动态画线
- 硬件 – Oracle:1台大型服务器与2台小型服务器?