ReactNative 学习笔记 Component - ViewPager, 异步网络数据

Component - ViewPager

一个允许在子视图之间左右翻页的容器。每一个ViewPagerAndroid的子容器会被视作一个单独的页,并且会被拉伸填满ViewPagerAndroid。

注意所有的子视图都必须是纯View,而不能是自定义的复合容器。你可以给每个子视图设置样式属性譬如padding或backgroundColor。

关键代码:


third-party lib

有很多开源的库支持左右翻页

1. React-Native-ViewPager

ViewPager and Indicator component for react-native on both android and ios.

ViewPager’s props is the same as ViewPagerAndroid.

2. react-native-scrollable-tab-view

This is probably my favorite navigation pattern on Android,

I wish it were more common on iOS! This is a very simple JavaScript-only implementation of it for React Native.

For more information about how the animations behind this work, check out the Rebound section of the React Native Animation Guide

Sample Code ViewPager

Sample Code GuidePage

异步网络数据

ReactNative不同于android的handler,AsyncTask。他是通过this.state 来触发UI更新。

RN中的网络请求:XMLHttpRequest, Fetch post get;

关键代码:

// get json data from network
fetchData(){
    fetch(REQ_URL)
        .then((response) => response.json())
        .then((responseData) => {
            this.setState({
                movies: responseData.movies
            });
        })
        .done();
}

Sample Code

官网API地址

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值