3
3
* @module @nativescript -community/ui-material-speedial
4
4
*/
5
5
6
- import {
7
- Animation ,
8
- AnimationDefinition ,
9
- CSSType ,
10
- Color ,
11
- EventData ,
12
- FlexboxLayout ,
13
- GestureTypes ,
14
- GridLayout ,
15
- HorizontalAlignment ,
16
- ImageSource ,
17
- View ,
18
- backgroundColorProperty ,
19
- colorProperty ,
20
- isUserInteractionEnabledProperty
21
- } from '@nativescript/core' ;
6
+ import { Animation , AnimationDefinition , CSSType , Color , CoreTypes , EventData , FlexboxLayout , GridLayout , ImageSource , isUserInteractionEnabledProperty } from '@nativescript/core' ;
22
7
import { Button } from '@nativescript-community/ui-material-button' ;
23
8
import { LinearGradient } from '@nativescript/core/ui/styling/gradient' ;
24
- import { AnimationCurve } from '@nativescript/core/ui/enums' ;
25
9
import { NotifyData } from '@nativescript/core/data/observable' ;
26
10
27
11
export class SpeedDialItemBase extends GridLayout { }
@@ -97,36 +81,45 @@ export class SpeedDialButton extends SpeedDialItemButton {}
97
81
@CSSType ( 'MDSpeedDialItem' )
98
82
export class SpeedDialItem extends SpeedDialItemBase {
99
83
public actualActive = false ;
100
- titleView : SpeedDialItemTitle ;
101
- button : SpeedDialItemButton ;
84
+ mTitleView : WeakRef < SpeedDialItemTitle > ;
85
+ mButton : WeakRef < SpeedDialItemButton > ;
102
86
fabmenu : WeakRef < SpeedDial > ;
87
+
88
+ get titleView ( ) {
89
+ return this . mTitleView ?. get ( ) ;
90
+ }
91
+ get button ( ) {
92
+ return this . mButton ?. get ( ) ;
93
+ }
103
94
constructor ( size = 'mini' , private isMain = false ) {
104
95
super ( ) ;
105
96
// this._fabsHolder.isPassThroughParentEnabled = true;
106
97
this . isPassThroughParentEnabled = true ;
107
- this . titleView = new SpeedDialItemTitle ( ) ;
108
- this . titleView . notify = this . notifyChildEvent ( this . titleView , this . titleView . notify ) ;
109
- this . titleView . col = 1 ;
110
- this . titleView . text = this . title ;
111
- this . button = isMain ? new SpeedDialButton ( ) : new SpeedDialItemButton ( ) ;
112
- this . button . notify = this . notifyChildEvent ( this . button , this . button . notify ) ;
113
- this . button . horizontalAlignment = 'center' ;
98
+ const titleView = new SpeedDialItemTitle ( ) ;
99
+ titleView . notify = this . notifyChildEvent ( titleView , titleView . notify ) ;
100
+ titleView . col = 1 ;
101
+ titleView . text = this . title ;
102
+ const button = isMain ? new SpeedDialButton ( ) : new SpeedDialItemButton ( ) ;
103
+ button . notify = this . notifyChildEvent ( button , button . notify ) ;
104
+ button . horizontalAlignment = 'center' ;
114
105
// this.fabButtonTitle.style['css:elevation'] = 4;this.fabButtonTitle.style['css:elevation'] = 2;
115
- this . button . col = this . fabButtonCol ;
106
+ button . col = this . fabButtonCol ;
116
107
if ( size === 'mini' ) {
117
- // this. button.style['css:border-radius'] = 20;
118
- this . button . style [ 'css:width' ] = 40 ;
119
- this . button . style [ 'css:height' ] = 40 ;
120
- this . button . style [ 'css:margin' ] = 16 ;
108
+ // button.style['css:border-radius'] = 20;
109
+ button . style [ 'css:width' ] = 40 ;
110
+ button . style [ 'css:height' ] = 40 ;
111
+ button . style [ 'css:margin' ] = 16 ;
121
112
} else {
122
- // this. button.style['css:border-radius'] = 28;
123
- this . button . style [ 'css:width' ] = 56 ;
124
- this . button . style [ 'css:height' ] = 56 ;
125
- this . button . style [ 'css:margin' ] = 16 ;
113
+ // button.style['css:border-radius'] = 28;
114
+ button . style [ 'css:width' ] = 56 ;
115
+ button . style [ 'css:height' ] = 56 ;
116
+ button . style [ 'css:margin' ] = 16 ;
126
117
}
127
118
( this as any ) . columns = this . fabColumns ;
128
- this . addChild ( this . titleView ) ;
129
- this . addChild ( this . button ) ;
119
+ this . addChild ( titleView ) ;
120
+ this . addChild ( button ) ;
121
+ this . mTitleView = new WeakRef ( titleView ) ;
122
+ this . mButton = new WeakRef ( button ) ;
130
123
}
131
124
updateAlignment ( ) {
132
125
( this as any ) . columns = this . fabColumns ;
@@ -265,14 +258,24 @@ export class SpeedDialItem extends SpeedDialItemBase {
265
258
266
259
@CSSType ( 'MDSpeedDial' )
267
260
export class SpeedDial extends SpeedDialItemBase {
268
- fabs : SpeedDialItem [ ] = [ ] ;
269
- private _fabsHolder : FlexboxLayout ;
261
+ mFabs : WeakRef < SpeedDialItem > [ ] = [ ] ;
262
+ private mFabsHolder : WeakRef < FlexboxLayout > ;
270
263
rows : string ;
271
264
columns : string ;
272
265
orientation = 'vertical' ;
273
266
isActive = false ;
274
267
actualActive = false ;
275
- private _fabMainButton : SpeedDialItem ;
268
+ private mFabMainButton : WeakRef < SpeedDialItem > ;
269
+
270
+ get fabsHolder ( ) {
271
+ return this . mFabsHolder ?. get ( ) ;
272
+ }
273
+ get fabMainButton ( ) {
274
+ return this . mFabMainButton ?. get ( ) ;
275
+ }
276
+ get fabs ( ) {
277
+ return this . mFabs . map ( ( f ) => f ?. get ( ) ) . filter ( ( f ) => ! ! f ) ;
278
+ }
276
279
constructor ( ) {
277
280
super ( ) ;
278
281
this . actualActive = this . isActive ;
@@ -281,23 +284,25 @@ export class SpeedDial extends SpeedDialItemBase {
281
284
this . rows = 'auto,*,auto,auto' ;
282
285
this . style [ 'css:padding-left' ] = 8 ;
283
286
this . style [ 'css:padding-right' ] = 8 ;
284
- this . _fabsHolder = new FlexboxLayout ( ) ;
285
- this . _fabsHolder . row = 2 ;
286
- this . _fabsHolder . horizontalAlignment = this . horizontalAlignment ;
287
+ const fabHolder = new FlexboxLayout ( ) ;
288
+ fabHolder . row = 2 ;
289
+ fabHolder . horizontalAlignment = this . horizontalAlignment ;
287
290
this . isPassThroughParentEnabled = true ;
288
291
if ( global . isIOS ) {
289
- this . _fabsHolder . isPassThroughParentEnabled = true ;
292
+ fabHolder . isPassThroughParentEnabled = true ;
290
293
}
291
- this . _fabsHolder . flexDirection = this . orientation === 'vertical' ? 'column-reverse' : 'row-reverse' ;
292
- this . _fabsHolder . visibility = 'hidden' ;
294
+ fabHolder . flexDirection = this . orientation === 'vertical' ? 'column-reverse' : 'row-reverse' ;
295
+ fabHolder . visibility = 'hidden' ;
293
296
this . backgroundColor = new Color ( '#00000000' ) ;
294
297
295
- this . _fabMainButton = new SpeedDialItem ( null , true ) ;
296
- this . prepareItem ( this . _fabMainButton , true ) ;
297
- this . _fabMainButton . row = 3 ;
298
+ const fabMainButton = new SpeedDialItem ( null , true ) ;
299
+ this . prepareItem ( fabMainButton , true ) ;
300
+ fabMainButton . row = 3 ;
298
301
299
- this . addChild ( this . _fabMainButton ) ;
300
- this . addChild ( this . _fabsHolder ) ;
302
+ this . addChild ( fabMainButton ) ;
303
+ this . addChild ( fabHolder ) ;
304
+ this . mFabsHolder = new WeakRef ( fabHolder ) ;
305
+ this . mFabMainButton = new WeakRef ( fabMainButton ) ;
301
306
}
302
307
303
308
get backDrop ( ) {
@@ -326,11 +331,11 @@ export class SpeedDial extends SpeedDialItemBase {
326
331
} ) ;
327
332
}
328
333
insertChild ( child , index ) {
329
- if ( child !== this . _fabMainButton && child instanceof SpeedDialItem ) {
334
+ if ( child !== this . fabMainButton && child instanceof SpeedDialItem ) {
330
335
this . prepareItem ( child ) ;
331
336
332
- this . fabs . splice ( index , 0 , child ) ;
333
- this . _fabsHolder . insertChild ( child , index ) ;
337
+ this . mFabs . splice ( index , 0 , new WeakRef ( child ) ) ;
338
+ this . fabsHolder . insertChild ( child , index ) ;
334
339
} else {
335
340
super . insertChild ( child , index ) ;
336
341
}
@@ -341,11 +346,11 @@ export class SpeedDial extends SpeedDialItemBase {
341
346
// this is to make sure the view does not get "visible" too quickly
342
347
// before we apply the translation
343
348
// super.addChild(child);
344
- if ( child !== this . _fabMainButton && child instanceof SpeedDialItem ) {
349
+ if ( child !== this . fabMainButton && child instanceof SpeedDialItem ) {
345
350
this . prepareItem ( child ) ;
346
351
347
- this . fabs . push ( child ) ;
348
- this . _fabsHolder . addChild ( child ) ;
352
+ this . mFabs . push ( new WeakRef ( child ) ) ;
353
+ this . fabsHolder . addChild ( child ) ;
349
354
} else {
350
355
super . addChild ( child ) ;
351
356
}
@@ -370,7 +375,7 @@ export class SpeedDial extends SpeedDialItemBase {
370
375
}
371
376
computeAnimationData ( way : 'open' | 'hide' , fab : SpeedDialItem , index , count , duration , isMain = false ) : AnimationDefinition [ ] {
372
377
const delay = ( duration / count ) * index ;
373
- const curve = AnimationCurve . easeOut ;
378
+ const curve = CoreTypes . AnimationCurve . easeOut ;
374
379
if ( way === 'open' ) {
375
380
const result : AnimationDefinition [ ] = [
376
381
{
@@ -439,18 +444,18 @@ export class SpeedDial extends SpeedDialItemBase {
439
444
return acc ;
440
445
} , [ ] as AnimationDefinition [ ] )
441
446
. filter ( ( a ) => ! ! a )
442
- . concat ( this . computeAnimationData ( 'open' , this . _fabMainButton , 0 , length , duration , true ) )
447
+ . concat ( this . computeAnimationData ( 'open' , this . fabMainButton , 0 , length , duration , true ) )
443
448
. concat ( [
444
449
{
445
450
target : this . backDrop ,
446
451
backgroundColor : new Color ( '#00000099' ) ,
447
- curve : AnimationCurve . easeInOut ,
452
+ curve : CoreTypes . AnimationCurve . easeInOut ,
448
453
duration
449
454
}
450
455
] ) ;
451
456
452
457
try {
453
- this . _fabsHolder . visibility = 'visible' ;
458
+ this . fabsHolder . visibility = 'visible' ;
454
459
this . isPassThroughParentEnabled = false ;
455
460
await new Animation ( params ) . play ( ) ;
456
461
fabs . forEach ( ( f ) => ( f . isUserInteractionEnabled = true ) ) ;
@@ -471,12 +476,12 @@ export class SpeedDial extends SpeedDialItemBase {
471
476
return acc ;
472
477
} , [ ] as AnimationDefinition [ ] )
473
478
. filter ( ( a ) => ! ! a )
474
- . concat ( this . computeAnimationData ( 'hide' , this . _fabMainButton , 0 , length , duration , true ) )
479
+ . concat ( this . computeAnimationData ( 'hide' , this . fabMainButton , 0 , length , duration , true ) )
475
480
. concat ( [
476
481
{
477
482
target : this . backDrop ,
478
483
backgroundColor : new Color ( '#00000000' ) ,
479
- curve : AnimationCurve . easeInOut ,
484
+ curve : CoreTypes . AnimationCurve . easeInOut ,
480
485
duration
481
486
}
482
487
] ) ;
@@ -485,7 +490,7 @@ export class SpeedDial extends SpeedDialItemBase {
485
490
fabs . forEach ( ( f ) => ( f . isUserInteractionEnabled = false ) ) ;
486
491
await new Animation ( params ) . play ( ) ;
487
492
this . isPassThroughParentEnabled = true ;
488
- this . _fabsHolder . visibility = 'hidden' ;
493
+ this . fabsHolder . visibility = 'hidden' ;
489
494
} catch ( err ) {
490
495
// console.error(err);
491
496
} finally {
@@ -515,52 +520,52 @@ export class SpeedDial extends SpeedDialItemBase {
515
520
516
521
//@ts -ignore
517
522
get icon ( ) {
518
- return this . _fabMainButton . icon ;
523
+ return this . fabMainButton . icon ;
519
524
}
520
525
set icon ( value : string | ImageSource ) {
521
- this . _fabMainButton . icon = value ;
522
- this . _fabMainButton . padding = 0 ;
526
+ this . fabMainButton . icon = value ;
527
+ this . fabMainButton . padding = 0 ;
523
528
}
524
529
get buttonClass ( ) {
525
- return this . _fabMainButton . buttonClass ;
530
+ return this . fabMainButton . buttonClass ;
526
531
}
527
532
set buttonClass ( value : string ) {
528
- this . _fabMainButton . buttonClass = value ;
533
+ this . fabMainButton . buttonClass = value ;
529
534
}
530
535
get buttonFontSize ( ) {
531
- return this . _fabMainButton . buttonFontSize ;
536
+ return this . fabMainButton . buttonFontSize ;
532
537
}
533
538
set buttonFontSize ( value ) {
534
- this . _fabMainButton . buttonFontSize = value ;
539
+ this . fabMainButton . buttonFontSize = value ;
535
540
}
536
541
537
542
//@ts -ignore
538
543
get color ( ) {
539
- return this . _fabMainButton . color ;
544
+ return this . fabMainButton . color ;
540
545
}
541
546
set color ( value ) {
542
- this . _fabMainButton . color = value ;
547
+ this . fabMainButton . color = value ;
543
548
}
544
549
get text ( ) {
545
- return this . _fabMainButton . text ;
550
+ return this . fabMainButton . text ;
546
551
}
547
552
set text ( value : string ) {
548
- this . _fabMainButton . text = value ;
553
+ this . fabMainButton . text = value ;
549
554
}
550
555
get title ( ) {
551
- return this . _fabMainButton . title ;
556
+ return this . fabMainButton . title ;
552
557
}
553
558
set title ( value : string ) {
554
- this . _fabMainButton . title = value ;
559
+ this . fabMainButton . title = value ;
555
560
}
556
561
//@ts -ignore
557
562
get horizontalAlignment ( ) {
558
- return this . _fabsHolder . horizontalAlignment ;
563
+ return this . fabsHolder . horizontalAlignment ;
559
564
}
560
565
set horizontalAlignment ( value ) {
561
- this . _fabsHolder . horizontalAlignment = value ;
562
- this . _fabMainButton . updateAlignment ( ) ;
563
- this . _fabsHolder . eachChild ( ( c ) => {
566
+ this . fabsHolder . horizontalAlignment = value ;
567
+ this . fabMainButton . updateAlignment ( ) ;
568
+ this . fabsHolder . eachChild ( ( c ) => {
564
569
if ( c instanceof SpeedDialItem ) {
565
570
c . updateAlignment ( ) ;
566
571
}
@@ -595,10 +600,10 @@ export class SpeedDial extends SpeedDialItemBase {
595
600
// }
596
601
597
602
get titleClass ( ) {
598
- return this . _fabMainButton . titleClass ;
603
+ return this . fabMainButton . titleClass ;
599
604
}
600
605
set titleClass ( value : string ) {
601
- this . _fabMainButton . titleClass = value ;
606
+ this . fabMainButton . titleClass = value ;
602
607
}
603
608
604
609
onBackdropTap ( args ) {
0 commit comments