IOS与React Native混编,将RN框架使用CocoaPods集成到原生项目中
来源:互联网 发布:淘宝摄影师在哪里接单? 编辑:程序博客网 时间:2024/05/20 09:10
1, 用Xcode创建一个iOS项目
2, 我们在RN-IOS 项目目录建一个package.json文件,用于初始化React-native。
//{
“name”: “AwesomeProject”,
“version”: “0.0.1”,
“private”: true,
“scripts”: {
“start”: “node node_modules/react-native/local-cli/cli.js start”,
“test”: “jest”
},
“dependencies”: {
“react”: “15.3.2”,
“react-native”: “0.36.1”
},
“jest”: {
“preset”: “jest-react-native”
}
}
**3,执行安装: 打开终端 cd 你的RN-IOS路径 (直接把文件拖进去)
然后 npm install
安装成功后,RN-IOS目录会产生一个node_modules,里面就是react-native依赖的所有项目包。**
4,创建index.ios.js文件
/**
* Sample React Native App
* https://github.com/facebook/react-native
* @flow
*/
import React, { Component } from ‘react’;
import {
AppRegistry,
StyleSheet,
Text,
View
} from ‘react-native’;
export default class RN-IOS extends Component {
render() {
return (
Welcome to React Native!
To get started, 222222edit index.ios.js
Press Cmd+R to reload,{‘\n’}
Cmd+D or shake for dev menu
);
}
}
const styles = StyleSheet.create({
Container: {
flex: 1,
justifyContent: ‘center’,
alignItems: ‘center’,
backgroundColor: ‘#F5FCFF’,
},
welcome: {
fontSize: 20,
textAlign: ‘center’,
margin: 10,
},
instructions: {
textAlign: ‘center’,
color: ‘#333333’,
marginBottom: 5,
},
});
AppRegistry.registerComponent(‘RN-IOS’, () => RN-IOS);
5,使用Cocoapods集成react-native
vim Podfile (创建Podfile文件,进去后 i 进入编辑状态,然后粘贴下边代码,然后Esc + : wq 保存退出)
platform:ios, ‘7.0’
target ‘RN-IOS’ do
pod ‘React’, :path => ‘./node_modules/react-native’, :subspecs => [
‘Core’,
‘RCTNetwork’,
‘RCTText’,
‘RCTWebSocket’,
]
end
最后执行 pod install ,就完成了react-native工程包的集成。
6,添加react-native应用
打开项目,创建一个ReactView,继承与UIView,
import “ReactView.h”
- IOS与React Native混编,将RN框架使用CocoaPods集成到原生项目中
- IOS-React Native 使用CocoaPods集成到原生项目中
- React Native集成到原生项目(IOS)
- React Native 集成到原生项目(iOS)
- React Native 集成到原生项目(iOS)
- React Native集成到IOS原生项目
- iOS原生项目中集成React Native
- iOS原生项目中集成React Native
- iOS原生项目中集成React Native
- iOS原生项目中集成React Native
- React Native集成到原生项目示例
- 最新iOS原生项目集成React-Native
- 使用CocoaPods 将 React Native 导入已有的项目中
- React Native 嵌入到iOS原生项目
- react native集成到原有的项目中(iOS)
- ios原生集成React Native
- React Native学习笔记之--向原生应用中集成RN页面
- ios原生项目集成react-native过程记录
- Oracle跟踪文件trace文件
- 404. Sum of Left Leaves [LeetCode]
- JAVA开发过程中使用第三方jar(未完待续)
- scrapy抓取一个电影网站信息
- shell脚本运行方式和对环境变量的影响
- IOS与React Native混编,将RN框架使用CocoaPods集成到原生项目中
- 1078. Hashing (25)
- 前端防止按钮被多次点击
- 用Web api /Nancy 通过Owin Self Host简易实现一个 Http 服务器
- Android Volley 发送请求Demo
- (二)Lua脚本语言入门
- tensorflow基础学习笔记
- 如何使用水果编曲软件预处理效果
- 【PAT】1081. Rational Sum