Skip to content

Commit 39c9c64

Browse files
Merge pull request #19 from TheOriginalJosh/ng2-compatability-update
adding angular property. for ng2 compatibility
2 parents c5b6ebc + 91db93b commit 39c9c64

File tree

4 files changed

+36
-10
lines changed

4 files changed

+36
-10
lines changed

README.md

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,22 +75,25 @@ the `<Slides:SlideContainer>` element also has a property called `velocityScroll
7575

7676
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>`), it can be restarted with `startSlidShow`.
7777

78+
#### Angular 2 compatibility
79+
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()`.
80+
7881
#### Android Optional Attributes
7982
- `androidTranslucentStatusBar`: boolean - If true, the Android status bar will be translucent on devices that support it. (Android sdk >= 19).
8083
- `androidTranslucentNavBar`: boolean - If true, the Android navigation bar will be translucent on devices that support it. (Android sdk >= 19).
8184

82-
###Plugin Development Work Flow:
85+
#### Plugin Development Work Flow:
8386

8487
* Clone repository to your machine.
8588
* Run `npm run setup` to prepare the demo project
8689
* Build with `npm run build`
8790
* Run and deploy to your device or emulator with `npm run demo.android` or `npm run demo.ios`
8891

89-
###Known issues
92+
#### Known issues
9093

9194
* There apears to be a bug with the loop resulting in bad transitions going right to left.
9295

93-
### Smoother panning on Android (For {N} v2.0.0 and below __only__).
96+
#### Smoother panning on Android (For {N} v2.0.0 and below __only__).
9497

9598
To achieve a much smoother drag on android simply go into the gestures.android.js file in the tns-core-modules here
9699

nativescript-slides.d.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ export declare class SlideContainer extends AbsoluteLayout {
1919
private _androidTranslucentStatusBar;
2020
private _androidTranslucentNavBar;
2121
private timer_reference;
22+
private _angular;
2223
hasNext: boolean;
2324
hasPrevious: boolean;
2425
interval: number;
@@ -27,11 +28,12 @@ export declare class SlideContainer extends AbsoluteLayout {
2728
androidTranslucentNavBar: boolean;
2829
velocityScrolling: boolean;
2930
pageWidth: number;
31+
angular: boolean;
3032
android: any;
3133
ios: any;
3234
constructor();
3335
private setupDefaultValues();
34-
constructView(): void;
36+
constructView(constructor?: boolean): void;
3537
private carousel(isenabled, time);
3638
private rebindSlideShow();
3739
stopSlideshow(): void;

nativescript-slides.ts

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ export class SlideContainer extends AbsoluteLayout {
4242
private _androidTranslucentStatusBar: boolean;
4343
private _androidTranslucentNavBar: boolean;
4444
private timer_reference: number;
45+
private _angular: boolean;
4546

4647
get hasNext(): boolean {
4748
return !!this.currentPanel.right;
@@ -93,6 +94,14 @@ export class SlideContainer extends AbsoluteLayout {
9394
return this._pageWidth;
9495
}
9596

97+
get angular(): boolean {
98+
return this._angular;
99+
}
100+
101+
set angular(value: boolean) {
102+
this._angular = value;
103+
}
104+
96105
get android(): any {
97106
return;
98107
}
@@ -103,34 +112,46 @@ export class SlideContainer extends AbsoluteLayout {
103112

104113
constructor() {
105114
super();
106-
this.constructView();
115+
this.setupDefaultValues();
116+
// if being used in an ng2 app we want to prevent it from excuting the constructView
117+
// until it is called manually in ngAfterViewInit.
118+
119+
this.constructView(true);
120+
107121
}
108122

109123
private setupDefaultValues(): void {
110124
this._loaded = false;
111125
if (this._loop == null) {
112126
this.loop = false;
113127
}
128+
114129
this.transitioning = false;
115130

116131
this._pageWidth = Platform.screen.mainScreen.widthDIPs;
117132

118133
if (this._interval == null) {
119-
this._interval = 0;
134+
this.interval = 0;
120135
}
121136

122137
if (this._velocityScrolling == null) {
123138
this._velocityScrolling = false;
124139
}
140+
if (this._angular == null) {
141+
this.angular = false;
142+
}
125143

126144
}
127-
constructView(): void {
128-
this.setupDefaultValues();
145+
146+
public constructView(constructor: boolean = false): void {
147+
129148

130149
this.on(AbsoluteLayout.loadedEvent, (data: any) => {
131150
if (!this._loaded) {
132151
this._loaded = true;
133-
152+
if (this.angular === true && constructor === true) {
153+
return;
154+
}
134155
// Android Translucent bars API >= 19 only
135156
if (this.androidTranslucentStatusBar === true || this._androidTranslucentNavBar === true && app.android && Platform.device.sdkVersion >= '19') {
136157
let window = app.android.startActivity.getWindow();

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "nativescript-slides",
3-
"version": "1.2.0",
3+
"version": "1.3.1",
44
"description": "NativeScript Slides plugin.",
55
"main": "nativescript-slides.js",
66
"nativescript": {

0 commit comments

Comments
 (0)