下一个项目公司也打算使用react native.大致看了下原型设计,写几个小demo先试试水.特此记录下.

1.微信及朋友圈分享.QQ及朋友圈分享,微博分享,微信支付,支付宝支付.

2.导航条渐隐

3.通讯录

4.卡片式轮播

5.时间轴

6.图片+列表的组合效果

7.图片下拉放大

8.原生视频播放器

9.react-navigation的使用和变更

10.倒计时

11.多张图片查看

12.自定义页面加载指示器

......

1.微信及朋友圈分享,微信支付: https://github.com/yorkie/react-native-wechat

QQ分享:https://github.com/reactnativecn/react-native-qq

微博分享: https://github.com/reactnativecn/react-native-weibo

支付宝支付:react-native-smart-alipay 或者 react-native-payment-alipay 或者react-native-alipay

微信支付: react-native-wechat

想要秀操作,通过交互原生支付也可以.

大神刚出炉的React Native 分享功能封装【一行代码,双平台分享】 支持平台:【QQ】【QQ空间】【微信】【朋友圈】【微博】         https://github.com/songxiaoliang/react-native-share

2.导航条渐隐,该项目我们打算使用react-navigation,但是该库的导航条使用不了渐隐,于是只能在需要导航条渐隐的地方,改用自己定义的导航条.

基本代码如下:

  1. /**
  2. * Created by shaotingzhou on 2017/5/9.
  3. */
  4. import React, { Component } from 'react';
  5. import {
  6. AppRegistry,
  7. StyleSheet,
  8. Text,
  9. View,
  10. Image,
  11. TouchableOpacity,
  12. Platform,
  13. Dimensions,
  14. RefreshControl,
  15. FlatList,
  16. ActivityIndicator,
  17. ScrollView,
  18. TextInput
  19. } from 'react-native';
  20. var {width,height} = Dimensions.get('window');
  21. var dataAry = []
  22. var start = 0
  23.  
  24. export default class OneDetailsFlat extends Component{
  25. //返回首页方法需要修改react-navigation库的源码.修改方法见:http://www.jianshu.com/p/2f575cc35780
  26. static navigationOptions = ({ navigation }) => ({
  27. header:null,
  28. title: 'FlatList',
  29. headerStyle:{backgroundColor:'rgba(255,255,255,0.0)'},
  30. headerTintColor: 'black',
  31. headerLeft:(
  32. <Text onPress={()=>navigation.goBack("Tab")}>返回首页</Text>
  33. ),
  34. })
  35.  
  36. // 构造
  37. constructor(props) {
  38. super(props);
  39. // 初始状态
  40. for(start = 0;start<20;start++){
  41. var obj = {}
  42. obj.key = start
  43. dataAry.push(obj)
  44. }
  45.  
  46. this.state = {
  47. opacity:0,
  48. dataAry: dataAry,
  49. };
  50. }
  51. render() {
  52. return (
  53. <View>
  54. <FlatList
  55. onScroll = {(e)=>{this.onScroll(e)}}
  56. data = {this.state.dataAry}
  57. renderItem = {(item) => this.renderRow(item)}
  58. />
  59. <View style={{width:width,height:69,alignItems:'center',flexDirection:'row',position:'absolute',top:0,backgroundColor:'rgba(122,233,111,' + this.state.opacity + ')'}}>
  60. <Text style={{width:60,color:'red'}} onPress={()=>this.props.navigation.goBack(null)}>返回</Text>
  61. </View>
  62. </View>
  63. );
  64. }
  65.  
  66. //listView的renderRow
  67. renderRow =(item) =>{
  68. return(
  69. <View style={{flexDirection:'row',marginTop:5,marginLeft:5,borderWidth:1,marginRight:5,borderColor:'#DEDEDE',backgroundColor:'white'}}>
  70. <Image source={require('../image/one_selected.png')} style={{width:60,height:60,borderRadius:30,marginTop:5,marginBottom:5}}/>
  71. <View style={{flexDirection:'column',justifyContent:'space-around',marginLeft:5}}>
  72. <Text style={{fontSize:16}}>歌名: 彩虹彼岸</Text>
  73. <View style={{flexDirection:'row'}}>
  74. <Text style={{fontSize:14,color:'#BDBDBD'}}>歌手:虚拟歌姬</Text>
  75. <Text style={{fontSize:14,color:'#BDBDBD',marginLeft:10}}>专辑:react native</Text>
  76. </View>
  77. </View>
  78. </View>
  79. )
  80. }
  81. onScroll =(e) =>{
  82. let y = e.nativeEvent.contentOffset.y;
  83. if(y < 10 ){
  84. this.setState({
  85. opacity:0
  86. })
  87. }else if( y <= 69 && y>= 10){
  88. console.log(y/100)
  89. this.setState({
  90. opacity:y/100
  91. })
  92. }else {
  93. this.setState({
  94. opacity:1
  95. })
  96. }
  97. }
  98.  
  99. };
  100.  
  101. var styles = StyleSheet.create({
  102. container: {
  103. flex: 1,
  104. backgroundColor: '#F5FCFF',
  105. },
  106. welcome: {
  107. fontSize: 20,
  108. textAlign: 'center',
  109. margin: 10,
  110. },
  111. instructions: {
  112. textAlign: 'center',
  113. color: '#333333',
  114. marginBottom: 5,
  115. }
  116. });

