1- import { Component , OnInit , OnDestroy } from "@angular/core" ;
1+ import { Component , OnInit , OnDestroy , AfterViewInit } from "@angular/core" ;
22import { ExampleItem } from "../exampleItem" ;
33import { ExampleItemService } from "../exampleItemService.service" ;
44import * as frameModule from "tns-core-modules/ui/frame" ;
55import { ActivatedRoute , Router } from '@angular/router' ;
6+ import { RadSideDrawer , FadeTransition , PushTransition , RevealTransition , ReverseSlideOutTransition , ScaleDownPusherTransition , ScaleUpTransition , SlideAlongTransition , SlideInOnTopTransition } from "nativescript-ui-sidedrawer" ;
7+ import { getRootView } from "tns-core-modules/application" ;
8+ import { Page } from "tns-core-modules/ui/page" ;
69
710@Component ( {
811 moduleId : module . id ,
912 selector : "tk-examples" ,
1013 templateUrl : "examples-list.component.html" ,
1114 styleUrls : [ "examples-list.component.css" ]
1215} )
13- export class ExamplesListDepth1Component implements OnInit , OnDestroy {
16+ export class ExamplesListDepth1Component implements OnInit , AfterViewInit , OnDestroy {
1417 private _currentExample : ExampleItem ;
1518 private _hasBack : boolean ;
1619 private _sub : any ;
20+ private _rootDrawer : RadSideDrawer ;
1721
18- constructor ( private _router : Router , private _route : ActivatedRoute , private _exampleItemsService : ExampleItemService ) {
22+ constructor ( private _router : Router , private _route : ActivatedRoute , private _exampleItemsService : ExampleItemService , private page : Page ) {
1923
2024 }
2125
@@ -26,12 +30,21 @@ export class ExamplesListDepth1Component implements OnInit, OnDestroy {
2630 this . hasBack = false ;
2731 this . _currentExample = this . _exampleItemsService . getParentExampleItem ( 0 ) ;
2832 } ) ;
33+ this . page . on ( Page . loadedEvent , this . onPageLoaded . bind ( this ) ) ;
2934 }
3035
3136 ngOnDestroy ( ) {
3237 this . _sub . unsubscribe ( ) ;
3338 }
3439
40+ ngAfterViewInit ( ) {
41+ this . _rootDrawer = getRootView ( ) as RadSideDrawer ;
42+ }
43+
44+ private onPageLoaded ( args ) {
45+ this . _rootDrawer = getRootView ( ) as RadSideDrawer ;
46+ }
47+
3548 public get currentExample ( ) : ExampleItem {
3649 return this . _currentExample ;
3750 }
@@ -58,6 +71,45 @@ export class ExamplesListDepth1Component implements OnInit, OnDestroy {
5871 }
5972 }
6073
74+ public onChangeTransition ( transition : string ) {
75+ switch ( transition ) {
76+ case "SlideInOnTopTransition" :
77+ this . _rootDrawer . drawerTransition = new SlideInOnTopTransition ( ) ;
78+ break ;
79+ case "FadeTransition" :
80+ this . _rootDrawer . drawerTransition = new FadeTransition ( ) ;
81+ break ;
82+ case "PushTransition" :
83+ this . _rootDrawer . drawerTransition = new PushTransition ( ) ;
84+ break ;
85+ case "RevealTransition" :
86+ this . _rootDrawer . drawerTransition = new RevealTransition ( ) ;
87+ break ;
88+ case "ReverseSlideOutTransition" :
89+ this . _rootDrawer . drawerTransition = new ReverseSlideOutTransition ( ) ;
90+ break ;
91+ case "ScaleDownPusherTransition" :
92+ this . _rootDrawer . drawerTransition = new ScaleDownPusherTransition ( ) ;
93+ break ;
94+ case "ScaleUpTransition" :
95+ this . _rootDrawer . drawerTransition = new ScaleUpTransition ( ) ;
96+ break ;
97+ case "SlideAlongTransition" :
98+ this . _rootDrawer . drawerTransition = new SlideAlongTransition ( ) ;
99+ break ;
100+ default :
101+ break ;
102+ }
103+
104+ console . log ( "Changed drawer transition to" , transition ) ;
105+ }
106+
107+ public onNavBtnTap ( ) {
108+ if ( this . _rootDrawer ) {
109+ this . _rootDrawer . toggleDrawerState ( ) ;
110+ }
111+ }
112+
61113 public onNavigationButtonTap ( ) {
62114 frameModule . topmost ( ) . goBack ( ) ;
63115 }
@@ -70,10 +122,11 @@ export class ExamplesListDepth1Component implements OnInit, OnDestroy {
70122 templateUrl : "examples-list.component.html" ,
71123 styleUrls : [ "examples-list.component.css" ]
72124} )
73- export class ExamplesListDepth2Component implements OnInit , OnDestroy {
125+ export class ExamplesListDepth2Component implements OnInit , AfterViewInit , OnDestroy {
74126 private _currentExample : ExampleItem ;
75127 private _hasBack : boolean ;
76128 private _sub : any ;
129+ private _rootDrawer : RadSideDrawer ;
77130
78131 constructor ( private _router : Router , private _route : ActivatedRoute , private _exampleItemsService : ExampleItemService ) {
79132
@@ -89,6 +142,10 @@ export class ExamplesListDepth2Component implements OnInit, OnDestroy {
89142
90143 }
91144
145+ ngAfterViewInit ( ) {
146+ this . _rootDrawer = getRootView ( ) as RadSideDrawer ;
147+ }
148+
92149 ngOnDestroy ( ) {
93150 this . _sub . unsubscribe ( ) ;
94151 }
@@ -122,6 +179,46 @@ export class ExamplesListDepth2Component implements OnInit, OnDestroy {
122179 public onNavigationButtonTap ( ) {
123180 frameModule . topmost ( ) . goBack ( ) ;
124181 }
182+
183+
184+ public onChangeTransition ( transition : string ) {
185+ switch ( transition ) {
186+ case "SlideInOnTopTransition" :
187+ this . _rootDrawer . drawerTransition = new SlideInOnTopTransition ( ) ;
188+ break ;
189+ case "FadeTransition" :
190+ this . _rootDrawer . drawerTransition = new FadeTransition ( ) ;
191+ break ;
192+ case "PushTransition" :
193+ this . _rootDrawer . drawerTransition = new PushTransition ( ) ;
194+ break ;
195+ case "RevealTransition" :
196+ this . _rootDrawer . drawerTransition = new RevealTransition ( ) ;
197+ break ;
198+ case "ReverseSlideOutTransition" :
199+ this . _rootDrawer . drawerTransition = new ReverseSlideOutTransition ( ) ;
200+ break ;
201+ case "ScaleDownPusherTransition" :
202+ this . _rootDrawer . drawerTransition = new ScaleDownPusherTransition ( ) ;
203+ break ;
204+ case "ScaleUpTransition" :
205+ this . _rootDrawer . drawerTransition = new ScaleUpTransition ( ) ;
206+ break ;
207+ case "SlideAlongTransition" :
208+ this . _rootDrawer . drawerTransition = new SlideAlongTransition ( ) ;
209+ break ;
210+ default :
211+ break ;
212+ }
213+
214+ console . log ( "Changed drawer transition to" , transition ) ;
215+ }
216+
217+ public onNavBtnTap ( ) {
218+ if ( this . _rootDrawer ) {
219+ this . _rootDrawer . toggleDrawerState ( ) ;
220+ }
221+ }
125222}
126223
127224@Component ( {
@@ -130,10 +227,11 @@ export class ExamplesListDepth2Component implements OnInit, OnDestroy {
130227 templateUrl : "examples-list.component.html" ,
131228 styleUrls : [ "examples-list.component.css" ]
132229} )
133- export class ExamplesListDepth3Component implements OnInit , OnDestroy {
230+ export class ExamplesListDepth3Component implements OnInit , AfterViewInit , OnDestroy {
134231 private _currentExample : ExampleItem ;
135232 private _hasBack : boolean ;
136233 private _sub : any ;
234+ private _rootDrawer : RadSideDrawer ;
137235
138236 constructor ( private _router : Router , private _route : ActivatedRoute , private _exampleItemsService : ExampleItemService ) {
139237
@@ -149,6 +247,10 @@ export class ExamplesListDepth3Component implements OnInit, OnDestroy {
149247
150248 }
151249
250+ ngAfterViewInit ( ) {
251+ this . _rootDrawer = getRootView ( ) as RadSideDrawer ;
252+ }
253+
152254 ngOnDestroy ( ) {
153255 this . _sub . unsubscribe ( ) ;
154256 }
@@ -178,6 +280,46 @@ export class ExamplesListDepth3Component implements OnInit, OnDestroy {
178280 public onNavigationButtonTap ( ) {
179281 frameModule . topmost ( ) . goBack ( ) ;
180282 }
283+
284+
285+ public onChangeTransition ( transition : string ) {
286+ switch ( transition ) {
287+ case "SlideInOnTopTransition" :
288+ this . _rootDrawer . drawerTransition = new SlideInOnTopTransition ( ) ;
289+ break ;
290+ case "FadeTransition" :
291+ this . _rootDrawer . drawerTransition = new FadeTransition ( ) ;
292+ break ;
293+ case "PushTransition" :
294+ this . _rootDrawer . drawerTransition = new PushTransition ( ) ;
295+ break ;
296+ case "RevealTransition" :
297+ this . _rootDrawer . drawerTransition = new RevealTransition ( ) ;
298+ break ;
299+ case "ReverseSlideOutTransition" :
300+ this . _rootDrawer . drawerTransition = new ReverseSlideOutTransition ( ) ;
301+ break ;
302+ case "ScaleDownPusherTransition" :
303+ this . _rootDrawer . drawerTransition = new ScaleDownPusherTransition ( ) ;
304+ break ;
305+ case "ScaleUpTransition" :
306+ this . _rootDrawer . drawerTransition = new ScaleUpTransition ( ) ;
307+ break ;
308+ case "SlideAlongTransition" :
309+ this . _rootDrawer . drawerTransition = new SlideAlongTransition ( ) ;
310+ break ;
311+ default :
312+ break ;
313+ }
314+
315+ console . log ( "Changed drawer transition to" , transition ) ;
316+ }
317+
318+ public onNavBtnTap ( ) {
319+ if ( this . _rootDrawer ) {
320+ this . _rootDrawer . toggleDrawerState ( ) ;
321+ }
322+ }
181323}
182324
183325export const ExamplesListDepthComponents = [ ExamplesListDepth1Component , ExamplesListDepth2Component , ExamplesListDepth3Component ] ;
0 commit comments