-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSlider.js
106 lines (84 loc) · 1.76 KB
/
Slider.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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
/*
* 封装ViewPager
*/
'use strict';
var React = require('react-native');
var ViewPager = require('react-native-viewpager');
var StoryView = require('./Story');
var {
View,
Text,
StyleSheet,
Dimensions,
Component,
TouchableHighlight,
Image,
} = React;
var deviceWidth = Dimensions.get('window').width;
class Slider extends Component{
constructor(props){
super(props);
this.state={
dataSource: new ViewPager.DataSource({
pageHasChanged: (p1, p2) => p1 !== p2})
};
}
componentDidMount(){
this.setState({
dataSource: this.state.dataSource.cloneWithPages(this.props.dataSource)
});
}
_onPress(id){
this.props.navigator.push({
name: '',
component: StoryView,
passProps: {storyId: id}
});
}
_renderPage(data,pageId){
return (
// <TouchableHighlight onPress=()=>this._onPress(data)>
<View style={styles.container}>
<Image
source={{uri: data.image}}
style={styles.page}>
<View style={styles.titleContainer}>
<Text style={styles.title}>{data.title}</Text>
</View>
</Image>
</View>
// </TouchableHighlight>
);
}
render(){
return (
<ViewPager
style={this.props.style}
dataSource={this.state.dataSource}
renderPage={this._renderPage}
isLoop={true}
autoPlay={true}/>
);
}
}
var styles = StyleSheet.create({
container: {
},
page: {
height: 200,
width: deviceWidth,
},
titleContainer: {
flex: 1,
padding: 20,
},
title: {
color: '#ffffff',
fontSize: 20,
fontWeight : 'bold',
position: 'absolute',
bottom: 20,
//backgroundColor: 'transparent',
}
});
module.exports = Slider;