參考資料:http://www.cnblogs.com/shaoting/p/7148240.html 下一個項目公司也打算使用react native.大致看了下原型設計,寫幾個小demo先試試水.特此記錄下. 1.微信及朋友圈分享.QQ及朋友圈分享,微博分享,微信支付,支付寶支付. 2.導航條漸 ...
參考資料:http://www.cnblogs.com/shaoting/p/7148240.html
下一個項目公司也打算使用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 分享功能封裝【一行代碼,雙平臺分享】 支持平臺:【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, 50 }; 51 } 52 render() { 53 return ( 54 <View> 55 <FlatList 56 onScroll = {(e)=>{this.onScroll(e)}} 57 data = {this.state.dataAry} 58 renderItem = {(item) => this.renderRow(item)} 59 /> 60 <View style={{width:width,height:69,alignItems:'center',flexDirection:'row',position:'absolute',top:0,backgroundColor:'rgba(122,233,111,' + this.state.opacity + ')'}}> 61 <Text style={{width:60,color:'red'}} onPress={()=>this.props.navigation.goBack(null)}>返回</Text> 62 </View> 63 </View> 64 ); 65 } 66 67 //listView的renderRow 68 renderRow =(item) =>{ 69 return( 70 <View style={{flexDirection:'row',marginTop:5,marginLeft:5,borderWidth:1,marginRight:5,borderColor:'#DEDEDE',backgroundColor:'white'}}> 71 <Image source={require('../image/one_selected.png')} style={{width:60,height:60,borderRadius:30,marginTop:5,marginBottom:5}}/> 72 <View style={{flexDirection:'column',justifyContent:'space-around',marginLeft:5}}> 73 <Text style={{fontSize:16}}>歌名: 彩虹彼岸</Text> 74 <View style={{flexDirection:'row'}}> 75 <Text style={{fontSize:14,color:'#BDBDBD'}}>歌手:虛擬歌姬</Text> 76 <Text style={{fontSize:14,color:'#BDBDBD',marginLeft:10}}>專輯:react native</Text> 77 </View> 78 </View> 79 </View> 80 ) 81 } 82 onScroll =(e) =>{ 83 let y = e.nativeEvent.contentOffset.y; 84 if(y < 10 ){ 85 this.setState({ 86 opacity:0 87 }) 88 }else if( y <= 69 && y>= 10){ 89 console.log(y/100) 90 this.setState({ 91 opacity:y/100 92 }) 93 }else { 94 this.setState({ 95 opacity:1 96 }) 97 } 98 } 99 100 }; 101 102 var styles = StyleSheet.create({ 103 container: { 104 flex: 1, 105 backgroundColor: '#F5FCFF', 106 }, 107 welcome: { 108 fontSize: 20, 109 textAlign: 'center', 110 margin: 10, 111 }, 112 instructions: { 113 textAlign: 'center', 114 color: '#333333', 115 marginBottom: 5, 116 } 117 });
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,
},
});這個是數據: