@shoutem/ui 4.6.6 → 4.6.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -79,14 +79,20 @@ class YearRangePicker extends PureComponent {
|
|
|
79
79
|
}
|
|
80
80
|
|
|
81
81
|
render() {
|
|
82
|
-
const {
|
|
82
|
+
const {
|
|
83
|
+
rangeEnd,
|
|
84
|
+
rangeStart,
|
|
85
|
+
resetButtonTitle,
|
|
86
|
+
confirmButtonTitle,
|
|
87
|
+
} = this.props;
|
|
83
88
|
const { buttonTooltip, collapsed } = this.state;
|
|
84
89
|
|
|
85
90
|
return (
|
|
86
|
-
<View
|
|
91
|
+
<View>
|
|
87
92
|
<YearPickerButton
|
|
88
93
|
tooltip={buttonTooltip}
|
|
89
94
|
onPress={this.handleButtonPressed}
|
|
95
|
+
collapsed={collapsed}
|
|
90
96
|
/>
|
|
91
97
|
<YearPickerModal
|
|
92
98
|
visible={collapsed}
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import React, { PureComponent } from 'react';
|
|
2
2
|
import { Animated } from 'react-native';
|
|
3
3
|
import PropTypes from 'prop-types';
|
|
4
|
-
import _ from 'lodash';
|
|
5
4
|
import autoBindReact from 'auto-bind/react';
|
|
6
5
|
import { connectStyle } from '@shoutem/theme';
|
|
7
6
|
import { TouchableOpacity } from '../TouchableOpacity';
|
|
@@ -14,6 +13,7 @@ class YearRangePickerButton extends PureComponent {
|
|
|
14
13
|
static propTypes = {
|
|
15
14
|
onPress: PropTypes.func,
|
|
16
15
|
tooltip: PropTypes.string,
|
|
16
|
+
collapsed: PropTypes.bool,
|
|
17
17
|
style: PropTypes.any,
|
|
18
18
|
};
|
|
19
19
|
|
|
@@ -23,55 +23,41 @@ class YearRangePickerButton extends PureComponent {
|
|
|
23
23
|
autoBindReact(this);
|
|
24
24
|
|
|
25
25
|
this.dropDownIconValue = new Animated.Value(0);
|
|
26
|
-
|
|
27
|
-
this.state = {
|
|
28
|
-
collapsed: false,
|
|
29
|
-
};
|
|
30
26
|
}
|
|
31
27
|
|
|
32
|
-
|
|
33
|
-
const { collapsed } = this.
|
|
34
|
-
const {
|
|
35
|
-
|
|
36
|
-
const toValue = collapsed ? 0 : 1;
|
|
28
|
+
componentDidUpdate(prevProps) {
|
|
29
|
+
const { collapsed } = this.props;
|
|
30
|
+
const { collapsed: prevCollapsed } = prevProps;
|
|
37
31
|
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
() => Animated.timing(
|
|
41
|
-
this.dropDownIconValue,
|
|
42
|
-
{
|
|
43
|
-
toValue,
|
|
44
|
-
useNativeDriver: true,
|
|
45
|
-
duration: 300,
|
|
46
|
-
}
|
|
47
|
-
).start());
|
|
32
|
+
if (collapsed !== prevCollapsed) {
|
|
33
|
+
const toValue = collapsed ? 1 : 0;
|
|
48
34
|
|
|
49
|
-
|
|
50
|
-
|
|
35
|
+
Animated.timing(this.dropDownIconValue, {
|
|
36
|
+
toValue,
|
|
37
|
+
useNativeDriver: true,
|
|
38
|
+
duration: 300,
|
|
39
|
+
}).start();
|
|
51
40
|
}
|
|
52
41
|
}
|
|
53
42
|
|
|
54
43
|
render() {
|
|
55
|
-
const { style, tooltip } = this.props;
|
|
44
|
+
const { style, tooltip, onPress } = this.props;
|
|
56
45
|
|
|
57
46
|
return (
|
|
58
|
-
<TouchableOpacity
|
|
59
|
-
|
|
60
|
-
style={style.container}
|
|
61
|
-
>
|
|
62
|
-
<Text>
|
|
63
|
-
{tooltip}
|
|
64
|
-
</Text>
|
|
47
|
+
<TouchableOpacity onPress={onPress} style={style.container}>
|
|
48
|
+
<Text>{tooltip}</Text>
|
|
65
49
|
<AnimatedIcon
|
|
66
50
|
name="drop-down"
|
|
67
51
|
style={{
|
|
68
52
|
...style.icon,
|
|
69
|
-
transform: [
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
53
|
+
transform: [
|
|
54
|
+
{
|
|
55
|
+
rotate: this.dropDownIconValue.interpolate({
|
|
56
|
+
inputRange: [0, 1],
|
|
57
|
+
outputRange: ['0deg', '180deg'],
|
|
58
|
+
}),
|
|
59
|
+
},
|
|
60
|
+
],
|
|
75
61
|
}}
|
|
76
62
|
/>
|
|
77
63
|
</TouchableOpacity>
|
|
@@ -79,4 +65,6 @@ class YearRangePickerButton extends PureComponent {
|
|
|
79
65
|
}
|
|
80
66
|
}
|
|
81
67
|
|
|
82
|
-
export default connectStyle('shoutem.ui.YearRangePickerButton')(
|
|
68
|
+
export default connectStyle('shoutem.ui.YearRangePickerButton')(
|
|
69
|
+
YearRangePickerButton,
|
|
70
|
+
);
|
|
@@ -20,10 +20,7 @@ function resolveVisibleYears(props) {
|
|
|
20
20
|
const yearsPerPage = NUMBER_OF_ROWS * YEARS_IN_ROW;
|
|
21
21
|
|
|
22
22
|
if (_.isEmpty(selectedYears)) {
|
|
23
|
-
const fullRange = _.times(
|
|
24
|
-
yearsPerPage,
|
|
25
|
-
index => rangeStart + index,
|
|
26
|
-
);
|
|
23
|
+
const fullRange = _.times(yearsPerPage, index => rangeStart + index);
|
|
27
24
|
|
|
28
25
|
return _.filter(fullRange, year => year <= rangeEnd);
|
|
29
26
|
}
|
|
@@ -31,11 +28,8 @@ function resolveVisibleYears(props) {
|
|
|
31
28
|
const firstSelectedYear = _.head(selectedYears);
|
|
32
29
|
const prevPagesNumber = Math.trunc(firstSelectedYear / yearsPerPage);
|
|
33
30
|
|
|
34
|
-
const fullRangeStart =
|
|
35
|
-
const fullRange = _.times(
|
|
36
|
-
yearsPerPage,
|
|
37
|
-
index => fullRangeStart + index,
|
|
38
|
-
);
|
|
31
|
+
const fullRangeStart = prevPagesNumber * yearsPerPage + 1;
|
|
32
|
+
const fullRange = _.times(yearsPerPage, index => fullRangeStart + index);
|
|
39
33
|
|
|
40
34
|
return _.filter(fullRange, year => year <= rangeEnd);
|
|
41
35
|
}
|
|
@@ -83,7 +77,6 @@ class YearRangePickerModal extends PureComponent {
|
|
|
83
77
|
const { onRangeConfirmed } = this.props;
|
|
84
78
|
|
|
85
79
|
if (onRangeConfirmed) {
|
|
86
|
-
LayoutAnimation.easeInEaseOut();
|
|
87
80
|
onRangeConfirmed(selectedYears);
|
|
88
81
|
}
|
|
89
82
|
}
|
|
@@ -91,7 +84,6 @@ class YearRangePickerModal extends PureComponent {
|
|
|
91
84
|
handleResetPress() {
|
|
92
85
|
const { onRangeConfirmed } = this.props;
|
|
93
86
|
|
|
94
|
-
LayoutAnimation.easeInEaseOut();
|
|
95
87
|
this.setState({ selectedYears: [] });
|
|
96
88
|
|
|
97
89
|
if (onRangeConfirmed) {
|
|
@@ -104,9 +96,15 @@ class YearRangePickerModal extends PureComponent {
|
|
|
104
96
|
const { visibleYears } = this.state;
|
|
105
97
|
|
|
106
98
|
const nextYearStart = _.last(visibleYears) + 1;
|
|
107
|
-
const nextYearEnd = Math.min(
|
|
99
|
+
const nextYearEnd = Math.min(
|
|
100
|
+
rangeEnd,
|
|
101
|
+
nextYearStart + this.YEARS_PER_PAGE - 1,
|
|
102
|
+
);
|
|
108
103
|
|
|
109
|
-
const nextVisibleYears = _.times(
|
|
104
|
+
const nextVisibleYears = _.times(
|
|
105
|
+
nextYearEnd + 1 - nextYearStart,
|
|
106
|
+
index => nextYearStart + index,
|
|
107
|
+
);
|
|
110
108
|
|
|
111
109
|
LayoutAnimation.easeInEaseOut();
|
|
112
110
|
this.setState({ visibleYears: nextVisibleYears });
|
|
@@ -118,7 +116,12 @@ class YearRangePickerModal extends PureComponent {
|
|
|
118
116
|
const prevYearStart = _.head(visibleYears) - this.YEARS_PER_PAGE;
|
|
119
117
|
|
|
120
118
|
LayoutAnimation.easeInEaseOut();
|
|
121
|
-
this.setState({
|
|
119
|
+
this.setState({
|
|
120
|
+
visibleYears: _.times(
|
|
121
|
+
this.YEARS_PER_PAGE,
|
|
122
|
+
index => prevYearStart + index,
|
|
123
|
+
),
|
|
124
|
+
});
|
|
122
125
|
}
|
|
123
126
|
|
|
124
127
|
handleYearPress(year) {
|
|
@@ -137,7 +140,9 @@ class YearRangePickerModal extends PureComponent {
|
|
|
137
140
|
}
|
|
138
141
|
|
|
139
142
|
const cutFromEnd = size / 2 <= index;
|
|
140
|
-
const newYears = _.filter(selectedYears, value =>
|
|
143
|
+
const newYears = _.filter(selectedYears, value =>
|
|
144
|
+
cutFromEnd ? value <= year : value >= year,
|
|
145
|
+
);
|
|
141
146
|
|
|
142
147
|
this.setState({ selectedYears: newYears });
|
|
143
148
|
return;
|
|
@@ -149,15 +154,23 @@ class YearRangePickerModal extends PureComponent {
|
|
|
149
154
|
}
|
|
150
155
|
|
|
151
156
|
const addToEnd = _.last(selectedYears) < year;
|
|
152
|
-
const yearsToAdd = addToEnd
|
|
157
|
+
const yearsToAdd = addToEnd
|
|
158
|
+
? year - _.last(selectedYears)
|
|
159
|
+
: _.head(selectedYears) - year;
|
|
153
160
|
|
|
154
161
|
const newYears = addToEnd
|
|
155
|
-
? [
|
|
156
|
-
|
|
162
|
+
? [
|
|
163
|
+
...selectedYears,
|
|
164
|
+
..._.times(yearsToAdd, index => _.last(selectedYears) + index + 1),
|
|
165
|
+
]
|
|
166
|
+
: [
|
|
167
|
+
...selectedYears,
|
|
168
|
+
..._.times(yearsToAdd, index => _.head(selectedYears) - index + -1),
|
|
169
|
+
];
|
|
157
170
|
const sortedYears = _.sortBy(newYears, item => item);
|
|
158
171
|
|
|
159
172
|
this.setState({ selectedYears: sortedYears });
|
|
160
|
-
}
|
|
173
|
+
};
|
|
161
174
|
}
|
|
162
175
|
|
|
163
176
|
renderYear(year) {
|
|
@@ -174,12 +187,14 @@ class YearRangePickerModal extends PureComponent {
|
|
|
174
187
|
style={style.yearContainer}
|
|
175
188
|
key={year.toString()}
|
|
176
189
|
>
|
|
177
|
-
<View
|
|
178
|
-
style
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
190
|
+
<View
|
|
191
|
+
style={[
|
|
192
|
+
style.year,
|
|
193
|
+
isSelected && style.yearSelected,
|
|
194
|
+
isFirst && style.yearFirst,
|
|
195
|
+
isLast && style.yearLast,
|
|
196
|
+
]}
|
|
197
|
+
>
|
|
183
198
|
<Text>{year.toString()}</Text>
|
|
184
199
|
</View>
|
|
185
200
|
</TouchableOpacity>
|
|
@@ -191,7 +206,7 @@ class YearRangePickerModal extends PureComponent {
|
|
|
191
206
|
<View styleName="horizontal flexible" key={index.toString()}>
|
|
192
207
|
{_.map(row, this.renderYear)}
|
|
193
208
|
</View>
|
|
194
|
-
)
|
|
209
|
+
);
|
|
195
210
|
}
|
|
196
211
|
|
|
197
212
|
render() {
|
|
@@ -221,6 +236,7 @@ class YearRangePickerModal extends PureComponent {
|
|
|
221
236
|
onBackdropPress={onDismiss}
|
|
222
237
|
useNativeDriver
|
|
223
238
|
backdropOpacity={Platform.OS === 'ios' ? 0.7 : 0}
|
|
239
|
+
animationIn="slideInUp"
|
|
224
240
|
>
|
|
225
241
|
<View style={style.container}>
|
|
226
242
|
<View style={style.tooltipContainer}>
|
|
@@ -229,7 +245,10 @@ class YearRangePickerModal extends PureComponent {
|
|
|
229
245
|
onPress={this.handleYearsBackPress}
|
|
230
246
|
disabled={prevDisabled}
|
|
231
247
|
>
|
|
232
|
-
<Icon
|
|
248
|
+
<Icon
|
|
249
|
+
name="left-arrow"
|
|
250
|
+
style={[style.icon, prevDisabled && style.iconDisabled]}
|
|
251
|
+
/>
|
|
233
252
|
</Button>
|
|
234
253
|
<Text>{buttonTooltip}</Text>
|
|
235
254
|
<Button
|
|
@@ -237,22 +256,33 @@ class YearRangePickerModal extends PureComponent {
|
|
|
237
256
|
onPress={this.handleYearsForwardPress}
|
|
238
257
|
disabled={nextDisabled}
|
|
239
258
|
>
|
|
240
|
-
<Icon
|
|
259
|
+
<Icon
|
|
260
|
+
name="right-arrow"
|
|
261
|
+
style={[style.icon, nextDisabled && style.iconDisabled]}
|
|
262
|
+
/>
|
|
241
263
|
</Button>
|
|
242
264
|
</View>
|
|
243
|
-
{_.times(NUMBER_OF_ROWS,
|
|
265
|
+
{_.times(NUMBER_OF_ROWS, row => this.renderYearRow(data[row], row))}
|
|
244
266
|
<View style={style.buttonContainer}>
|
|
245
|
-
<Button
|
|
267
|
+
<Button
|
|
268
|
+
styleName="secondary flexible"
|
|
269
|
+
onPress={this.handleResetPress}
|
|
270
|
+
>
|
|
246
271
|
<Text>{resetButtonTitle}</Text>
|
|
247
272
|
</Button>
|
|
248
|
-
<Button
|
|
273
|
+
<Button
|
|
274
|
+
styleName="primary flexible md-gutter-left"
|
|
275
|
+
onPress={this.handleConfirmPress}
|
|
276
|
+
>
|
|
249
277
|
<Text>{confirmButtonTitle}</Text>
|
|
250
278
|
</Button>
|
|
251
279
|
</View>
|
|
252
|
-
</
|
|
280
|
+
</View>
|
|
253
281
|
</Modal>
|
|
254
282
|
);
|
|
255
283
|
}
|
|
256
284
|
}
|
|
257
285
|
|
|
258
|
-
export default connectStyle('shoutem.ui.YearRangePickerModal')(
|
|
286
|
+
export default connectStyle('shoutem.ui.YearRangePickerModal')(
|
|
287
|
+
YearRangePickerModal,
|
|
288
|
+
);
|