Skip to content

Commit 7157310

Browse files
committed
adding ng2 property.
basically we don’t want the constructView function to fire for angular to so that it can be called latter in ngAfterViewInit
1 parent c5b6ebc commit 7157310

File tree

4 files changed

+28
-5
lines changed

4 files changed

+28
-5
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 `ng2` 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

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">
4+
<Slides:SlideContainer id="slides" ng2="true" row="0">
55
<Slides:Slide class="slide-1">
66
<Label text="This is Panel 1" />
77
</Slides:Slide>

nativescript-slides.d.ts

Lines changed: 2 additions & 0 deletions
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 _ng2;
2223
hasNext: boolean;
2324
hasPrevious: boolean;
2425
interval: number;
@@ -27,6 +28,7 @@ export declare class SlideContainer extends AbsoluteLayout {
2728
androidTranslucentNavBar: boolean;
2829
velocityScrolling: boolean;
2930
pageWidth: number;
31+
ng2: boolean;
3032
android: any;
3133
ios: any;
3234
constructor();

nativescript-slides.ts

Lines changed: 19 additions & 1 deletion
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 _ng2: 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 ng2(): boolean {
98+
return this._ng2;
99+
}
100+
101+
set ng2(value: boolean) {
102+
this._ng2 = value;
103+
}
104+
96105
get android(): any {
97106
return;
98107
}
@@ -122,10 +131,19 @@ export class SlideContainer extends AbsoluteLayout {
122131
if (this._velocityScrolling == null) {
123132
this._velocityScrolling = false;
124133
}
134+
if (this._ng2 == null) {
135+
this._ng2 = false;
136+
}
125137

126138
}
127-
constructView(): void {
139+
140+
public constructView(): void {
128141
this.setupDefaultValues();
142+
// if being used in an ng2 app we want to prevent it from excuting the constructView
143+
// until it is called manually in ngAfterViewInit.
144+
if (this.ng2) {
145+
return;
146+
}
129147

130148
this.on(AbsoluteLayout.loadedEvent, (data: any) => {
131149
if (!this._loaded) {

0 commit comments

Comments
 (0)