@@ -2,39 +2,33 @@ import * as app from 'application';
22import * as Platform from 'platform' ;
33import { AbsoluteLayout } from 'ui/layouts/absolute-layout' ;
44import { StackLayout } from 'ui/layouts/stack-layout' ;
5- import { View , AddChildFromBuilder } from 'ui/core/view' ;
5+ import { View } from 'ui/core/view' ;
66import { Button } from 'ui/button' ;
7- import { SlideUtilities , ISlideMap } from './utilities' ;
87import { Label } from 'ui/label' ;
98import * as AnimationModule from 'ui/animation' ;
109import * as gestures from 'ui/gestures' ;
1110
12- export class Slide extends StackLayout {
11+ export class Slide extends StackLayout { }
1312
14- }
1513enum 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