forked from race604/ZhiHuDaily-React-Native
-
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
Showing
5 changed files
with
605 additions
and
13 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,102 @@ | ||
'use strict'; | ||
|
||
var React = require('react-native'); | ||
var { | ||
Dimensions, | ||
StyleSheet, | ||
Text, | ||
TouchableOpacity, | ||
View, | ||
Animated, | ||
} = React; | ||
|
||
var deviceWidth = Dimensions.get('window').width; | ||
var DOT_SIZE = 6; | ||
var DOT_SAPCE = 3; | ||
|
||
var styles = StyleSheet.create({ | ||
tab: { | ||
alignItems: 'center', | ||
}, | ||
|
||
tabs: { | ||
flexDirection: 'row', | ||
alignItems: 'center', | ||
justifyContent: 'center', | ||
}, | ||
|
||
dot: { | ||
width: DOT_SIZE, | ||
height: DOT_SIZE, | ||
borderRadius: DOT_SIZE / 2, | ||
backgroundColor: 'rgba(100,100,100,0.5)', | ||
marginLeft: DOT_SAPCE, | ||
marginRight: DOT_SAPCE, | ||
}, | ||
|
||
curDot: { | ||
position: 'absolute', | ||
width: DOT_SIZE, | ||
height: DOT_SIZE, | ||
borderRadius: DOT_SIZE / 2, | ||
backgroundColor: 'rgba(250,250,250,0.8)', | ||
margin: DOT_SAPCE, | ||
bottom: 0, | ||
}, | ||
}); | ||
|
||
var DefaultViewPageIndicator = React.createClass({ | ||
propTypes: { | ||
goToPage: React.PropTypes.func, | ||
activePage: React.PropTypes.number, | ||
pageCount: React.PropTypes.number | ||
}, | ||
|
||
getInitialState() { | ||
return { | ||
viewWidth: 0, | ||
}; | ||
}, | ||
|
||
renderIndicator(page) { | ||
//var isTabActive = this.props.activePage === page; | ||
return ( | ||
<TouchableOpacity style={styles.tab} key={'idc_' + page} onPress={() => this.props.goToPage(page)}> | ||
<View style={styles.dot} /> | ||
</TouchableOpacity> | ||
); | ||
}, | ||
|
||
render() { | ||
var pageCount = this.props.pageCount; | ||
var itemWidth = DOT_SIZE + (DOT_SAPCE * 2); | ||
var offset = (this.state.viewWidth - itemWidth * pageCount) / 2 + itemWidth * this.props.activePage; | ||
|
||
var left = offset; /*this.state.offsetX.interpolate({ | ||
inputRange: [0, 1], outputRange: [0, offset] | ||
});*/ | ||
|
||
var indicators = []; | ||
for (var i = 0; i < pageCount; i++) { | ||
indicators.push(this.renderIndicator(i)) | ||
} | ||
|
||
return ( | ||
<View style={styles.tabs} | ||
onLayout={(event) => { | ||
var viewWidth = event.nativeEvent.layout.width; | ||
if (!viewWidth || this.state.viewWidth === viewWidth) { | ||
return; | ||
} | ||
this.setState({ | ||
viewWidth: viewWidth, | ||
}); | ||
}}> | ||
{indicators} | ||
<Animated.View style={[styles.curDot, {left}]} /> | ||
</View> | ||
); | ||
}, | ||
}); | ||
|
||
module.exports = DefaultViewPageIndicator; |
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
Oops, something went wrong.