美文网首页
RN-学习笔记

RN-学习笔记

作者: 壹点微尘 | 来源:发表于2017-08-04 08:44 被阅读66次
1. react-native-swiper 轮播组件

参考
http://www.jianshu.com/p/4dba338ef37a

render() {
        if(this.state.swiperShow){
            return(
                <View>
                    <Swiper height={ 300 }    //高度
                            showsButtons={false}  //显示左右箭头
                            autoplay={true}   //页面自动跳转
                            autoplayTimeout={ 2.5 }   //设置每个页面自动滑动的停留时间
                            autoplayDirection={ true }  //允许控制圆点的方向
                            index = { 1 }    //从第几页开始播放
                            showsPagination={ true }  //显示小圆点,(pagination是页码的意思)
                            paginationStyle={{ position:'absolute',bottom:10}}
                            activeDotStyle={{backgroundColor:'#ff7454', width: 10, height: 10}}
                            horizontal={ true }   //滚动的内容横向排列
                    >
                        <View style={styles.win}>
                            <Image source={ require('../8.jpg')}  style={styles.img}/>
                        </View>
                        <View style={styles.win}>
                            <Image source={ require('../10.jpg')} style={styles.img2} />
                        </View>
                        <View style={styles.win}>
                            <Image source={ require('../8.jpg')}  style={styles.img}/>
                        </View>

                    </Swiper>
                </View>
            )
        }else {
            return (
                <View style={{height:200}}>
                    <Image source={ require('../8.jpg')}  />
                </View>
            );
        }
    }
}
img2: {
        width: width,
        height:300,
        resizeMode: 'stretch'
    }
2.array.map(callback,[ thisObject]); ( map在这里是映射的意思)
-
- array.map(callback,[ thisObject]);   ( map在这里是映射的意思)
-
callback的参数也类似:
[].map(function(value, index, array) {
    // ...
});
-------------------------------------------------------------------
例一:
map方法的作用不难理解,“映射”嘛,也就是原数组被“映射”成对应新数组。下面这个例子是数值项求平方:
var data = [1, 2, 3, 4];

var arrayOfSquares = data.map(function (item) {
  return item * item;
});

alert(arrayOfSquares); // 1, 4, 9, 16
callback需要有return值
--------------------------------------------------------------------
例二:
 data1 = dataJson.data;
 i++;
 data1.map( (item)=> {
       dataList.push({     //dataList是全局定义的空数组
           key: i,
           value: item
        })
        i++;
 } )
3.验证码倒计时 setInterval() 和 clearInterval()
coutDown() {
        this.setState({
            MainTime:60,
            MainTimeTitle: ''
        });
        this.bb = setInterval( () => {
            var aa = this.state.MainTime - 1;
            if( aa ===0){
                clearInterval( this.bb );
                this.setState({
                    MainTime:'',
                    MainTimeTitle: '重新获取'
                })}else{
                    this.setState({
                        MainTime: aa,
                        MainTimeTitle: ''
                    })
                }
        },1000)
    }
-------------------------------------
 <Text
         onPress={ this.coutDown.bind(this) }
          style={ styles.time}
 >{this.state.MainTime}{this.state.MainTimeTitle}
 </Text>

(踩坑) :这样写的话会有个警告(如下,如图):

countDown()中的bb方法一直在执行

(解决方法)如下:

Waring: Can only update a mounted or mounting component. 

分析:可以看到在 countdown方法中每秒中调用一次bb方法去递减秒数,
当组件unmounted之后这个timer并没有停止,所以出现了上面的问题。

--------------------------------------------------------
解决方法:
将每次setInterval返回的ID保存起来,在componentWillUnmount方法中clearInterval
--------------------------------------------------------

完整代码:
    //组件将被卸载
    componentWillUnmount() {
        clearInterval(this.state.timeId)
    }
    //倒计时
    coutDown() {
        this.setState({
            MainTime:60,
            MainTimeTitle: ''
        });
        this.bb = setInterval( () => {
            var aa = this.state.MainTime - 1;
            if( aa ===56 ){
                clearInterval( this.bb );
                this.setState({
                    MainTime:'',
                    MainTimeTitle: '重新获取'
                })}else{
                    this.setState({
                        MainTime: aa,
                        MainTimeTitle: ''
                    })
                }
        },1000)
        this.setState({
            timeId: this.bb
        });
    }

http://blog.csdn.net/tujiaw/article/details/58238975

4.(react-native-image-picker)上传头像 + (modal浮层) +(AsyncStorage.setItem-getItem)

http://www.jianshu.com/p/04dfef54645c

5.两种方式实现城市三级联动 + (react-narive-picker)+ (sectionList高性能的分组列表组件)+ (webview

http://www.jianshu.com/p/ea94c8c1ee44

相关文章

  • RN-学习笔记

    1. react-native-swiper 轮播组件 参考http://www.jianshu.com/p/4d...

  • RN-笔记

    创建指定RN版本的工程 倒计时 (系统自带的) 按钮 Switch的状态切换 ScrollView的吸顶效果 遍历...

  • 学习笔记:RN-原生交互方案

    一、iOS端交互 1、iOS调用JavaScript方法 1.1、原生端 新建桥连类,继承于RCTEventEmi...

  • react-native-update-mutlirn RN热更

    一、RN-安装 react-native-update-mutlirn npm install react-nat...

  • 学习笔记:RN-打包和动态化加载

    一、Native本地加载流程 1.1、React应用打包 1、导出.jsbundle包和图片资源 生成.jsbun...

  • 2019-01-15 RN仿微信朋友圈

    1.下载本示例 github 地址https://github.com/anzipeng/-RN-,喜欢就点个赞吧...

  • MARKDOWN学习笔记

    标题 # MARKDOWN学习笔记 MARKDOWN学习笔记 MARKDOWN学习笔记- MARKDOWN学习笔记...

  • RN-可拖动的悬浮按钮

    RN-可拖动的悬浮按钮 需求 分享悬浮按钮,需要展示在特定页面,并且支持拖动(防止遮挡页面内容) 解决方案思路 1...

  • RN-封装

    本文内容通过代码来描述封装的思想(本人理解的封装) 封装嘛 1、能不给你看的,坚决不给你看2、必须要给你看的,让你...

  • RN-继承

    显示类 父类 子类

网友评论

      本文标题:RN-学习笔记

      本文链接:https://www.haomeiwen.com/subject/cmtvlxtx.html