3.通讯录采用三方库即可满足.https://github.com/sunnylqm/react-native-alphabetlistview

4.卡片式轮播采用三方库即可满足.https://github.com/archriss/react-native-snap-carousel

5.时间轴效果. 该效果采用FlatList打造即可.

  1.  
  1. /**
    * Created by shaotingzhou on 2017/7/10.
    */
    import React, { Component } from 'react';
    import {
    AppRegistry,
    StyleSheet,
    Text,
    View,
    FlatList,
    Dimensions,
    Image
    } from 'react-native';
    var {width,height} = Dimensions.get('window');
    var dataAry = []
    import data from './data.json'
    export default class TimerShaft extends Component {
    // 构造
    constructor(props) {
    super(props);
    // 初始状态
    this.state = {
    dataAry: dataAry,
    };
    }
  2.  
  3. render() {
    return (
    <View style={{marginTop:30}}>
    <FlatList
    data = {this.state.dataAry}
    renderItem = {(item) => this.renderRow(item)}
    keyExtractor={this.keyExtractor}
    />
    <View style={{width:1,height:height,backgroundColor:'red',position:'absolute',left:50}}></View>
    </View>
    );
    }
  4.  
  5. renderRow =(item) =>{
    if(item.item.text){
    return(
    <View style={{marginBottom:10,marginLeft:60}}>
    <Text>{item.item.text}</Text>
    </View>
    )
    }else{
    return(
    <View style={{flexDirection:'row',marginBottom:10}}>
    {/*左边*/}
    <View style={{width:60,marginBottom:10}}>
    <View style={{flexDirection:'row',alignItems:'center'}}>
    <Text>{item.item.time}</Text>
    <View style={{width:10,height:10,borderRadius:5,backgroundColor:'red',position:'absolute',left:45}}></View>
    </View>
    </View>
    {/*右边*/}
    <View style={{backgroundColor:"#F2F2F2",marginLeft:5,width:width-70}} onLayout = {(event)=>this.onLayout(event)} >
    <Text style={{}}>{item.item.content}</Text>
    <View style={{flexDirection:'row',flexWrap:'wrap'}}>
    {this.renderImg(item.item.image)}
    </View>
    </View>
    </View>
    )
  6.  
  7. }
  8.  
  9. }
  10.  
  11. keyExtractor(item: Object, index: number) {
    return item.id
    }
  12.  
  13. onLayout = (event)=>{
    console.log(event.nativeEvent.layout.height)
    }
  14.  
  15. renderImg = (imgAry) =>{
    var renderAry = []
    for(var i = 0;i < imgAry.length; i++){
    if(imgAry.length == 1){
    renderAry.push(
    <Image key={i} source={{uri:imgAry[0].url}} style={{width:200,height:200}}/>
    )
    }else if(imgAry.length == 2 || imgAry.length == 4){
    renderAry.push(
    <Image key={i} source={{uri:imgAry[i].url}} style={{width:(width-70)*0.5-2,height:(width-70)*0.5-2,marginLeft:1,marginTop:1}}/>
    )
    }else {
    renderAry.push(
    <Image key={i} source={{uri:imgAry[i].url}} style={{width:(width-70)/3-2,height:(width-70)/3-2,marginLeft:1,marginTop:1}}/>
    )
    }
    }
  16.  
  17. return renderAry
    }
  18.  
  19. componentDidMount() {
    this.setState({
    dataAry:data
    })
    }
    }
  20.  
  21. 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,
    },
    });
  1.  

