This repository has been archived by the owner on Jan 12, 2023. It is now read-only.
/
PageControlIOS.ios.js
96 lines (78 loc) · 2.18 KB
/
PageControlIOS.ios.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
'use strict';
/**
* @providesModule PageControlIOS
*/
import React from 'react';
import {
Dimensions,
NativeModules,
requireNativeComponent,
StyleSheet,
ViewPropTypes,
} from 'react-native';
import PropTypes from 'prop-types';
class PageControlIOS extends React.PureComponent {
constructor(props) {
super(props);
this._onChange = this._onChange.bind(this);
}
render() {
return (
<RCTPageControl
{...this.props}
onChange={this._onChange}
style={[styles.PageControlIOS, this.props.style]}
/>
);
}
/**
* Handle PageControl change event
* @param {Event} event
* @private
*/
_onChange(event) {
this.props.onChange && this.props.onChange(event);
this.props.onValueChange && this.props.onValueChange(event.nativeEvent.currentPage);
}
}
PageControlIOS.propTypes = {
...ViewPropTypes,
/**
* The current page, shown by the receiver as a white dot.
*/
currentPage: PropTypes.number,
/**
* The number of pages the receiver shows (as dots).
*/
numberOfPages: PropTypes.number,
/**
* A Boolean value that controls whether the page control is hidden when there is only one page.
*/
hidesForSinglePage: PropTypes.bool,
/**
* The tint color to be used for the page indicator.
*/
pageIndicatorTintColor: PropTypes.string,
/**
* The tint color to be used for the current page indicator.
*/
currentPageIndicatorTintColor: PropTypes.string,
/**
* Callback that is called when the user taps a PageControl;
* passes the event as an argument
*/
onChange: PropTypes.func,
/**
* Callback that is called when the user taps a PageControl;
* passes the currentPage value as an argument
*/
onValueChange: PropTypes.func,
};
const styles = StyleSheet.create({
PageControlIOS: {
height: NativeModules.PageControlManager.ComponentHeight,
width: Dimensions.get('window').width,
},
});
const RCTPageControl = requireNativeComponent('RCTPageControl', PageControlIOS);
export default PageControlIOS;