您的位置:首页 > Web前端 > React

iOS原生 和 react native视图混编

2017-12-08 18:29 429 查看
在iOS原生功能中加入RN,请看之前 写的 RN与iOS交互系列文章.本篇只讲下视图混编.

关键点只有二:

1.通过 RCTRootView 加载RN视图.

2.RN中,只需要AppRegistry.registerComponent()导出即可.

关键代码:

OC里面:

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

const instructions = Platform.select({
ios: 'Press Cmd+R to reload,\n' +
'Cmd+D or shake for dev menu',
android: 'Double tap R on your keyboard to reload,\n' +
'Shake or press menu button for dev menu',
});

export default class App extends Component<{}> {
render() {
return (
<View style={styles.container}>
<Text>
我是RN
</Text>
</View>
);
}
}

const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: '#F5FCFF',
},
welcome: {
fontSize: 20,
textAlign: 'center',
margin: 10,
},
instructions: {
textAlign: 'center',
color: '#333333',
marginBottom: 5,
},
});

AppRegistry.registerComponent('iosrn', () => App);


View Code
效果如图:



github: https://github.com/pheromone/IOS-native-and-React-native-interaction 中的 iOSRN
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: