Skip to content

Commit f7f894d

Browse files
committed
Add hideSingle prop which, if true, will not show the indicator when there's only one page.
1 parent 609d74d commit f7f894d

File tree

1 file changed

+10
-7
lines changed

1 file changed

+10
-7
lines changed

viewpager/indicator/PagerDotIndicator.js

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,14 @@ export default class PagerDotIndicator extends Component {
1515
initialPage: PropTypes.number,
1616
pager: PropTypes.instanceOf(IndicatorViewPager),
1717
dotStyle: View.propTypes.style,
18-
selectedDotStyle: View.propTypes.style
18+
selectedDotStyle: View.propTypes.style,
19+
hideSingle: React.PropTypes.bool
1920
}
2021

2122
static defaultProps = {
2223
pageCount: 0,
23-
initialPage: 0
24+
initialPage: 0,
25+
hideSingle: false
2426
}
2527

2628
state = {
@@ -35,10 +37,11 @@ export default class PagerDotIndicator extends Component {
3537
this.props.style != nextProps.style
3638
}
3739

38-
render () {
39-
let {pageCount, dotStyle, selectedDotStyle} = this.props
40-
if (pageCount <= 0)return null
41-
let dotsView = []
40+
render() {
41+
let {pageCount, dotStyle, selectedDotStyle}=this.props;
42+
if (pageCount <= 0)return null;
43+
if (this.props.hideSingle && pageCount == 1) return null;
44+
let dotsView = [];
4245
for (let i = 0; i < pageCount; i++) {
4346
let isSelect = i === this.state.selectedIndex
4447
dotsView.push(
@@ -79,4 +82,4 @@ const styles = StyleSheet.create({
7982
selectDot: {
8083
backgroundColor: 'white'
8184
}
82-
})
85+
})

0 commit comments

Comments
 (0)