Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Interaction with Image and remove unused imports #10

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,10 @@ npm install nativescript-ng2-carousel --save

3. To use the CarouselDirective, create a template that applies the directive as an attribute to a paragraph GridLayout element:
<pre>
&lt;GridLayout [carousel]="images" carouselLabelOverlay="true" carouselSpeed="2000"&gt;
&lt;GridLayout [carousel]="images"
carouselLabelOverlay="true"
carouselSpeed="2000"
(selectedImageChange)="select($event)"&gt;

&lt;/GridLayout&gt;
</pre>
Expand Down Expand Up @@ -135,6 +138,7 @@ Currently directive supported attributes:
* **carouselAnimationSpeed** _(optional)_ defines the animation speed (number in ms)
* **carouselArrows** _(optional)_ arrow type, accepted values _none_, _small_, _normal_, _bold_ or _narrow_ (default _normal_)
* **carouselLabelOverlay** _(optional)_ silde title over image, accepted values _true_ or _false_ (default false)
* **selectedImageChange** _(optional)_ get the title of the selected image (key)

## Changelog

Expand Down
17 changes: 12 additions & 5 deletions nativescript-ng2-carousel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,10 @@ import {AnimationCurve} from "ui/enums";
import {Image} from "ui/image";
import {StackLayout} from "ui/layouts/stack-layout";
import {GridLayout, ItemSpec} from "ui/layouts/grid-layout";
import {GridUnitType} from "ui/layouts/grid-layout";
import {HorizontalAlignment} from "ui/enums";
import {Label} from "ui/label";
import {GestureTypes} from "ui/gestures";
import {View} from "ui/core/view";
import {Visibility} from "ui/enums";
import {fromFile} from "image-source";
import {fromResource} from "image-source";
import {fromFile, fromResource} from "image-source";

@Directive({selector: '[carousel]'})
export class CarouselDirective implements AfterViewInit {
Expand Down Expand Up @@ -40,6 +36,8 @@ export class CarouselDirective implements AfterViewInit {
@Input() carouselLabelOverlay: boolean; // title over image (bool)
@Input() carouselAnimationSpeed: number; // animation speed

@Output() selectedImageChange: EventEmitter<string> = new EventEmitter<string>();

constructor(private elem: ElementRef) {
this.container = elem.nativeElement;
}
Expand Down Expand Up @@ -128,16 +126,25 @@ export class CarouselDirective implements AfterViewInit {

if (slide.url) {
let image: Image = CarouselDirective.generateImageSliderFromUrl(slide.url);
image.on(GestureTypes.tap, () => {
this.selectedImageChange.emit( slide.title );
});
gridLayout.addChild(image);
}

if (slide.file && slide.file.indexOf('res://') !== 0) {
let image: Image = CarouselDirective.generateImageSliderFromFile(slide.file);
image.on(GestureTypes.tap, () => {
this.selectedImageChange.emit( slide.title );
});
gridLayout.addChild(image);
}

if (slide.file && slide.file.indexOf('res://') === 0) {
let image: Image = CarouselDirective.generateImageSliderFromResource(slide.file);
image.on(GestureTypes.tap, () => {
this.selectedImageChange.emit( slide.title );
});
gridLayout.addChild(image);
}

Expand Down
47 changes: 47 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.