1- import { Directive , ElementRef , AfterViewInit , Input } from '@angular/core' ;
1+ import { AfterViewInit , Directive , ElementRef , EventEmitter , Input , Output } from '@angular/core' ;
22import { AnimationCurve } from "ui/enums" ;
33import { Image } from "ui/image" ;
44import { StackLayout } from "ui/layouts/stack-layout" ;
55import { GridLayout , ItemSpec } from "ui/layouts/grid-layout" ;
6- import { GridUnitType } from "ui/layouts/grid-layout" ;
7- import { HorizontalAlignment } from "ui/enums" ;
86import { Label } from "ui/label" ;
9- import { GestureTypes } from "ui/gestures" ;
7+ import { GestureTypes , SwipeGestureEventData } from "ui/gestures" ;
108import { View } from "ui/core/view" ;
11- import { Visibility } from "ui/enums " ;
12- import { fromFile } from "image-source" ;
13- import { fromResource } from "image-source" ;
9+ import { fromFile , fromResource } from "image-source " ;
10+
11+ var labelModule = require ( "ui/label" ) ;
1412
1513@Directive ( { selector : '[carousel]' } )
1614export class CarouselDirective implements AfterViewInit {
@@ -37,19 +35,27 @@ export class CarouselDirective implements AfterViewInit {
3735 @Input ( ) carousel : any ;
3836 @Input ( ) carouselSpeed : number ; // autoplay speed (ms)
3937 @Input ( ) carouselArrows : string ; // arrows type
38+ @Input ( ) arrowsEnabled : boolean = false ; // enable arrows [default to false]
4039 @Input ( ) carouselLabelOverlay : boolean ; // title over image (bool)
4140 @Input ( ) carouselAnimationSpeed : number ; // animation speed
4241
42+ @Output ( ) selectedImageChange : EventEmitter < string > = new EventEmitter < string > ( ) ;
43+
4344 constructor ( private elem : ElementRef ) {
4445 this . container = elem . nativeElement ;
46+
47+
4548 }
4649
4750 ngAfterViewInit ( ) {
4851 this . initOptions ( ) ;
4952 this . initContainer ( ) ;
5053 this . initImagesLayout ( ) ;
5154 this . initSlides ( ) ;
52- this . initControls ( ) ;
55+ // Prefer swipe over arrows tap
56+ if ( this . arrowsEnabled ) {
57+ this . initControls ( ) ;
58+ }
5359 this . initAutoPlay ( ) ;
5460 }
5561
@@ -128,16 +134,46 @@ export class CarouselDirective implements AfterViewInit {
128134
129135 if ( slide . url ) {
130136 let image : Image = CarouselDirective . generateImageSliderFromUrl ( slide . url ) ;
137+ image . on ( GestureTypes . tap , ( ) => {
138+ this . selectedImageChange . emit ( slide . title ) ;
139+ } ) ;
140+ image . on ( GestureTypes . swipe , ( args : SwipeGestureEventData ) => {
141+ if ( args . direction === 1 ) {
142+ this . swipe ( CarouselDirections . DIRECTION_LEFT ) ;
143+ } else if ( args . direction === 2 ) {
144+ this . swipe ( CarouselDirections . DIRECTION_RIGHT ) ;
145+ }
146+ } ) ;
131147 gridLayout . addChild ( image ) ;
132148 }
133149
134150 if ( slide . file && slide . file . indexOf ( 'res://' ) !== 0 ) {
135151 let image : Image = CarouselDirective . generateImageSliderFromFile ( slide . file ) ;
152+ image . on ( GestureTypes . tap , ( ) => {
153+ this . selectedImageChange . emit ( slide . title ) ;
154+ } ) ;
155+ image . on ( GestureTypes . swipe , ( args : SwipeGestureEventData ) => {
156+ if ( args . direction === 1 ) {
157+ this . swipe ( CarouselDirections . DIRECTION_LEFT ) ;
158+ } else if ( args . direction === 2 ) {
159+ this . swipe ( CarouselDirections . DIRECTION_RIGHT ) ;
160+ }
161+ } ) ;
136162 gridLayout . addChild ( image ) ;
137163 }
138164
139165 if ( slide . file && slide . file . indexOf ( 'res://' ) === 0 ) {
140166 let image : Image = CarouselDirective . generateImageSliderFromResource ( slide . file ) ;
167+ image . on ( GestureTypes . tap , ( ) => {
168+ this . selectedImageChange . emit ( slide . title ) ;
169+ } ) ;
170+ image . on ( GestureTypes . swipe , ( args : SwipeGestureEventData ) => {
171+ if ( args . direction === 1 ) {
172+ this . swipe ( CarouselDirections . DIRECTION_LEFT ) ;
173+ } else if ( args . direction === 2 ) {
174+ this . swipe ( CarouselDirections . DIRECTION_RIGHT ) ;
175+ }
176+ } ) ;
141177 gridLayout . addChild ( image ) ;
142178 }
143179
0 commit comments