Skip to content

Commit 41dc42e

Browse files
Merge pull request #3 from Obsessive/master
Added the interval feature
2 parents efc719b + 0c3eadd commit 41dc42e

File tree

4 files changed

+41
-3
lines changed

4 files changed

+41
-3
lines changed

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,8 @@ the `SlideContainer` class also has public `nextSlide` and `previousSlide` funct
6464

6565
the `<Slides:SlideContainer>` element also has a property called `loop` which is a boolean value and if set to true will cause the slide to be an endless loop. The suggested use case would be for a Image Carousel or something of that nature.
6666

67+
the `<Slides:SlideContainer>` element also has a property called `interval` which is a integer value and the value is in milliseconds. The suggested use case would be for a Image Carousel or something of that nature which can change the image for every fixed intervals. In unloaded function call page.getViewById("your_id").stopSlideshow() to unregister it (your_id is the id given to `<Slides:SlideContainer>`).
68+
6769
#### Android Optional Attribute
6870
- `AndroidTransparentStatusBar`: boolean - If true, the Android status bar will be transparent on devices that support it. Typically this is API >=21 (Lollipop).
6971

@@ -124,4 +126,4 @@ https://github.com/NathanWalker/nativescript-plugin-seed
124126

125127
[MIT](/LICENSE)
126128

127-
for {N} version 2.0.0+
129+
for {N} version 2.0.0+

nativescript-slides.d.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,17 @@ export declare class SlideContainer extends AbsoluteLayout {
1515
private direction;
1616
private _loop;
1717
private _AndroidTransparentStatusBar;
18+
private timer_reference;
19+
private _interval;
20+
interval: number;
1821
loop: boolean;
1922
AndroidTransparentStatusBar: boolean;
2023
pageWidth: number;
2124
android: any;
2225
ios: any;
2326
constructor();
2427
constructView(): void;
28+
stopSlideshow(): void;
2529
nextSlide(): void;
2630
previousSlide(): void;
2731
private setupLeftPanel();
@@ -33,4 +37,5 @@ export declare class SlideContainer extends AbsoluteLayout {
3337
private setwidthPercent(view, percentage);
3438
private newFooterButton(name);
3539
private buildSlideMap(views);
40+
private carousel(isenabled, time);
3641
}

nativescript-slides.ts

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,20 @@ export class SlideContainer extends AbsoluteLayout {
2828
private _pageWidth: number;
2929
private transitioning: boolean;
3030
private direction: direction = direction.none;
31+
private _loop: boolean;
32+
private _interval: number;
33+
private _AndroidTransparentStatusBar: boolean;
3134
private _loop: boolean
3235
private _AndroidTransparentStatusBar: boolean;
3336

37+
get interval() {
38+
return this._interval;
39+
}
40+
41+
set interval(value: boolean) {
42+
this._interval = value;
43+
}
44+
3445
get loop() {
3546
return this._loop;
3647
}
@@ -122,6 +133,18 @@ export class SlideContainer extends AbsoluteLayout {
122133

123134
}
124135

136+
private carousel(isenabled: boolean,time: number) {
137+
if (isenabled) {
138+
this.timer_reference = setInterval(() => {
139+
this.nextSlide();
140+
},time);
141+
}else {
142+
clearTimeout(this.timer_reference);
143+
}
144+
}
145+
public stopSlideshow() {
146+
this.carousel(false,0);
147+
}
125148
public nextSlide() {
126149
this.transitioning = true;
127150
this.showRightSlide(this.currentPanel).then(() => {
@@ -319,6 +342,9 @@ export class SlideContainer extends AbsoluteLayout {
319342
slideMap[0].left = slideMap[slideMap.length - 1];
320343
slideMap[slideMap.length - 1].right = slideMap[0];
321344
}
345+
if (this.interval !== 0) {
346+
this.carousel(true,this.interval);
347+
}
322348
return slideMap[0];
323349
}
324350
}

package.json

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,12 @@
4242
"name": "Brad Martin",
4343
"email": "bradwaynemartin@gmail.com",
4444
"url": "https://github.com/bradmartin"
45-
}
45+
},
46+
{
47+
"name": "Obsessive Inc/Abhijith Reddy",
48+
"email": "mabhijith95a10@gmail.com",
49+
"url": "https://github.com/Obsessive"
50+
}
4651
],
4752
"bugs": {
4853
"url": "https://github.com/TheOriginalJosh/nativescript-slides/issues"
@@ -56,4 +61,4 @@
5661
"devDependencies": {
5762
"typescript": "^1.8.7"
5863
}
59-
}
64+
}

0 commit comments

Comments
 (0)