1
1
import { ChangeDetectionStrategy , Component , ContentChildren , ContentChild , Directive , ElementRef , EventEmitter , HostBinding , Input , Optional , Output , QueryList , Renderer , ViewEncapsulation } from '@angular/core' ;
2
2
3
3
import { List } from '../list/list' ;
4
- import { Ion } from '../ion' ;
5
4
import { Item } from './item' ;
6
5
import { isPresent } from '../../util/util' ;
7
- import { CSS } from '../../util/dom' ;
6
+ import { CSS , nativeRaf , nativeTimeout } from '../../util/dom' ;
8
7
9
8
const SWIPE_FACTOR = 1.1 ;
10
9
const ELASTIC_FACTOR = 0.55 ;
@@ -22,19 +21,18 @@ export const enum SideFlags {
22
21
@Directive ( {
23
22
selector : 'ion-item-options' ,
24
23
} )
25
- export class ItemOptions extends Ion {
24
+ export class ItemOptions {
26
25
@Input ( ) side : string ;
27
26
@Output ( ) ionSwipe : EventEmitter < ItemSliding > = new EventEmitter ( ) ;
28
27
29
- constructor ( elementRef : ElementRef , private _renderer : Renderer ) {
30
- super ( elementRef ) ;
28
+ constructor ( private _elementRef : ElementRef , private _renderer : Renderer ) {
31
29
}
32
30
33
31
/**
34
32
* @private
35
33
*/
36
34
setCssStyle ( property : string , value : string ) {
37
- this . _renderer . setElementStyle ( this . elementRef . nativeElement , property , value ) ;
35
+ this . _renderer . setElementStyle ( this . _elementRef . nativeElement , property , value ) ;
38
36
}
39
37
40
38
/**
@@ -48,6 +46,10 @@ export class ItemOptions extends Ion {
48
46
}
49
47
}
50
48
49
+ width ( ) {
50
+ return this . _elementRef . nativeElement . offsetWidth ;
51
+ }
52
+
51
53
}
52
54
53
55
const enum SlidingState {
@@ -224,10 +226,14 @@ export class ItemSliding {
224
226
* @private
225
227
*/
226
228
startSliding ( startX : number ) {
229
+ if ( this . _timer ) {
230
+ clearTimeout ( this . _timer ) ;
231
+ this . _timer = null ;
232
+ }
227
233
if ( this . _openAmount === 0 ) {
234
+ this . _optsDirty = true ;
228
235
this . _setState ( SlidingState . Enabled ) ;
229
236
}
230
- this . _optsDirty = true ;
231
237
this . _startX = startX + this . _openAmount ;
232
238
this . item . setCssStyle ( CSS . transition , 'none' ) ;
233
239
}
@@ -236,7 +242,10 @@ export class ItemSliding {
236
242
* @private
237
243
*/
238
244
moveSliding ( x : number ) : number {
239
- this . calculateOptsWidth ( ) ;
245
+ if ( this . _optsDirty ) {
246
+ this . calculateOptsWidth ( ) ;
247
+ return ;
248
+ }
240
249
241
250
let openAmount = this . _startX - x ;
242
251
switch ( this . _sides ) {
@@ -290,17 +299,20 @@ export class ItemSliding {
290
299
}
291
300
292
301
calculateOptsWidth ( ) {
293
- if ( this . _optsDirty ) {
294
- this . _optsWidthRightSide = 0 ;
295
- if ( this . _rightOptions ) {
296
- this . _optsWidthRightSide = this . _rightOptions . width ( ) ;
302
+ nativeRaf ( ( ) => {
303
+ if ( this . _optsDirty ) {
304
+ this . _optsWidthRightSide = 0 ;
305
+ if ( this . _rightOptions ) {
306
+ this . _optsWidthRightSide = this . _rightOptions . width ( ) ;
307
+ }
308
+
309
+ this . _optsWidthLeftSide = 0 ;
310
+ if ( this . _leftOptions ) {
311
+ this . _optsWidthLeftSide = this . _leftOptions . width ( ) ;
312
+ }
313
+ this . _optsDirty = false ;
297
314
}
298
- this . _optsWidthLeftSide = 0 ;
299
- if ( this . _leftOptions ) {
300
- this . _optsWidthLeftSide = this . _leftOptions . width ( ) ;
301
- }
302
- this . _optsDirty = false ;
303
- }
315
+ } ) ;
304
316
}
305
317
306
318
/**
@@ -317,7 +329,7 @@ export class ItemSliding {
317
329
if ( didEnd ) {
318
330
// TODO: refactor. there must exist a better way
319
331
// if sliding ended, we wait 400ms until animation finishes
320
- this . _timer = setTimeout ( ( ) => {
332
+ this . _timer = nativeTimeout ( ( ) => {
321
333
this . _setState ( SlidingState . Disabled ) ;
322
334
this . _timer = null ;
323
335
} , 400 ) ;
@@ -347,6 +359,10 @@ export class ItemSliding {
347
359
this . setClass ( 'active-slide' , state !== SlidingState . Disabled ) ;
348
360
this . setClass ( 'active-options-right' , state === SlidingState . Right ) ;
349
361
this . setClass ( 'active-options-left' , state === SlidingState . Left ) ;
362
+ if ( state === SlidingState . Disabled || state === SlidingState . Enabled ) {
363
+ this . setClass ( 'active-swipe-right' , false ) ;
364
+ this . setClass ( 'active-swipe-left' , false ) ;
365
+ }
350
366
}
351
367
}
352
368
0 commit comments