|
@@ -1,6 +1,8 @@
|
1
|
1
|
// @flow
|
|
2
|
+
|
2
|
3
|
import React from 'react';
|
3
|
4
|
import { Text, TouchableOpacity, View, ViewPagerAndroid } from 'react-native';
|
|
5
|
+import { connect } from 'react-redux';
|
4
|
6
|
|
5
|
7
|
import { Icon } from '../../base/font-icons';
|
6
|
8
|
import { MeetingList } from '../../calendar-sync';
|
|
@@ -14,24 +16,74 @@ import styles from './styles';
|
14
|
16
|
*
|
15
|
17
|
* @extends PagedList
|
16
|
18
|
*/
|
17
|
|
-export default class PagedList extends AbstractPagedList {
|
|
19
|
+class PagedList extends AbstractPagedList {
|
18
|
20
|
/**
|
19
|
21
|
* A reference to the viewpager.
|
20
|
22
|
*/
|
21
|
23
|
_viewPager: Object;
|
22
|
24
|
|
23
|
25
|
/**
|
24
|
|
- * Constructor of the PagedList Component.
|
|
26
|
+ * Initializes a new {@code PagedList} instance.
|
25
|
27
|
*
|
26
|
28
|
* @inheritdoc
|
27
|
29
|
*/
|
28
|
30
|
constructor(props) {
|
29
|
31
|
super(props);
|
30
|
32
|
|
|
33
|
+ // Bind event handlers so they are only bound once per instance.
|
31
|
34
|
this._getIndicatorStyle = this._getIndicatorStyle.bind(this);
|
32
|
35
|
this._onPageSelected = this._onPageSelected.bind(this);
|
33
|
36
|
this._onSelectPage = this._onSelectPage.bind(this);
|
34
|
|
- this._setPagerReference = this._setPagerReference.bind(this);
|
|
37
|
+ this._setViewPager = this._setViewPager.bind(this);
|
|
38
|
+ }
|
|
39
|
+
|
|
40
|
+ _getIndicatorStyle: number => Object;
|
|
41
|
+
|
|
42
|
+ /**
|
|
43
|
+ * Constructs the style of an indicator.
|
|
44
|
+ *
|
|
45
|
+ * @param {number} indicatorIndex - The index of the indicator.
|
|
46
|
+ * @private
|
|
47
|
+ * @returns {Object}
|
|
48
|
+ */
|
|
49
|
+ _getIndicatorStyle(indicatorIndex) {
|
|
50
|
+ if (this.state.pageIndex === indicatorIndex) {
|
|
51
|
+ return styles.pageIndicatorTextActive;
|
|
52
|
+ }
|
|
53
|
+
|
|
54
|
+ return null;
|
|
55
|
+ }
|
|
56
|
+
|
|
57
|
+ _onPageSelected: Object => void;
|
|
58
|
+
|
|
59
|
+ /**
|
|
60
|
+ * Updates the index of the currently selected page.
|
|
61
|
+ *
|
|
62
|
+ * @param {Object} event - The native event of the callback.
|
|
63
|
+ * @private
|
|
64
|
+ * @returns {void}
|
|
65
|
+ */
|
|
66
|
+ _onPageSelected({ nativeEvent: { position } }) {
|
|
67
|
+ if (this.state.pageIndex !== position) {
|
|
68
|
+ this._selectPage(position);
|
|
69
|
+ }
|
|
70
|
+ }
|
|
71
|
+
|
|
72
|
+ _onSelectPage: number => Function;
|
|
73
|
+
|
|
74
|
+ /**
|
|
75
|
+ * Constructs a function to be used as a callback for the tab bar.
|
|
76
|
+ *
|
|
77
|
+ * @param {number} pageIndex - The index of the page to activate via the
|
|
78
|
+ * callback.
|
|
79
|
+ * @private
|
|
80
|
+ * @returns {Function}
|
|
81
|
+ */
|
|
82
|
+ _onSelectPage(pageIndex) {
|
|
83
|
+ return () => {
|
|
84
|
+ this._viewPager.setPage(pageIndex);
|
|
85
|
+ this._selectPage(pageIndex);
|
|
86
|
+ };
|
35
|
87
|
}
|
36
|
88
|
|
37
|
89
|
/**
|
|
@@ -42,23 +94,19 @@ export default class PagedList extends AbstractPagedList {
|
42
|
94
|
* @returns {ReactElement}
|
43
|
95
|
*/
|
44
|
96
|
_renderPagedList(disabled) {
|
45
|
|
- const { pageIndex } = this.state;
|
46
|
|
-
|
47
|
97
|
return (
|
48
|
98
|
<View style = { styles.pagedListContainer }>
|
49
|
99
|
<ViewPagerAndroid
|
50
|
100
|
initialPage = { DEFAULT_PAGE }
|
51
|
101
|
onPageSelected = { this._onPageSelected }
|
52
|
102
|
peekEnabled = { true }
|
53
|
|
- ref = { this._setPagerReference }
|
|
103
|
+ ref = { this._setViewPager }
|
54
|
104
|
style = { styles.pagedList }>
|
55
|
105
|
<View key = { 0 }>
|
56
|
106
|
<RecentList disabled = { disabled } />
|
57
|
107
|
</View>
|
58
|
108
|
<View key = { 1 }>
|
59
|
|
- <MeetingList
|
60
|
|
- disabled = { disabled }
|
61
|
|
- displayed = { pageIndex === 1 } />
|
|
109
|
+ <MeetingList disabled = { disabled } />
|
62
|
110
|
</View>
|
63
|
111
|
</ViewPagerAndroid>
|
64
|
112
|
<View style = { styles.pageIndicatorContainer }>
|
|
@@ -107,69 +155,19 @@ export default class PagedList extends AbstractPagedList {
|
107
|
155
|
);
|
108
|
156
|
}
|
109
|
157
|
|
110
|
|
- _getIndicatorStyle: number => Object;
|
111
|
|
-
|
112
|
|
- /**
|
113
|
|
- * Constructs the style of an indicator.
|
114
|
|
- *
|
115
|
|
- * @private
|
116
|
|
- * @param {number} indicatorIndex - The index of the indicator.
|
117
|
|
- * @returns {Object}
|
118
|
|
- */
|
119
|
|
- _getIndicatorStyle(indicatorIndex) {
|
120
|
|
- if (this.state.pageIndex === indicatorIndex) {
|
121
|
|
- return styles.pageIndicatorTextActive;
|
122
|
|
- }
|
123
|
|
-
|
124
|
|
- return null;
|
125
|
|
- }
|
126
|
|
-
|
127
|
|
- _onPageSelected: Object => void;
|
|
158
|
+ _setViewPager: Object => void;
|
128
|
159
|
|
129
|
160
|
/**
|
130
|
|
- * Updates the index of the currently selected page.
|
|
161
|
+ * Sets the {@link ViewPagerAndroid} instance.
|
131
|
162
|
*
|
|
163
|
+ * @param {ViewPagerAndroid} viewPager - The {@code ViewPagerAndroid}
|
|
164
|
+ * instance.
|
132
|
165
|
* @private
|
133
|
|
- * @param {Object} event - The native event of the callback.
|
134
|
166
|
* @returns {void}
|
135
|
167
|
*/
|
136
|
|
- _onPageSelected({ nativeEvent: { position } }) {
|
137
|
|
- if (this.state.pageIndex !== position) {
|
138
|
|
- this.setState({
|
139
|
|
- pageIndex: position
|
140
|
|
- });
|
141
|
|
- }
|
142
|
|
- }
|
143
|
|
-
|
144
|
|
- _onSelectPage: number => Function
|
145
|
|
-
|
146
|
|
- /**
|
147
|
|
- * Constructs a function to be used as a callback for the tab bar.
|
148
|
|
- *
|
149
|
|
- * @private
|
150
|
|
- * @param {number} pageIndex - The index of the page to activate via the
|
151
|
|
- * callback.
|
152
|
|
- * @returns {Function}
|
153
|
|
- */
|
154
|
|
- _onSelectPage(pageIndex) {
|
155
|
|
- return () => {
|
156
|
|
- this._viewPager.setPage(pageIndex);
|
157
|
|
- this.setState({
|
158
|
|
- pageIndex
|
159
|
|
- });
|
160
|
|
- };
|
161
|
|
- }
|
162
|
|
-
|
163
|
|
- _setPagerReference: Object => void
|
164
|
|
-
|
165
|
|
- /**
|
166
|
|
- * Sets the pager's reference for direct modification.
|
167
|
|
- *
|
168
|
|
- * @private
|
169
|
|
- * @param {React@Node} component - The pager component.
|
170
|
|
- * @returns {void}
|
171
|
|
- */
|
172
|
|
- _setPagerReference(component) {
|
173
|
|
- this._viewPager = component;
|
|
168
|
+ _setViewPager(viewPager) {
|
|
169
|
+ this._viewPager = viewPager;
|
174
|
170
|
}
|
175
|
171
|
}
|
|
172
|
+
|
|
173
|
+export default connect()(PagedList);
|