Skip to content

Commit 92a0721

Browse files
Merge pull request #36 from sitefinitysteve/master
Add Events
2 parents b7d9ba0 + ff1fdb8 commit 92a0721

File tree

7 files changed

+80
-12
lines changed

7 files changed

+80
-12
lines changed

README.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,11 @@ add as many ``<Slides:Slide>`` as you want.
8686

8787
- **disablePan : boolean** - If true panning is disabled. So that you can call nextSlide()/previousSlide() functions to change the slide. If slides is used to get details about users like email, phone number, username etc. in this case you don't want users to move from one slide to another slide without filling details.
8888

89+
#### Events
90+
- **start** - Start pan
91+
- **changed** - Transition complete
92+
- **cancelled** - User didn't complete the transition
93+
8994
#### Angular 2 compatibility
9095
To use the slides with Angular2 and the `registerElement` from `nativescript-angular` you will want to set the `SlideContainer`'s property of `angular` to `true`. Then in your angular component in the `ngAfterViewInit`. you will want to have an instance of your slide container to call the function `constructView()`.
9196

@@ -153,6 +158,8 @@ _please note this will change the panning gesture for your entire project._
153158

154159
[Victor Nascimento](https://github.com/vjoao)
155160

161+
[Steve McNiven-Scott](https://github.com/sitefinitysteve)
162+
156163
And thanks to [Nathan Walker](https://github.com/NathanWalker) for setting up the {N} plugin seed that was used to help get this plugin up and running. More info can be found about it here:
157164
https://github.com/NathanWalker/nativescript-plugin-seed
158165

demo/app/app.css

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,26 @@
11
.slide-1{
2-
background-color: darkslateblue;
2+
background-color: #448AFF;
33
}
44

55
.slide-2{
6-
background-color: lightcyan;
6+
background-color: #F44336;
77
}
88
.slide-3{
9-
background-color: darkgreen;
10-
}
9+
background-color: #8BC34A;
10+
}
1111

1212
.slide-4{
13-
background-color: darkgoldenrod;
13+
background-color: #9C27B0;
1414
}
1515
.slide-5{
16-
background-color: darkslategray;
16+
background-color: #FFC107;
1717
}
1818

1919
Label{
2020
text-align: center;
2121
width: 100%;
2222
font-size: 35;
2323
margin-top: 35;
24+
color: #FFF;
2425
}
2526

demo/app/main-page.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,19 @@ export function next() {
1818

1919
export function prev() {
2020
slideContainer.previousSlide();
21+
}
22+
23+
export function onStart(args){
24+
var data = args.eventData;
25+
console.log("Start: " + JSON.stringify(data));
26+
}
27+
28+
export function onChanged(args){
29+
var data = args.eventData;
30+
console.log("Changed: " + JSON.stringify(data));
31+
}
32+
33+
export function onCancelled(args){
34+
var data = args.eventData;
35+
console.log("Cancelled: " + JSON.stringify(data));
2136
}

demo/app/main-page.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<Page xmlns="http://schemas.nativescript.org/tns.xsd" xmlns:Slides="nativescript-slides" loaded="pageLoaded">
22

33
<GridLayout rows="* auto">
4-
<Slides:SlideContainer id="slides" row="0" pageIndicators="true" androidTranslucentStatusBar ="true">
4+
<Slides:SlideContainer id="slides" row="0" pageIndicators="true" androidTranslucentStatusBar="true" start="onStart" cancelled="onCancelled" changed="onChanged">
55
<Slides:Slide class="slide-1">
66
<Label text="This is Panel 1" />
77
</Slides:Slide>

nativescript-slides.d.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@ export declare class SlideContainer extends AbsoluteLayout {
2626
private _footer;
2727
private _pageIndicators;
2828
private _indicatorsColor;
29+
static startEvent: string;
30+
static changedEvent: string;
31+
static cancelledEvent: string;
2932
pageIndicators: boolean;
3033
indicatorsColor: string;
3134
hasNext: boolean;

nativescript-slides.ts

Lines changed: 40 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,10 @@ export class SlideContainer extends AbsoluteLayout {
5353
private _pageIndicators: boolean;
5454
private _indicatorsColor: string;
5555

56+
public static startEvent = "start";
57+
public static changedEvent = "changed";
58+
public static cancelledEvent = "cancelled";
59+
5660
/* page indicator stuff*/
5761
get pageIndicators(): boolean {
5862
return this._pageIndicators;
@@ -187,8 +191,6 @@ export class SlideContainer extends AbsoluteLayout {
187191
}
188192

189193
public constructView(constructor: boolean = false): void {
190-
191-
192194
this.on(AbsoluteLayout.loadedEvent, (data: any) => {
193195
if (!this._loaded) {
194196
this._loaded = true;
@@ -349,11 +351,18 @@ export class SlideContainer extends AbsoluteLayout {
349351
let startTime, deltaTime;
350352

351353
this.currentPanel.panel.on('pan', (args: gestures.PanGestureEventData): void => {
352-
353354
if (args.state === gestures.GestureStateTypes.began) {
354355
startTime = Date.now();
355356
previousDelta = 0;
356357
endingVelocity = 250;
358+
359+
this.notify({
360+
eventName: SlideContainer.startEvent,
361+
object: this,
362+
eventData: {
363+
currentIndex: this.currentPanel.index
364+
}
365+
});
357366
} else if (args.state === gestures.GestureStateTypes.ended) {
358367
deltaTime = Date.now() - startTime;
359368
// if velocityScrolling is enabled then calculate the velocitty
@@ -366,6 +375,16 @@ export class SlideContainer extends AbsoluteLayout {
366375
this.transitioning = true;
367376
this.showLeftSlide(this.currentPanel, args.deltaX, endingVelocity).then(() => {
368377
this.setupPanel(this.currentPanel.left);
378+
379+
this.notify({
380+
eventName: SlideContainer.changedEvent,
381+
object: this,
382+
eventData: {
383+
direction: direction.left,
384+
newIndex: this.currentPanel.index,
385+
oldIndex: this.currentPanel.index + 1
386+
}
387+
});
369388
});
370389
}
371390
return;
@@ -374,12 +393,30 @@ export class SlideContainer extends AbsoluteLayout {
374393
this.transitioning = true;
375394
this.showRightSlide(this.currentPanel, args.deltaX, endingVelocity).then(() => {
376395
this.setupPanel(this.currentPanel.right);
396+
397+
this.notify({
398+
eventName: SlideContainer.changedEvent,
399+
object: this,
400+
eventData: {
401+
direction: direction.right,
402+
newIndex: this.currentPanel.index,
403+
oldIndex: this.currentPanel.index - 1
404+
}
405+
});
377406
});
378407
}
379408
return;
380409
}
381410

382411
if (this.transitioning === false) {
412+
this.notify({
413+
eventName: SlideContainer.cancelledEvent,
414+
object: this,
415+
eventData: {
416+
currentIndex: this.currentPanel.index
417+
}
418+
});
419+
383420
this.transitioning = true;
384421
this.currentPanel.panel.animate({
385422
translate: { x: -this.pageWidth, y: 0 },

package.json

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "nativescript-slides",
3-
"version": "1.5.4",
3+
"version": "1.5.5",
44
"description": "NativeScript Slides plugin.",
55
"main": "nativescript-slides.js",
66
"nativescript": {
@@ -9,7 +9,7 @@
99
"ios": "2.0.0"
1010
},
1111
"tns-ios": {
12-
"version": "2.0.0"
12+
"version": "2.0.1"
1313
}
1414
},
1515
"scripts": {
@@ -55,6 +55,11 @@
5555
"name": "Victor Nascimento",
5656
"email": "victormota15@gmail.com",
5757
"url": "https://github.com/vjoao"
58+
},
59+
{
60+
"name": "Steve McNiven-Scott",
61+
"email": "steve@sitefinitysteve.com",
62+
"url": "https://github.com/sitefinitysteve"
5863
}
5964
],
6065
"bugs": {

0 commit comments

Comments
 (0)