@@ -48,10 +48,23 @@ export default class StackAggregator extends PureBaseComponent {
48
48
/**
49
49
* A callback for item press
50
50
*/
51
- onItemPress : PropTypes . func
52
- } ;
51
+ onItemPress : PropTypes . func ,
52
+ /**
53
+ * A callback for collapse state will change (value is future collapsed state)
54
+ */
55
+ onCollapseWillChange : PropTypes . func ,
56
+ /**
57
+ * A callback for collapse state change (value is collapsed state)
58
+ */
59
+ onCollapseChanged : PropTypes . func ,
60
+ /**
61
+ * A setting that disables pressability on cards
62
+ */
63
+ disablePresses : PropTypes . boolean
64
+ }
53
65
54
66
static defaultProps = {
67
+ disablePresses : false ,
55
68
collapsed : true ,
56
69
itemBorderRadius : 0
57
70
} ;
@@ -100,56 +113,78 @@ export default class StackAggregator extends PureBaseComponent {
100
113
return 1 ;
101
114
}
102
115
103
- animate = ( ) => {
104
- this . animateValues ( ) ;
105
- this . animateCards ( ) ;
106
- } ;
116
+ animate = async ( ) => {
117
+ return Promise . all ( [ this . animateValues ( ) , this . animateCards ( ) ] ) ;
118
+ }
107
119
108
120
animateValues ( ) {
109
121
const { collapsed} = this . state ;
110
122
const newValue = collapsed ? buttonStartValue : 1 ;
111
-
112
- Animated . parallel ( [
113
- Animated . timing ( this . animatedOpacity , {
114
- duration : DURATION ,
115
- toValue : Number ( newValue ) ,
116
- useNativeDriver : true
117
- } ) ,
118
- Animated . timing ( this . animatedScale , {
119
- toValue : Number ( newValue ) ,
120
- easing : this . easeOut ,
121
- duration : DURATION ,
122
- useNativeDriver : true
123
- } ) ,
124
- Animated . timing ( this . animatedContentOpacity , {
125
- toValue : Number ( collapsed ? 0 : 1 ) ,
126
- easing : this . easeOut ,
127
- duration : DURATION ,
128
- useNativeDriver : true
129
- } )
130
- ] ) . start ( ) ;
123
+ return new Promise ( ( resolve ) => {
124
+ Animated . parallel ( [
125
+ Animated . timing ( this . animatedOpacity , {
126
+ duration : DURATION ,
127
+ toValue : Number ( newValue ) ,
128
+ useNativeDriver : true
129
+ } ) ,
130
+ Animated . timing ( this . animatedScale , {
131
+ toValue : Number ( newValue ) ,
132
+ easing : this . easeOut ,
133
+ duration : DURATION ,
134
+ useNativeDriver : true
135
+ } ) ,
136
+ Animated . timing ( this . animatedContentOpacity , {
137
+ toValue : Number ( collapsed ? 0 : 1 ) ,
138
+ easing : this . easeOut ,
139
+ duration : DURATION ,
140
+ useNativeDriver : true
141
+ } )
142
+ ] ) . start ( resolve ) ;
143
+ } ) ;
131
144
}
132
145
133
- animateCards ( ) {
146
+ animateCards ( ) {
147
+ const promises = [ ] ;
134
148
for ( let index = 0 ; index < this . itemsCount ; index ++ ) {
135
149
const newScale = this . getItemScale ( index ) ;
136
150
137
- Animated . timing ( this . animatedScaleArray [ index ] , {
138
- toValue : Number ( newScale ) ,
139
- easing : this . easeOut ,
140
- duration : DURATION ,
141
- useNativeDriver : true
142
- } ) . start ( ) ;
151
+ promises . push (
152
+ new Promise ( ( resolve ) => {
153
+ Animated . timing ( this . animatedScaleArray [ index ] , {
154
+ toValue : Number ( newScale ) ,
155
+ easing : this . easeOut ,
156
+ duration : DURATION ,
157
+ useNativeDriver : true
158
+ } ) . start ( resolve ) ;
159
+ } )
160
+ ) ;
143
161
}
162
+ return Promise . all ( promises ) ;
144
163
}
145
164
146
165
close = ( ) => {
147
- this . setState ( { collapsed : true } , ( ) => this . animate ( ) ) ;
148
- } ;
166
+ this . setState ( { collapsed : true } , async ( ) => {
167
+ _ . invoke ( this . props , 'onCollapseWillChange' , true ) ;
168
+ if ( this . props . onCollapseChanged ) {
169
+ await this . animate ( ) ;
170
+ this . props . onCollapseChanged ( true ) ;
171
+ } else {
172
+ this . animate ( ) ;
173
+ }
174
+ } ) ;
175
+ }
149
176
150
177
open = ( ) => {
151
- this . setState ( { collapsed : false } , ( ) => this . animate ( ) ) ;
152
- } ;
178
+ this . setState ( { collapsed : false } , async ( ) => {
179
+ _ . invoke ( this . props , 'onCollapseWillChange' , false ) ;
180
+ if ( this . props . onCollapseChanged ) {
181
+ await this . animate ( ) ;
182
+ this . props . onCollapseChanged ( false ) ;
183
+ } else {
184
+ this . animate ( ) ;
185
+ }
186
+ } ) ;
187
+ }
153
188
154
189
getTop ( index ) {
155
190
let start = 0 ;
@@ -216,7 +251,7 @@ export default class StackAggregator extends PureBaseComponent {
216
251
>
217
252
< Card
218
253
style = { [ contentContainerStyle , this . styles . card ] }
219
- onPress = { ( ) => this . onItemPress ( index ) }
254
+ onPress = { this . props . disablePresses ? false : ( ) => this . onItemPress ( index ) }
220
255
borderRadius = { itemBorderRadius }
221
256
elevation = { 5 }
222
257
>
0 commit comments