本文作者:IMWeb 朱灵子 原文出处:IMWeb社区 未经同意,禁止转载
本文举一个简单的例子介绍如何进行react native实战开发,主要从以下几个方面来进行介绍:
react native入门实战初体验,希望能给大家一些小帮助哦~~~^_^
在mac环境下可行的react native简易安装步骤如下:
Mac系统的包管理器,用于安装NodeJS和一些其他必需的工具软件。
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
brew install node
Watchman是由Facebook提供的监视文件系统变更的工具。安装此工具可以提高开发时的性能
brew install watchman
npm config set registry https://registry.npm.taobao.org
npm config set disturl https://npm.taobao.org/dist
react-native init ShortVideoList
cd ShortVideoList
react-native run-ios
使用react native List view写一个简单的页面
class ShortVideoList extends Component {
constructor(props) {
super(props);
this.state = {
dataSource: new ListView.DataSource({
....
}),
};
this.fetchData = this.fetchData.bind(this);
}
componentDidMount() {
this.fetchData();
}
render() {
return (
<ListView
dataSource={this.state.dataSource}
renderRow={this.renderShortVidio.bind(this)}
style={styles.listView}/>
);
}
renderShortVidio(data) {
return (
<View>
...
</View>
); }
React-Native的布局方式与web布局有一些不同,主要的不同点可以总结为以下几点:
mac环境下使用react-native处理进行真机模拟与调试的步骤方法是:
实现react native懒加载与Web懒加载的实现方式有些许不同。在react native中,我们使用measureLayout来判断窗体的具体位置。实现react native懒加载我们首先需要研究如何捕获图片出现在模拟器的可视区域,原生ios可以直接根据已有的属性判断图像出现在模拟器的可视区域。在react native中,我们也可以使用istView视图列表组件中的相关函数onChangeVisibleRows来辅助进行处理;
具体的使用方法是使用AsyncStorage.getItem()等方法获取数据,然后将数据保存在cache中,通过shouldComponentUpdate方法判断cache data和response data的差异,仅当两份数据不一致时才再次触发render方法。
扫码关注腾讯云开发者
领取腾讯云代金券
Copyright © 2013 - 2025 Tencent Cloud. All Rights Reserved. 腾讯云 版权所有
深圳市腾讯计算机系统有限公司 ICP备案/许可证号:粤B2-20090059 深公网安备号 44030502008569
腾讯云计算(北京)有限责任公司 京ICP证150476号 | 京ICP备11018762号 | 京公网安备号11010802020287
Copyright © 2013 - 2025 Tencent Cloud.
All Rights Reserved. 腾讯云 版权所有