-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
horizon0514
authored and
horizon0514
committed
Dec 12, 2015
1 parent
ff88255
commit 63f8813
Showing
4 changed files
with
147 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
/* | ||
* 封装ViewPager | ||
*/ | ||
'use strict'; | ||
|
||
var React = require('react-native'); | ||
var ViewPager = require('react-native-viewpager'); | ||
|
||
|
||
|
||
var { | ||
View, | ||
Text, | ||
StyleSheet, | ||
Dimensions, | ||
Component, | ||
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) | ||
}); | ||
} | ||
|
||
_renderPage(data,pageId){ | ||
console.log(data); | ||
return ( | ||
<Image | ||
source={{uri: data.image}} | ||
style={styles.page} /> | ||
); | ||
} | ||
|
||
render(){ | ||
console.log('render slider'); | ||
console.log(this.props); | ||
return ( | ||
<ViewPager | ||
style={{flex:1,height: 200}} | ||
dataSource={this.state.dataSource} | ||
renderPage={this._renderPage} | ||
isLoop={true} | ||
autoPlay={true}/> | ||
); | ||
} | ||
} | ||
|
||
var styles = StyleSheet.create({ | ||
page: { | ||
height: 200, | ||
width: deviceWidth, | ||
|
||
}, | ||
|
||
}); | ||
|
||
module.exports = Slider; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters