社区微信群开通啦,扫一扫抢先加入社区官方微信群
社区微信群
首先考虑集成到现有的项目,而不是新建一个项目从0->100
这里默认上一篇文章中的配置都已完成。
1、安装cocoapods
pod安装:pod init
卸载pod:sudo gem uninstall cocoapods
安装pod:sudo gem install cocoapods pod setup
2、我们把具体的依赖包记录在package.json文件中
{
"name": "rn_testAddRNIntoProject",
"version": "0.0.1",
"private": true,
"scripts": {
"start": "node node_modules/react-native/local-cli/cli.js start"
},
"dependencies": {
"react": "15.0.2",
"react-native": "0.26.1"
}
}
npm install
会有这么一个文件夹
3、配置Podfile,创建xcworkspace
初始文件目录(马赛克的地方一开始没有):
cd 到这个目录,然后:pod init
pod init
一直出错,先不用管它,直接创建Podfile文件,编写需要的内容,再pod install
就可以了:运行:pod install
pod 内容:
# 这里写上项目名⬇️
target 'rn_testAddRNIntoProject' do
# Your 'node_modules' directory is probably in the root of your project,
# but if not, adjust the `:path` accordingly
pod 'React', :path => '../node_modules/react-native', :subspecs => [
'Core',
'RCTText',
'RCTNetwork',
'RCTWebSocket', # needed for debugging
# Add any other subspecs you want to use in your project
]
end
$ touch index.ios.js
'use strict';
import React from 'react';
import {
AppRegistry,
StyleSheet,
Text,
View
} from 'react-native';
class RNHighScores extends React.Component {
render() {
var contents = this.props["scores"].map(
score => <Text key={score.name}>{score.name}:{score.value}{"n"}</Text>
);
return (
<View style={styles.container}>
<Text style={styles.highScoresTitle}>
2048 High Scores!
</Text>
<Text style={styles.scores}>
{contents}
</Text>
</View>
);
}
}
const styles = StyleSheet.create({
container: {
flex: 1,
justifyContent: 'center',
alignItems: 'center',
backgroundColor: '#FFFFFF',
},
highScoresTitle: {
fontSize: 20,
textAlign: 'center',
margin: 10,
},
scores: {
textAlign: 'center',
color: '#333333',
marginBottom: 5,
},
});
// Module name
AppRegistry.registerComponent('RNHighScores', () => RNHighScores);
这里提醒一句:所有使用<>的地方,都先完整写好<>,再写参数,否则很容易忘记补全,新手已经自坑几次了
如果觉得我的文章对您有用,请随意打赏。你的支持将鼓励我继续创作!