@@ -26,7 +26,7 @@ const ITEM_PROP_TYPES = {
26
26
27
27
/**
28
28
* @description : Interactable Drawer component
29
- * @extendslink :
29
+ * @extendslink :
30
30
*/
31
31
export default class Drawer extends PureBaseComponent {
32
32
static displayName = 'Drawer' ;
@@ -72,6 +72,10 @@ export default class Drawer extends PureBaseComponent {
72
72
* The items' text style
73
73
*/
74
74
itemsTextStyle : PropTypes . oneOfType ( [ PropTypes . object , PropTypes . number ] ) ,
75
+ /**
76
+ * Perform the animation in natively
77
+ */
78
+ useNativeAnimations : PropTypes . bool ,
75
79
} ;
76
80
77
81
static defaultProps = {
@@ -95,7 +99,7 @@ export default class Drawer extends PureBaseComponent {
95
99
}
96
100
97
101
UNSAFE_componentWillReceiveProps ( nextProps ) {
98
- if ( JSON . stringify ( this . props . leftItem ) !== JSON . stringify ( nextProps . leftItem ) ||
102
+ if ( JSON . stringify ( this . props . leftItem ) !== JSON . stringify ( nextProps . leftItem ) ||
99
103
JSON . stringify ( this . props . rightItems ) !== JSON . stringify ( nextProps . rightItems ) ) {
100
104
this . closeDrawer ( ) ;
101
105
}
@@ -178,7 +182,7 @@ export default class Drawer extends PureBaseComponent {
178
182
if ( _ . size ( rightItems ) > 0 ) {
179
183
const items = rightItems . reverse ( ) ;
180
184
const size = numberOfItems && numberOfItems >= 0 ? numberOfItems : items . length ;
181
-
185
+
182
186
for ( let i = 0 ; i < size ; i ++ ) {
183
187
total += this . getItemWidth ( items [ i ] ) ;
184
188
}
@@ -201,21 +205,21 @@ export default class Drawer extends PureBaseComponent {
201
205
const rightSpring = equalWidths ? 0 : 30 ;
202
206
const rightWidth = this . getRightItemsTotalWidth ( ) ;
203
207
const rightBound = rightWidth > 0 ? - rightWidth - rightSpring : 0 ;
204
-
208
+
205
209
return {
206
210
right : _ . isEmpty ( leftItem ) ? 0 : leftBound , left : _ . isEmpty ( rightItems ) ? 0 : rightBound } ;
207
211
}
208
212
getSnapPoints ( ) {
209
213
const { leftItem, rightItems, damping, tension} = this . getThemeProps ( ) ;
210
214
const size = rightItems ? rightItems . length : 0 ;
211
-
215
+
212
216
const left = ! _ . isEmpty ( leftItem ) ? { x : this . getItemWidth ( leftItem ) , damping, tension} : { } ;
213
217
const initial = { x : 0 , damping, tension} ;
214
218
const last = rightItems && ! _ . isEmpty ( rightItems [ 0 ] ) ?
215
219
{ x : - ( this . getRightItemsTotalWidth ( ) ) , damping, tension} : { } ;
216
220
217
221
switch ( size ) {
218
- case 0 :
222
+ case 0 :
219
223
return [ left , initial ] ;
220
224
default :
221
225
return [ left , initial , last ] ;
@@ -227,9 +231,9 @@ export default class Drawer extends PureBaseComponent {
227
231
228
232
const first = { id : 'first' , influenceArea : { left : - ( this . getRightItemsTotalWidth ( 1 ) ) } } ;
229
233
const second = { id : 'second' , influenceArea : { left : - ( this . getRightItemsTotalWidth ( size - 1 ) ) } } ;
230
-
234
+
231
235
switch ( size ) {
232
- case 0 :
236
+ case 0 :
233
237
case 1 :
234
238
return [ ] ;
235
239
case 2 :
@@ -243,7 +247,7 @@ export default class Drawer extends PureBaseComponent {
243
247
const size = rightItems ? rightItems . length : 0 ;
244
248
const interval = 65 ;
245
249
const inputRanges = [ ] ;
246
-
250
+
247
251
for ( let i = 0 ; i < size ; i ++ ) {
248
252
const itemWidth = this . getItemWidth ( rightItems [ i ] ) ;
249
253
const end = itemWidth - ( size * BLEED ) ;
@@ -256,13 +260,13 @@ export default class Drawer extends PureBaseComponent {
256
260
257
261
onLayout = ( event ) => {
258
262
const { width, height} = event . nativeEvent . layout ;
259
-
263
+
260
264
const typography = height >= SCALE_POINT ? Typography . text70 : Typography . text80 ;
261
265
const textTopMargin = height > SCALE_POINT ? 8 : 0 ;
262
266
const itemPadding = height >= SCALE_POINT ? ITEM_PADDING : 8 ;
263
-
267
+
264
268
this . setState ( { width, height, typography, textTopMargin, itemPadding} ) ;
265
- } ;
269
+ } ;
266
270
267
271
renderLeftItem ( ) {
268
272
const { leftItem, itemsTintColor, itemsIconSize, itemsTextStyle} = this . getThemeProps ( ) ;
@@ -331,7 +335,7 @@ export default class Drawer extends PureBaseComponent {
331
335
] }
332
336
{ ...this . getAnimationConfig ( ) }
333
337
/> }
334
- { leftItem && leftItem . text &&
338
+ { leftItem && leftItem . text &&
335
339
< Animated . Text
336
340
numberOfLines = { 1 }
337
341
style = {
@@ -426,7 +430,7 @@ export default class Drawer extends PureBaseComponent {
426
430
] }
427
431
{ ...this . getAnimationConfig ( ) }
428
432
/> }
429
- { item . text &&
433
+ { item . text &&
430
434
< Animated . Text
431
435
numberOfLines = { 1 }
432
436
style = {
@@ -473,7 +477,7 @@ export default class Drawer extends PureBaseComponent {
473
477
if ( migrate ) {
474
478
return < NewDrawer ref = { this . drawer } { ...this . getThemeProps ( ) } /> ;
475
479
}
476
-
480
+
477
481
const { style, onPress, rightItems} = this . getThemeProps ( ) ;
478
482
const Container = onPress ? TouchableOpacity : View ;
479
483
const backgroundColor = _ . get ( rightItems , '[0].background' , ITEM_BG ) ;
@@ -483,7 +487,7 @@ export default class Drawer extends PureBaseComponent {
483
487
< View style = { [ style , this . styles . container , { backgroundColor} ] } onLayout = { this . onLayout } >
484
488
{ rightItems && this . renderRightItems ( ) }
485
489
{ this . renderLeftItem ( ) }
486
-
490
+
487
491
< Interactable . View
488
492
ref = { el => ( this . interactableElem = el ) }
489
493
horizontalOnly
@@ -499,15 +503,15 @@ export default class Drawer extends PureBaseComponent {
499
503
style = { [ this . styles . interactable , { width : containerWidth * 2 } ] }
500
504
>
501
505
< View style = { { backgroundColor : Colors . white } } >
502
- < Container
506
+ < Container
503
507
style = { [ this . styles . childrenContainer , { width : containerWidth } ] }
504
508
activeOpacity = { 0.7 }
505
- onPress = { this . onPress }
509
+ onPress = { this . onPress }
506
510
>
507
511
{ this . props . children }
508
512
</ Container >
509
513
</ View >
510
- { rightItems &&
514
+ { rightItems &&
511
515
< View style = { { width : containerWidth , flexDirection : 'row' } } >
512
516
{ _ . map ( rightItems , this . renderGhostButton ) }
513
517
</ View >
0 commit comments