1- import * as labelModule from "tns-core-modules/ui/label" ;
2- import * as gestures from "tns-core-modules/ui/gestures" ;
3- import * as button from "tns-core-modules/ui/button" ;
4- import * as pages from "tns-core-modules/ui/page" ;
5- import * as deviceProperties from "tns-core-modules/platform" ;
6- import * as stackLayoutModule from "tns-core-modules/ui/layouts/stack-layout" ;
1+ import {
2+ GestureEventData ,
3+ RotationGestureEventData ,
4+ GestureTypes ,
5+ SwipeGestureEventData ,
6+ PanGestureEventData ,
7+ PinchGestureEventData ,
8+ GestureStateTypes
9+ } from "tns-core-modules/ui/gestures" ;
10+ import { Button } from "tns-core-modules/ui/button" ;
11+ import { Label } from "tns-core-modules/ui/label" ;
12+ import { Page } from "tns-core-modules/ui/page" ;
13+ import { StackLayout } from "tns-core-modules/ui/layouts/stack-layout" ;
14+ import { screen , isAndroid } from "tns-core-modules/platform" ;
715
816export function createPage ( ) {
9-
10- var stack = new stackLayoutModule . StackLayout ( ) ;
11- var labelHeight = Math . round ( deviceProperties . screen . mainScreen . heightPixels / ( 7 * deviceProperties . screen . mainScreen . scale ) ) ;
12- var stopButton = new button . Button ( ) ;
17+ const stack = new StackLayout ( ) ;
18+ var stopButton = new Button ( ) ;
19+ if ( isAndroid ) {
20+ stopButton . height = 30 ;
21+ stopButton . fontSize = 8 ;
22+ }
1323 stopButton . text = "Stop Detecting Gestures" ;
24+ stopButton . automationText = "stopGesturesDetecting" ;
1425 stack . addChild ( stopButton ) ;
1526
16- var tapLabel = new labelModule . Label ( ) ;
17- tapLabel . text = "Tap here" ;
27+ const labelHeight = Math . round ( screen . mainScreen . heightPixels / ( 10 * screen . mainScreen . scale ) ) ;
28+
29+ const tapLabel = createLabel ( "Tap here" , labelHeight ) ;
1830 stack . addChild ( tapLabel ) ;
1931
20- var doubletapLabel = new labelModule . Label ( ) ;
21- doubletapLabel . text = "Double Tap here" ;
22- stack . addChild ( doubletapLabel ) ;
32+ const doubleTapLabel = createLabel ( "Double Tap here" , labelHeight ) ;
33+ stack . addChild ( doubleTapLabel ) ;
34+
35+ const longPressLabel = createLabel ( "Long Press here" , labelHeight ) ;
36+ stack . addChild ( longPressLabel ) ;
2337
24- var longpressLabel = new labelModule . Label ( ) ;
25- longpressLabel . text = "Long Press here" ;
26- stack . addChild ( longpressLabel ) ;
38+ const tapAndDoubleTapLabel = createLabel ( "Tap or Double Tap" , labelHeight , true ) ;
39+ stack . addChild ( tapAndDoubleTapLabel ) ;
2740
28- var swipeLabel = new labelModule . Label ( ) ;
29- swipeLabel . height = labelHeight ;
30- swipeLabel . text = "Swipe here" ;
31- swipeLabel . textWrap = true ;
41+ const swipeLabel = createLabel ( "Swipe here" , labelHeight , true ) ;
3242 stack . addChild ( swipeLabel ) ;
3343
34- var panLabel = new labelModule . Label ( ) ;
35- panLabel . height = labelHeight ;
36- panLabel . text = "Pan here" ;
37- panLabel . textWrap = true ;
44+ const panLabel = createLabel ( "Pan here" , labelHeight , true ) ;
3845 stack . addChild ( panLabel ) ;
3946
40- var pinchLabel = new labelModule . Label ( ) ;
41- pinchLabel . height = labelHeight ;
42- pinchLabel . text = "Pinch here" ;
43- pinchLabel . textWrap = true ;
47+ const pinchLabel = createLabel ( "Pinch here" , labelHeight , true ) ;
4448 stack . addChild ( pinchLabel ) ;
4549
46- var rotaionLabel = new labelModule . Label ( ) ;
47- rotaionLabel . height = labelHeight ;
48- rotaionLabel . text = "Rotate here" ;
49- rotaionLabel . textWrap = true ;
50- stack . addChild ( rotaionLabel ) ;
50+ const rotationLabel = createLabel ( "Rotate here" , labelHeight , true ) ;
51+ stack . addChild ( rotationLabel ) ;
5152
52- stopButton . on ( button . Button . tapEvent , function ( ) {
53+ stopButton . on ( "tap" , function ( ) {
5354 observer1 . disconnect ( ) ;
5455 observer2 . disconnect ( ) ;
5556 observer3 . disconnect ( ) ;
5657 observer4 . disconnect ( ) ;
5758 observer5 . disconnect ( ) ;
5859 observer6 . disconnect ( ) ;
5960 observer7 . disconnect ( ) ;
61+ observer8 . disconnect ( ) ;
62+ observer9 . disconnect ( ) ;
6063 tapLabel . text = "Gestures detection disabled" ;
61- doubletapLabel . text = "Gestures detection disabled" ;
62- longpressLabel . text = "Gestures detection disabled" ;
63- swipeLabel . text = "Gesturesd detection disabled" ;
64+ tapLabel . automationText = "Gestures detection disabled" ;
65+ doubleTapLabel . text = "Gestures detection disabled" ;
66+ doubleTapLabel . automationText = "Gestures detection disabled" ;
67+ longPressLabel . text = "Gestures detection disabled" ;
68+ longPressLabel . automationText = "Gestures detection disabled" ;
69+ swipeLabel . text = "Gestures detection disabled" ;
70+ swipeLabel . automationText = "Gestures detection disabled" ;
6471 panLabel . text = "Gestures detection disabled" ;
72+ panLabel . automationText = "Gestures detection disabled" ;
6573 pinchLabel . text = "Gestures detection disabled" ;
66- rotaionLabel . text = "Gestures detection disabled" ;
74+ pinchLabel . automationText = "Gestures detection disabled" ;
75+ rotationLabel . text = "Gestures detection disabled" ;
76+ rotationLabel . automationText = "Gestures detection disabled" ;
77+ tapAndDoubleTapLabel . text = "Gestures detection disabled" ;
78+ tapAndDoubleTapLabel . automationText = "Gestures detection disabled" ;
6779 } ) ;
6880
69- tapLabel . on ( gestures . GestureTypes . tap , function ( args : gestures . GestureEventData ) {
81+ tapLabel . on ( GestureTypes [ GestureTypes . tap ] , function ( args : GestureEventData ) {
7082 tapLabel . text = "Tap gesture detected, " + ( args . object === tapLabel ) ;
7183 } ) ;
7284
73- var observer1 = tapLabel . getGestureObservers ( gestures . GestureTypes . tap ) [ 0 ] ;
85+ const observer1 = tapLabel . getGestureObservers ( GestureTypes . tap ) [ 0 ] ;
7486
75- doubletapLabel . on ( gestures . GestureTypes . doubleTap , function ( args : gestures . GestureEventData ) {
76- doubletapLabel . text = "Double Tap gesture detected, " + ( args . object === doubletapLabel ) ;
87+ doubleTapLabel . on ( GestureTypes [ GestureTypes . doubleTap ] , function ( args : GestureEventData ) {
88+ doubleTapLabel . text = "Double Tap gesture detected, " + ( args . object === doubleTapLabel ) ;
7789 } ) ;
7890
79- var observer2 = doubletapLabel . getGestureObservers ( gestures . GestureTypes . doubleTap ) [ 0 ] ;
91+ const observer2 = doubleTapLabel . getGestureObservers ( GestureTypes . doubleTap ) [ 0 ] ;
8092
81- longpressLabel . on ( gestures . GestureTypes . longPress , function ( args : gestures . GestureEventData ) {
82- longpressLabel . text = "Long Press gesture detected, " + ( args . object === longpressLabel ) ;
93+ longPressLabel . on ( GestureTypes [ GestureTypes . longPress ] , function ( args : GestureEventData ) {
94+ longPressLabel . text = "Long Press gesture detected, " + ( args . object === longPressLabel ) ;
8395 } ) ;
8496
85- var observer3 = longpressLabel . getGestureObservers ( gestures . GestureTypes . longPress ) [ 0 ] ;
97+ const observer3 = longPressLabel . getGestureObservers ( GestureTypes . longPress ) [ 0 ] ;
8698
87- swipeLabel . on ( gestures . GestureTypes . swipe , function ( args : gestures . SwipeGestureEventData ) {
99+ swipeLabel . on ( GestureTypes [ GestureTypes . swipe ] , function ( args : SwipeGestureEventData ) {
88100 swipeLabel . text = "Swipe Direction: " + args . direction + ", " + ( args . object === swipeLabel ) ; // + getStateAsString(args.state);
89101 } ) ;
90102
91- var observer4 = swipeLabel . getGestureObservers ( gestures . GestureTypes . swipe ) [ 0 ] ;
103+ const observer4 = swipeLabel . getGestureObservers ( GestureTypes . swipe ) [ 0 ] ;
92104
93- panLabel . on ( gestures . GestureTypes . pan , function ( args : gestures . PanGestureEventData ) {
105+ panLabel . on ( GestureTypes [ GestureTypes . pan ] , function ( args : PanGestureEventData ) {
94106 panLabel . text = "Pan deltaX:" + Math . round ( args . deltaX ) + "; deltaY:" + Math . round ( args . deltaY ) + ";" + ", " + ( args . object === panLabel ) + getStateAsString ( args . state ) ;
95107 } ) ;
96108
97- var observer5 = panLabel . getGestureObservers ( gestures . GestureTypes . pan ) [ 0 ] ;
109+ const observer5 = panLabel . getGestureObservers ( GestureTypes . pan ) [ 0 ] ;
98110
99- pinchLabel . on ( gestures . GestureTypes . pinch , function ( args : gestures . PinchGestureEventData ) {
111+ pinchLabel . on ( GestureTypes [ GestureTypes . pinch ] , function ( args : PinchGestureEventData ) {
100112 pinchLabel . text = "Pinch Scale: " + Math . round ( args . scale ) + ", " + ( args . object === pinchLabel ) + getStateAsString ( args . state ) ;
101113 } ) ;
102114
103- var observer6 = pinchLabel . getGestureObservers ( gestures . GestureTypes . pinch ) [ 0 ] ;
115+ const observer6 = pinchLabel . getGestureObservers ( GestureTypes . pinch ) [ 0 ] ;
104116
105- rotaionLabel . on ( gestures . GestureTypes . rotation , function ( args : gestures . RotationGestureEventData ) {
106- rotaionLabel . text = "Rotation: " + Math . round ( args . rotation ) + ", " + ( args . object === rotaionLabel ) + getStateAsString ( args . state ) ;
117+ rotationLabel . on ( GestureTypes [ GestureTypes . rotation ] , function ( args : RotationGestureEventData ) {
118+ rotationLabel . text = "Rotation: " + Math . round ( args . rotation ) + ", " + ( args . object === rotationLabel ) + getStateAsString ( args . state ) ;
107119 } ) ;
108120
109- var observer7 = rotaionLabel . getGestureObservers ( gestures . GestureTypes . rotation ) [ 0 ] ;
121+ const observer7 = rotationLabel . getGestureObservers ( GestureTypes . rotation ) [ 0 ] ;
110122
111- var page = new pages . Page ( ) ;
112- page . content = stack ;
123+ tapAndDoubleTapLabel . on ( GestureTypes [ GestureTypes . doubleTap ] , function ( args : GestureEventData ) {
124+ tapAndDoubleTapLabel . text = "Last action: Double tap gesture, " + ( args . object === tapAndDoubleTapLabel ) ;
125+ } ) ;
126+
127+ const observer8 = tapAndDoubleTapLabel . getGestureObservers ( GestureTypes . doubleTap ) [ 0 ] ;
113128
129+ tapAndDoubleTapLabel . on ( GestureTypes [ GestureTypes . tap ] , function ( args : GestureEventData ) {
130+ tapAndDoubleTapLabel . text = "Last action: Tap gesture, " + ( args . object === tapAndDoubleTapLabel ) ;
131+ } ) ;
132+
133+ const observer9 = tapAndDoubleTapLabel . getGestureObservers ( GestureTypes . tap ) [ 0 ] ;
134+
135+ const page = new Page ( ) ;
136+ page . content = stack ;
137+
114138 return page ;
115139}
116140
117- var states = new Array < string > ( ) ;
118- function getStateAsString ( state : gestures . GestureStateTypes ) : string {
119- if ( state === gestures . GestureStateTypes . began ) {
141+ function getStateAsString ( state : GestureStateTypes ) : string {
142+ const states = new Array < string > ( ) ;
143+ if ( state === GestureStateTypes . began ) {
120144 states . length = 0 ;
121145 states . push ( "began" ) ;
122- } else if ( state === gestures . GestureStateTypes . cancelled ) {
146+ } else if ( state === GestureStateTypes . cancelled ) {
123147 states . push ( "cancelled" ) ;
124- } else if ( state === gestures . GestureStateTypes . changed ) {
148+ } else if ( state === GestureStateTypes . changed ) {
125149 if ( states . indexOf ( "changed" ) === - 1 ) {
126150 states . push ( "changed" ) ;
127151 }
128- } else if ( state === gestures . GestureStateTypes . ended ) {
152+ } else if ( state === GestureStateTypes . ended ) {
129153 states . push ( "ended" ) ;
130154 }
131155
132156 return ", states: " + states . join ( "," ) ;
133157}
158+
159+ function createLabel ( text : string , labelHeight : number , shouldWrap = false ) {
160+ const label = new Label ( ) ;
161+ label . height = labelHeight ;
162+ label . text = text ;
163+ label . textWrap = shouldWrap ;
164+ label . borderColor = "green" ;
165+ label . borderWidth = 1 ;
166+
167+ return label ;
168+ }
0 commit comments