-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
72 lines (64 loc) · 2.16 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
import React, {Component} from 'react';
import {View,Text,TouchableOpacity,ScrollView,Image,Dimensions } from "react-native"
export default class GaleryCarousel extends Component{
constructor(props){
super(props)
this.width = Dimensions.get('window').width
this.state={
defaultImageIndex:this.props.defaultImageIndex,
}
}
changeImageIndex(defaultImageIndex){
this.setState({defaultImageIndex})
}
createImages(elt,key){
const {joinFirst,getImageFrom,joinLast} = this.props
return(
<TouchableOpacity
key={key}
style={{height: (this.props.mainHeight / 3.73)}}
onPress={()=>{this.changeImageIndex(key)} }
onLongPress={()=>this.props.onLongPress(key,elt)}
>
<Image style={{height: (this.props.mainHeight / 3.73), width: 130}} source={{uri:`${joinFirst}${elt[getImageFrom]}${joinLast}`}} />
</TouchableOpacity>
)
}
render(){
const {dataImage,joinFirst,joinLast,getImageFrom,mainImageComponents} = this.props;
const {defaultImageIndex}= this.state;
if(dataImage.length>0)
return(
<View>
<View style={{height: this.props.mainHeight, padding: 0}}>
<Image source={{uri:`${joinFirst}${dataImage[defaultImageIndex][getImageFrom]}${joinLast}`}}
style={{width: this.width, height: this.props.mainHeight,flex:1}}
resizeMode='cover'>
{mainImageComponents}
</Image>
</View>
<View>
<ScrollView
ref={(scrollView) => { _scrollView = scrollView; }}
automaticallyAdjustContentInsets={false}
onScroll={() => { console.log('onScroll!'); }}
scrollEventThrottle={200}
horizontal={true}
style={{height: (this.props.mainHeight / 3.73)}}>
{dataImage.map((elt, key) => this.createImages(elt, key))}
</ScrollView>
</View>
</View>
)
if(dataImage.length==0)return (<View/>)
}
}
GaleryCarousel.defaultProps={
dataImage:[],
joinLast:'',
joinFirst:'',
defaultImageIndex:0,
mainHeight:280,
mainImageComponents:<View/>,
getImageFrom:"path"
};