Skip to content

Commit 9b99e9e

Browse files
committed
1.0.0 Release
1 parent 90ad1f1 commit 9b99e9e

File tree

7 files changed

+140
-209
lines changed

7 files changed

+140
-209
lines changed

README.md

Lines changed: 44 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Nativescript Intro Slides for iOS and Android
22

3-
[![Nativescript Intro Slides. Click to Play](https://img.youtube.com/vi/5GGGiNA98TU/0.jpg)](https://www.youtube.com/embed/5GGGiNA98TU)
3+
[![Nativescript Intro Slides. Click to Play](https://img.youtube.com/vi/1AatGtPA6J8/0.jpg)](https://www.youtube.com/embed/1AatGtPA6J8)
44

55
Beta
66
###XML
@@ -59,24 +59,57 @@ when using the intro slide plugin you need at least two ``<IntroSlides:Slide>``
5959

6060
add as many ``<IntroSlides:Slide>`` as you want.
6161

62-
### Planned additions:
63-
64-
* disable/enable previous and next buttons
65-
* Add function and property for button text, for next button on the last slide.
66-
* add properties to override previous and next buttons text.
67-
68-
### Known Issues:
69-
* Breaks on screen rotation. will be fixed.
62+
the `IntroSlides` class also has public `nextSlide` and `previousSlide` functions so you can add your own previous and next buttons as needed.
7063

7164
###Plugin Development Work Flow:
7265

7366
* Clone repository to your machine.
74-
* First run `npm install`
75-
* Then run `npm run setup` to prepare the demo project
67+
* Run `npm run setup` to prepare the demo project
7668
* Build with `npm run build`
7769
* Run and deploy to your device or emulator with `npm run demo.android` or `npm run demo.ios`
7870

7971

72+
### Smoother panning on Android.
73+
74+
To achieve a much smoother drag on android simply go into the gestures.android.js file in the tns-core-modules here
75+
76+
77+
`/node_modules/tns-core-modules/ui/gestures/gestures.android.js`
78+
79+
and change
80+
81+
```javascript
82+
CustomPanGestureDetector.prototype.getMotionEventCenter = function (event) {
83+
var count = event.getPointerCount();
84+
var res = { x: 0, y: 0 };
85+
for (var i = 0; i < count; i++) {
86+
res.x += event.getX(i);
87+
res.y += event.getY(i);
88+
}
89+
res.x /= (count * this.density);
90+
res.y /= (count * this.density);
91+
return res;
92+
};
93+
```
94+
95+
to
96+
```javascript
97+
CustomPanGestureDetector.prototype.getMotionEventCenter = function (event) {
98+
var count = event.getPointerCount();
99+
var res = { x: 0, y: 0 };
100+
for (var i = 0; i < count; i++) {
101+
res.x += event.getRawX();
102+
res.y += event.getRawY();
103+
}
104+
res.x /= (count * this.density);
105+
res.y /= (count * this.density);
106+
return res;
107+
};
108+
```
109+
110+
_please note this will change the panning gesture for your entire project._
111+
112+
80113
###Special thanks to:
81114
Thanks to [Nathan Walker](https://github.com/NathanWalker) for setting up the {N} plugin seed that I used to help get this plugin up and running. More info can be found about it here:
82115
https://github.com/NathanWalker/nativescript-plugin-seed

nativescript-intro-slides.d.ts

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,32 @@
11
import { AbsoluteLayout } from 'ui/layouts/absolute-layout';
22
import { StackLayout } from 'ui/layouts/stack-layout';
3-
import { AddChildFromBuilder } from 'ui/core/view';
4-
import { Button } from 'ui/button';
5-
import { ISlideMap } from './utilities';
6-
import * as AnimationModule from 'ui/animation';
73
export declare class Slide extends StackLayout {
84
}
9-
export declare class IntroSlides extends AbsoluteLayout implements AddChildFromBuilder {
10-
private _childSlides;
5+
export interface ISlideMap {
6+
panel: StackLayout;
7+
left?: ISlideMap;
8+
right?: ISlideMap;
9+
}
10+
export declare class IntroSlides extends AbsoluteLayout {
1111
private _loaded;
1212
private currentPanel;
1313
private _pageWidth;
14-
private _btnNext;
15-
private _btnPrevious;
1614
private transitioning;
1715
private direction;
18-
btnNext: Button;
19-
btnPrevious: Button;
2016
pageWidth: number;
2117
android: any;
2218
ios: any;
2319
constructor();
2420
constructView(): void;
21+
nextSlide(): void;
22+
previousSlide(): void;
2523
private setupLeftPanel();
2624
private setupRightPanel();
27-
_addChildFromBuilder: (name: string, value: any) => void;
2825
private applySwipe(pageWidth);
29-
showRightSlide(panelMap: ISlideMap, offset?: number): AnimationModule.AnimationPromise;
30-
showLeftSlide(panelMap: ISlideMap, offset?: number): AnimationModule.AnimationPromise;
26+
private showRightSlide(panelMap, offset?);
27+
private showLeftSlide(panelMap, offset?);
3128
private buildFooter();
3229
private setwidthPercent(view, percentage);
3330
private newFooterButton(name);
31+
private buildSlideMap(views);
3432
}

nativescript-intro-slides.ts

Lines changed: 82 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -2,39 +2,33 @@ import * as app from 'application';
22
import * as Platform from 'platform';
33
import {AbsoluteLayout} from 'ui/layouts/absolute-layout';
44
import {StackLayout} from 'ui/layouts/stack-layout';
5-
import {View, AddChildFromBuilder} from 'ui/core/view';
5+
import {View} from 'ui/core/view';
66
import { Button } from 'ui/button';
7-
import {SlideUtilities, ISlideMap} from './utilities';
87
import {Label} from 'ui/label';
98
import * as AnimationModule from 'ui/animation';
109
import * as gestures from 'ui/gestures';
1110

12-
export class Slide extends StackLayout {
11+
export class Slide extends StackLayout { }
1312

14-
}
1513
enum direction {
1614
none,
1715
left,
1816
right
1917
}
20-
export class IntroSlides extends AbsoluteLayout implements AddChildFromBuilder {
2118

22-
private _childSlides: View[];
19+
export interface ISlideMap {
20+
panel: StackLayout;
21+
left?: ISlideMap;
22+
right?: ISlideMap;
23+
}
24+
25+
export class IntroSlides extends AbsoluteLayout {
2326
private _loaded: boolean;
2427
private currentPanel: ISlideMap;
2528
private _pageWidth: number;
26-
private _btnNext: Button;
27-
private _btnPrevious: Button;
2829
private transitioning: boolean;
2930
private direction: direction = direction.none;
3031

31-
get btnNext() {
32-
return this._btnNext;
33-
}
34-
35-
get btnPrevious() {
36-
return this._btnPrevious;
37-
}
3832

3933
get pageWidth() {
4034
return this._pageWidth;
@@ -48,6 +42,7 @@ export class IntroSlides extends AbsoluteLayout implements AddChildFromBuilder {
4842
return;
4943
}
5044

45+
5146
constructor() {
5247
super();
5348
this.constructView();
@@ -57,21 +52,15 @@ export class IntroSlides extends AbsoluteLayout implements AddChildFromBuilder {
5752

5853
this._loaded = false;
5954
this.transitioning = false;
60-
this._childSlides = [];
6155

6256
this._pageWidth = Platform.screen.mainScreen.widthDIPs;
63-
const pageHeight = Platform.screen.mainScreen.heightDIPs;
57+
58+
6459

6560
this.on(AbsoluteLayout.loadedEvent, (data: any) => {
6661
if (!this._loaded) {
6762
this._loaded = true;
6863

69-
let footer = this.buildFooter();
70-
71-
this._btnPrevious = <Button>footer.getViewById('btn-info-previous');
72-
this._btnNext = <Button>footer.getViewById('btn-info-next');
73-
74-
let info = <Label>footer.getViewById('info');
7564
let slides: StackLayout[] = [];
7665

7766
this.eachLayoutChild((view: View) => {
@@ -82,82 +71,87 @@ export class IntroSlides extends AbsoluteLayout implements AddChildFromBuilder {
8271
slides.push(view);
8372
}
8473
});
85-
this.currentPanel = SlideUtilities.buildSlideMap(slides);
86-
87-
this.btnNext.on('tap', () => {
88-
this.transitioning = true;
89-
this.showRightSlide(this.currentPanel).then(() => {
90-
console.log('right button done');
91-
this.setupRightPanel();
74+
this.currentPanel = this.buildSlideMap(slides);
75+
this.currentPanel.panel.translateX = -this.pageWidth;
76+
this.applySwipe(this.pageWidth);
9277

78+
app.on(app.orientationChangedEvent, (args: app.OrientationChangedEventData) => {
79+
this._pageWidth = Platform.screen.mainScreen.widthDIPs;
80+
this.eachLayoutChild((view: View) => {
81+
if (view instanceof StackLayout) {
82+
AbsoluteLayout.setLeft(view, this.pageWidth);
83+
view.width = this.pageWidth;
84+
}
9385
});
86+
this.applySwipe(this.pageWidth);
87+
this.currentPanel.panel.translateX = -this.pageWidth;
9488
});
95-
this.btnPrevious.on('tap', () => {
96-
this.transitioning = true;
97-
this.showLeftSlide(this.currentPanel).then(() => {
98-
this.setupLeftPanel();
99-
});
100-
});
101-
// this.addChild(footer);
10289

103-
if (isNaN(footer.height)) {
104-
footer.height = 76; //footer min height
105-
}
106-
AbsoluteLayout.setTop(footer, (pageHeight - footer.height));
107-
this.currentPanel.panel.translateX = -this.pageWidth;
108-
this.btnPrevious.visibility = 'collapse';
109-
this.applySwipe(this.pageWidth);
11090
}
11191
});
11292

11393
}
94+
95+
public nextSlide() {
96+
this.transitioning = true;
97+
this.showRightSlide(this.currentPanel).then(() => {
98+
this.setupRightPanel();
99+
});
100+
}
101+
public previousSlide() {
102+
this.transitioning = true;
103+
this.showRightSlide(this.currentPanel).then(() => {
104+
this.setupRightPanel();
105+
});
106+
}
107+
114108
private setupLeftPanel() {
115109
this.direction = direction.none;
116110
this.transitioning = false;
117-
this.btnNext.visibility = 'visible';
118-
this.btnPrevious.visibility = 'visible';
119-
this.currentPanel.panel.off('touch,pan');
111+
this.currentPanel.panel.off('pan');
120112
this.currentPanel = this.currentPanel.left;
121113
this.applySwipe(this.pageWidth);
122-
if (this.currentPanel.left == null) {
123-
this.btnPrevious.visibility = 'collapse';
124-
}
125114
}
126115

127116
private setupRightPanel() {
128117
this.direction = direction.none;
129118
this.transitioning = false;
130-
this.btnNext.visibility = 'visible';
131-
this.btnPrevious.visibility = 'visible';
132-
this.currentPanel.panel.off('touch,pan');
119+
this.currentPanel.panel.off('pan');
133120
this.currentPanel = this.currentPanel.right;
134121
this.applySwipe(this.pageWidth);
135-
if (this.currentPanel.right == null) {
136-
this.btnNext.visibility = 'collapse';
137-
}
138122
}
139123

140-
_addChildFromBuilder = (name: string, value: any) => {
141-
if (value instanceof View) {
142-
if (value instanceof Slide) {
143-
this._childSlides.push(value);
144-
}
145-
this.addChild(value);
146-
}
147-
};
148-
149124
private applySwipe(pageWidth: number) {
150125
let previousDelta = -1; //hack to get around ios firing pan event after release
151126

152127
this.currentPanel.panel.on('pan', (args: gestures.PanGestureEventData): void => {
153128
if (args.state === gestures.GestureStateTypes.ended) {
154129
if (this.transitioning === false) {
155130
this.transitioning = true;
156-
this.currentPanel.panel.translateX = -this.pageWidth;
131+
this.currentPanel.panel.animate({
132+
translate: { x: -this.pageWidth, y: 0 },
133+
duration: 250,
134+
});
157135
if (this.currentPanel.right != null) {
158-
this.currentPanel.right.panel.translateX = -this.pageWidth;
159-
this.currentPanel.right.panel.translateX = this.pageWidth;
136+
this.currentPanel.right.panel.animate({
137+
translate: { x: 0, y: 0 },
138+
duration: 250,
139+
});
140+
if (app.ios) //for some reason i have to set these in ios or there is some sort of bounce back.
141+
this.currentPanel.right.panel.translateX = 0;
160142
}
143+
if (this.currentPanel.left != null) {
144+
this.currentPanel.left.panel.animate({
145+
translate: { x: -this.pageWidth * 2, y: 0 },
146+
duration: 250,
147+
});
148+
if (app.ios)
149+
this.currentPanel.left.panel.translateX = -this.pageWidth;
150+
151+
}
152+
if (app.ios)
153+
this.currentPanel.panel.translateX = -this.pageWidth;
154+
161155
this.transitioning = false;
162156

163157
}
@@ -200,7 +194,7 @@ export class IntroSlides extends AbsoluteLayout implements AddChildFromBuilder {
200194
});
201195
}
202196

203-
public showRightSlide(panelMap: ISlideMap, offset: number = 0): AnimationModule.AnimationPromise {
197+
private showRightSlide(panelMap: ISlideMap, offset: number = 0): AnimationModule.AnimationPromise {
204198
let transition = new Array();
205199
transition.push({
206200
target: panelMap.right.panel,
@@ -216,21 +210,19 @@ export class IntroSlides extends AbsoluteLayout implements AddChildFromBuilder {
216210
let animationSet = new AnimationModule.Animation(transition, false);
217211

218212
return animationSet.play();
219-
// panelMap.panel.off('pan');
220-
// this.applySwipe(info, wrapper, pageWidth, panelMap.right, this.btnPrevious, btnNext);
221213
}
222214

223-
public showLeftSlide(panelMap: ISlideMap, offset: number = 0): AnimationModule.AnimationPromise {
215+
private showLeftSlide(panelMap: ISlideMap, offset: number = 0): AnimationModule.AnimationPromise {
224216
let transition = new Array();
225217
transition.push({
226218
target: panelMap.left.panel,
227219
translate: { x: -this.pageWidth, y: 0 },
228-
duration: 500,
220+
duration: 300,
229221
});
230222
transition.push({
231223
target: panelMap.panel,
232224
translate: { x: 0, y: 0 },
233-
duration: 500,
225+
duration: 300,
234226
});
235227

236228
let animationSet = new AnimationModule.Animation(transition, false);
@@ -278,5 +270,21 @@ export class IntroSlides extends AbsoluteLayout implements AddChildFromBuilder {
278270
this.setwidthPercent(button, 100);
279271
return button;
280272
}
273+
274+
private buildSlideMap(views: StackLayout[]) {
275+
let slideMap: ISlideMap[] = [];
276+
views.forEach((view: StackLayout) => {
277+
slideMap.push({
278+
panel: view
279+
});
280+
});
281+
slideMap.forEach((mapping: ISlideMap, index: number) => {
282+
if (slideMap[index - 1] != null)
283+
mapping.left = slideMap[index - 1];
284+
if (slideMap[index + 1] != null)
285+
mapping.right = slideMap[index + 1];
286+
});
287+
return slideMap[0];
288+
}
281289
}
282290

0 commit comments

Comments
 (0)