这个是数据:

  1. [
  2. {
  3. "id":1,
  4. "time":"01-05",
  5. "content":"今天,带二哈去节育,再不节育的话,就要被泰迪榨干了(ps:只有累死的牛,没有耕坏的地),关键一路上,那只小区里面的泰迪一路尾随.....这..这个.这是哪个女人养的泰迪,请告诉我你的职业和联系方式,你对我二哈做的,我十倍还你!!!夕阳西下,俩狗一路走,二哈好像知道自己的下场,一脸委屈的看着我,就像许仙看法海似得看着我,二哈,不是哥不成全你们俩,而是哥看着你心疼啊...........",
  6. "image":[
  7. {
  8. "imageId":47,
  9. "url":"https://ws1.sinaimg.cn/mw690/610dc034ly1ffwb7npldpj20u00u076z.jpg"
  10. }
  11. ]
  12. },
  13. {
  14. "id":2,
  15. "time":"01-04",
  16. "content":"今天在家躺尸,二哈在家吃刚买的狗粮,我蹲在旁边看着它吃,二哈看看我,看看碗,于是往旁边挪了挪",
  17. "image":[
  18. {
  19. "imageId":3,
  20. "url":"https://ws1.sinaimg.cn/large/610dc034gy1fh9utulf4kj20u011itbo.jpg"
  21. },
  22. {
  23. "imageId":4,
  24. "url":"https://ws1.sinaimg.cn/large/610dc034ly1fh8ox6bmjlj20u00u0mz7.jpg"
  25. },
  26. {
  27. "imageId":5,
  28. "url":"https://ws1.sinaimg.cn/large/610dc034ly1fh7hwi9lhzj20u011hqa9.jpg"
  29. },
  30. {
  31. "imageId":6,
  32. "url":"https://ws1.sinaimg.cn/large/610dc034ly1fgj7jho031j20u011itci.jpg"
  33. }
  34. ]
  35. },
  36. {
  37. "id":3,
  38. "time":"01-03",
  39. "content":"今天上班,把狗丢在家里,回来家没了~~~",
  40. "image":[
  41. {
  42. "imageId":7,
  43. "url":"https://ws1.sinaimg.cn/large/610dc034ly1fgi3vd6irmj20u011i439.jpg"
  44. },
  45. {
  46. "imageId":8,
  47. "url":"https://ws1.sinaimg.cn/large/610dc034ly1fgepc1lpvfj20u011i0wv.jpg"
  48. },
  49. {
  50. "imageId":9,
  51. "url":"https://ws1.sinaimg.cn/large/610dc034ly1fgchgnfn7dj20u00uvgnj.jpg"
  52. },
  53. {
  54. "imageId":10,
  55. "url":"https://ws1.sinaimg.cn/large/610dc034ly1fga6auw8ycj20u00u00uw.jpg"
  56. },
  57. {
  58. "imageId":11,
  59. "url":"https://ws1.sinaimg.cn/large/d23c7564ly1fg7ow5jtl9j20pb0pb4gw.jpg"
  60. },
  61. {
  62. "imageId":12,
  63. "url":"https://ws1.sinaimg.cn/large/610dc034ly1fgepc1lpvfj20u011i0wv.jpg"
  64. },
  65. {
  66. "imageId":13,
  67. "url":"https://ws1.sinaimg.cn/large/d23c7564ly1fg6qckyqxkj20u00zmaf1.jpg"
  68. },
  69. {
  70. "imageId":14,
  71. "url":"https://ws1.sinaimg.cn/large/610dc034ly1ffyp4g2vwxj20u00tu77b.jpg"
  72. },
  73. {
  74. "imageId":15,
  75. "url":"https://ws1.sinaimg.cn/large/610dc034ly1ffxjlvinj5j20u011igri.jpg"
  76. }
  77. ]
  78. },
  79. {
  80. "id":4,
  81. "time":"01-02",
  82. "content":"今天是2017年的第二天,两只单身狗在家附近的公园里的亭子躲雨,然后,来了只泰迪.然后亭子里就剩一只单身狗了(ps:我
  83. React Native 继续学习的更多相关文章

      1. React Native 常用学习链接地址
      1. Android Studio下载http://www.android-studio.org/ 第二章:Android Studio概述(一)http://ask.android-studio.org/ ...

      1. react native进一步学习(NavigatorIOS 学习)
      1. 特别申明:本人代码不作为任何商业的用途,只是个人学习的一些心得,为了使得后来的更多的程序员少走一些弯路.*(如若侵犯你的版权还望见谅)*. 开发工具:WebStorm,xcode 1. rn的创建的时 ...

      1. React Native 【学习总结】-【常用命令】
      1. 前言 刚接触RN,相信很多人无从下手,不知道下一步要干什么,能干什么,本次学习围绕这个问题,将RN的常用命令总结一下,帮助你快速上手 架构理解 光知道命令的作用,远远不够,如果知道命令背后的意义,才能 ...

      1. React Native的学习资源网址
      1. react官方文档(英文): https://facebook.github.io/react/docs/getting-started.html   react中文社区(内部有视频教程等): htt ...

      1. react native 常用学习或查资料网址
      1. react-native facebook官网:http://facebook.github.io/react-native/中文网:http://reactnative.cn/ react 官网地址 ...

      1. [转] 学习React Native必看的几个开源项目
      1. http://www.lcode.org/study-react-native-opensource-one/ http://gold.xitu.io/entry/575f498c128fe10057 ...

      1. React Native环境配置之Windows版本搭建
      1. 接近年底了,回想这一年都做了啥,学习了啥,然后突然发现,这一年买了不少书,看是看了,就没有完整看完的.悲催. 然后,最近项目也不是很紧了,所以抽空学习了H5.自学啃书还是很无趣的,虽然Head Fir ...

      1. React Native开发入门
      1. 目录: 一.前言 二.什么是React Native 三.开发环境搭建 四.预备知识 五.最简单的React Native小程序 六.总结 七.参考资料   一.前言 虽然只是简单的了解了一下Reac ...

      1. 史上最详细Windows版本搭建安装React Native环境配置 转载,比官网的靠谱亲测可用
      1. 史上最详细Windows版本搭建安装React Native环境配置   2016/01/29 |  React Native技术文章 |  Sky丶清|  95条评论 |  33530 views ...

    1.  
    2. 随机推荐

        1. 【题解】Luogu P4588 [TJOI2018]数学计算
        1. 原题传送门 这题是线段树的模板题 显而易见,直接模拟是不好模拟的(取模后就不好再除了) 我们按照时间来建一颗线段树 线段树初始值都为1,用来维护乘积 第一种操作就在当前时间所对应的节点上把乘数改成m ...

        1. bzoj 1835 base 基站选址 - 动态规划 - 线段树
        1. 题目传送门 需要高级权限的传送门 题目大意 有$n$个村庄坐落在一条直线上,第$i \ \ \ (i>1)$个村庄距离第$1$个村庄的距离为$D_i$.需要在这些村庄中建立不超过$K$个通讯基站 ...

        1. bzoj 4358 Permu - 莫队算法 - 链表
        1. 题目传送门 需要高级权限的传送门 题目大意 给定一个全排列,询问一个区间内的值域连续的一段的长度的最大值. 考虑使用莫队算法. 每次插入一个数$x$,对值域的影响可以分成4种情况: $x - 1$, ...

        1. 马上AI全球挑战者大赛-违约用户风险预测
        1. 方案概述 近年来,互联网金融已经是当今社会上的一个金融发展趋势.在金融领域,无论是投资理财还是借贷放款,风险控制永远是业务的核心基础.对于消费金融来说,其主要服务对象的特点是:额度小.人群大.周期短, ...

        1. 【Git】git error记录之 "unpacking the sent packfile failed on the remote"
        1. 错误信息: error: cannot open .git/FETCH_HEAD: Permission denied unpacking the sent packfile failed on th ...

        1. Learning-Python【13】:迭代器和生成器
        1. 一.什么是迭代器 迭代指的是一个重复的过程,每一次重复都是基于上一次的结果而来的 # 这里的循环也是一个迭代,每次基于上一次的结果而取值 li = 'hello' i = 0 while i < ...

        1. 使用Rancher和私有仓库快速搭建Kubernetes集群
        1. 来来来,先出题:Rancher可以快速部署Kubernetes,但其使用的gcr.io上的镜像无法下载怎么办?使用Rancher可以快速部署Kubernetes,但我们需要下载哪些镜像?Rancher ...

        1. JS中for in 与 for of
        1. // 数组var A=[4,6,74,67]; for in:拿到的是数组下标 for (let i in A){ console.log(i); } //0,1,2,3 for of:拿到的是数组元 ...

        1. postman(五):在不同接口之间传递数据
        1. 为了更灵活地构造请求以及处理响应数据,postman提供了Pre-request-Script和Tests,在这两个标签中可以编写js代码辅助测试.之前学习了在发送请求的Tests标签如何添加断言以及 ...

        1. z2-xcode使用
        1. @xcode区块命名 左边导航栏,右边工具栏,下边调试栏 @快捷键 最常用的#显示/隐藏导航栏:Command+ (反选一样Command+) #显示/隐藏工具栏:Command+Option+ (反 ...