React Native 继续学习
下一个项目公司也打算使用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,但是该库的导航条使用不了渐隐,于是只能在需要导航条渐隐的地方,改用自己定义的导航条.
基本代码如下:
/**
* Created by shaotingzhou on 2017/5/9.
*/
import React, { Component } from 'react';
import {
AppRegistry,
StyleSheet,
Text,
View,
Image,
TouchableOpacity,
Platform,
Dimensions,
RefreshControl,
FlatList,
ActivityIndicator,
ScrollView,
TextInput
} from 'react-native';
var {width,height} = Dimensions.get('window');
var dataAry = []
var start = 0 export default class OneDetailsFlat extends Component{
//返回首页方法需要修改react-navigation库的源码.修改方法见:http://www.jianshu.com/p/2f575cc35780
static navigationOptions = ({ navigation }) => ({
header:null,
title: 'FlatList',
headerStyle:{backgroundColor:'rgba(255,255,255,0.0)'},
headerTintColor: 'black',
headerLeft:(
<Text onPress={()=>navigation.goBack("Tab")}>返回首页</Text>
),
}) // 构造
constructor(props) {
super(props);
// 初始状态
for(start = 0;start<20;start++){
var obj = {}
obj.key = start
dataAry.push(obj)
} this.state = {
opacity:0,
dataAry: dataAry,
};
}
render() {
return (
<View>
<FlatList
onScroll = {(e)=>{this.onScroll(e)}}
data = {this.state.dataAry}
renderItem = {(item) => this.renderRow(item)}
/>
<View style={{width:width,height:69,alignItems:'center',flexDirection:'row',position:'absolute',top:0,backgroundColor:'rgba(122,233,111,' + this.state.opacity + ')'}}>
<Text style={{width:60,color:'red'}} onPress={()=>this.props.navigation.goBack(null)}>返回</Text>
</View>
</View>
);
} //listView的renderRow
renderRow =(item) =>{
return(
<View style={{flexDirection:'row',marginTop:5,marginLeft:5,borderWidth:1,marginRight:5,borderColor:'#DEDEDE',backgroundColor:'white'}}>
<Image source={require('../image/one_selected.png')} style={{width:60,height:60,borderRadius:30,marginTop:5,marginBottom:5}}/>
<View style={{flexDirection:'column',justifyContent:'space-around',marginLeft:5}}>
<Text style={{fontSize:16}}>歌名: 彩虹彼岸</Text>
<View style={{flexDirection:'row'}}>
<Text style={{fontSize:14,color:'#BDBDBD'}}>歌手:虚拟歌姬</Text>
<Text style={{fontSize:14,color:'#BDBDBD',marginLeft:10}}>专辑:react native</Text>
</View>
</View>
</View>
)
}
onScroll =(e) =>{
let y = e.nativeEvent.contentOffset.y;
if(y < 10 ){
this.setState({
opacity:0
})
}else if( y <= 69 && y>= 10){
console.log(y/100)
this.setState({
opacity:y/100
})
}else {
this.setState({
opacity:1
})
}
} }; var styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: '#F5FCFF',
},
welcome: {
fontSize: 20,
textAlign: 'center',
margin: 10,
},
instructions: {
textAlign: 'center',
color: '#333333',
marginBottom: 5,
}
});
3.通讯录采用三方库即可满足.https://github.com/sunnylqm/react-native-alphabetlistview
4.卡片式轮播采用三方库即可满足.https://github.com/archriss/react-native-snap-carousel
5.时间轴效果. 该效果采用FlatList打造即可.
/**
* 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,
};
} 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>
);
} 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>
) } } keyExtractor(item: Object, index: number) {
return item.id
} onLayout = (event)=>{
console.log(event.nativeEvent.layout.height)
} 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}}/>
)
}
} return renderAry
} componentDidMount() {
this.setState({
dataAry:data
})
}
} 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,
},
});
这个是数据:
[
{
"id":1,
"time":"01-05",
"content":"今天,带二哈去节育,再不节育的话,就要被泰迪榨干了(ps:只有累死的牛,没有耕坏的地),关键一路上,那只小区里面的泰迪一路尾随.....这..这个.这是哪个女人养的泰迪,请告诉我你的职业和联系方式,你对我二哈做的,我十倍还你!!!夕阳西下,俩狗一路走,二哈好像知道自己的下场,一脸委屈的看着我,就像许仙看法海似得看着我,二哈,不是哥不成全你们俩,而是哥看着你心疼啊...........",
"image":[
{
"imageId":47,
"url":"https://ws1.sinaimg.cn/mw690/610dc034ly1ffwb7npldpj20u00u076z.jpg"
}
]
},
{
"id":2,
"time":"01-04",
"content":"今天在家躺尸,二哈在家吃刚买的狗粮,我蹲在旁边看着它吃,二哈看看我,看看碗,于是往旁边挪了挪",
"image":[
{
"imageId":3,
"url":"https://ws1.sinaimg.cn/large/610dc034gy1fh9utulf4kj20u011itbo.jpg"
},
{
"imageId":4,
"url":"https://ws1.sinaimg.cn/large/610dc034ly1fh8ox6bmjlj20u00u0mz7.jpg"
},
{
"imageId":5,
"url":"https://ws1.sinaimg.cn/large/610dc034ly1fh7hwi9lhzj20u011hqa9.jpg"
},
{
"imageId":6,
"url":"https://ws1.sinaimg.cn/large/610dc034ly1fgj7jho031j20u011itci.jpg"
}
]
},
{
"id":3,
"time":"01-03",
"content":"今天上班,把狗丢在家里,回来家没了~~~",
"image":[
{
"imageId":7,
"url":"https://ws1.sinaimg.cn/large/610dc034ly1fgi3vd6irmj20u011i439.jpg"
},
{
"imageId":8,
"url":"https://ws1.sinaimg.cn/large/610dc034ly1fgepc1lpvfj20u011i0wv.jpg"
},
{
"imageId":9,
"url":"https://ws1.sinaimg.cn/large/610dc034ly1fgchgnfn7dj20u00uvgnj.jpg"
},
{
"imageId":10,
"url":"https://ws1.sinaimg.cn/large/610dc034ly1fga6auw8ycj20u00u00uw.jpg"
},
{
"imageId":11,
"url":"https://ws1.sinaimg.cn/large/d23c7564ly1fg7ow5jtl9j20pb0pb4gw.jpg"
},
{
"imageId":12,
"url":"https://ws1.sinaimg.cn/large/610dc034ly1fgepc1lpvfj20u011i0wv.jpg"
},
{
"imageId":13,
"url":"https://ws1.sinaimg.cn/large/d23c7564ly1fg6qckyqxkj20u00zmaf1.jpg"
},
{
"imageId":14,
"url":"https://ws1.sinaimg.cn/large/610dc034ly1ffyp4g2vwxj20u00tu77b.jpg"
},
{
"imageId":15,
"url":"https://ws1.sinaimg.cn/large/610dc034ly1ffxjlvinj5j20u011igri.jpg"
}
]
},
{
"id":4,
"time":"01-02",
"content":"今天是2017年的第二天,两只单身狗在家附近的公园里的亭子躲雨,然后,来了只泰迪.然后亭子里就剩一只单身狗了(ps:我React Native 继续学习的更多相关文章
- React Native 常用学习链接地址
Android Studio下载http://www.android-studio.org/ 第二章:Android Studio概述(一)http://ask.android-studio.org/ ...
- react native进一步学习(NavigatorIOS 学习)
特别申明:本人代码不作为任何商业的用途,只是个人学习的一些心得,为了使得后来的更多的程序员少走一些弯路.*(如若侵犯你的版权还望见谅)*. 开发工具:WebStorm,xcode 1. rn的创建的时 ...
- React Native 【学习总结】-【常用命令】
前言 刚接触RN,相信很多人无从下手,不知道下一步要干什么,能干什么,本次学习围绕这个问题,将RN的常用命令总结一下,帮助你快速上手 架构理解 光知道命令的作用,远远不够,如果知道命令背后的意义,才能 ...
- React Native的学习资源网址
react官方文档(英文): https://facebook.github.io/react/docs/getting-started.html react中文社区(内部有视频教程等): htt ...
- react native 常用学习或查资料网址
react-native facebook官网:http://facebook.github.io/react-native/中文网:http://reactnative.cn/ react 官网地址 ...
- [转] 学习React Native必看的几个开源项目
http://www.lcode.org/study-react-native-opensource-one/ http://gold.xitu.io/entry/575f498c128fe10057 ...
- React Native环境配置之Windows版本搭建
接近年底了,回想这一年都做了啥,学习了啥,然后突然发现,这一年买了不少书,看是看了,就没有完整看完的.悲催. 然后,最近项目也不是很紧了,所以抽空学习了H5.自学啃书还是很无趣的,虽然Head Fir ...
- React Native开发入门
目录: 一.前言 二.什么是React Native 三.开发环境搭建 四.预备知识 五.最简单的React Native小程序 六.总结 七.参考资料 一.前言 虽然只是简单的了解了一下Reac ...
- 史上最详细Windows版本搭建安装React Native环境配置 转载,比官网的靠谱亲测可用
史上最详细Windows版本搭建安装React Native环境配置 2016/01/29 | React Native技术文章 | Sky丶清| 95条评论 | 33530 views ...
随机推荐
- Keepalived原理与实战精讲--VRRP协议
. 前言 VRRP(Virtual Router Redundancy Protocol)协议是用于实现路由器冗余的协议,最新协议在RFC3768中定义,原来的定义RFC2338被废除,新协议相对还简 ...
- redis编译问题
在编译redis时,出现以下问题 In file included from adlist.c:34:0: zmalloc.h:50:31: fatal error: jemalloc/jemallo ...
- Failed to auto-configure a DataSource: 'spring.datasource.url' is not specified and no embedded datasource could be auto-configured.
从报错信息中,我们就可以分析出错误原因是触发了数据源的自动化配置,然而当前项目其实并不需要数据源.查其根源是依赖方提供的API依赖中引用了一些多余的依赖触发了该自动化配置的加载. 如何解决 为了解决上 ...
- C#以太坊基础入门
在这一部分,我们将使用C#开发一个最简单的.Net控制台应用,来接入以太坊节点,并打印 所连接节点旳版本信息.通过这一部分的学习,你将掌握以下技能: 如何使用节点仿真器 如何在命令行访问以太坊节点 如 ...
- buntu下cutecom图像界面串口调试工具使用
一.安装,首先下载这个软件,终端和软件中心均可下载,终端下载命令: sudo apt-get install cutecom 即可快速搞定安装问题. 软件中心: 由于我已经通过终端安装成功,所以软件中 ...
- DAY13 迭代器与生成器
一.迭代器 定义:器:包含了多个值的容器 迭代:循环反馈(一次从容器中取出一个值) 迭代器:从装有多个值的容器中一次取出一个值给外界 优点:不依赖索引,完成取值 缺点:不能计算长度,不能指定位取值(只 ...
- [Hibernate] 分页查询
@Test public void test9(){ //根据部门编号进行分组,再根据每个部门总工资>5000 Session ss=HibernateUtil.getSession(); St ...
- httpd常见配置
httpd常见配置 配置文件 /etc/httpd/conf/httpd.conf 主配置文件 /etc/httpd/conf.d/*.conf 辅助配置文件 配置文件语法检查及重新加载配置文 ...
- 记录一个下最近用tensorflow的几个坑
1, softmax_cross_entropy_with_logits 的中的logits=x*w+b,其中w应该是[nfeats,nclass],b是[nclass]是对输出的每个类上logits ...
- ABAP基础一:ALV基础之ALV的整体结构
很久没摸ECC了,最近看到很多新人在捯饬ALV...中国就喜欢量产垃圾...培训,上岗...没有行业道德... 闲话不多说,开始正事: ALV很常见,在SAP非WEB的项目,没有不用的,它包含了报表和 ...