mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-11-05 13:26:48 +08:00
Merge pull request #1088 from NativeScript/gestures-state
states for various gestures added
This commit is contained in:
@@ -28,21 +28,25 @@ export function createPage() {
|
||||
var swipeLabel = new labelModule.Label();
|
||||
swipeLabel.height = labelHeight;
|
||||
swipeLabel.text = "Swipe here";
|
||||
swipeLabel.textWrap = true;
|
||||
stack.addChild(swipeLabel);
|
||||
|
||||
var panLabel = new labelModule.Label();
|
||||
panLabel.height = labelHeight;
|
||||
panLabel.text = "Pan here";
|
||||
panLabel.textWrap = true;
|
||||
stack.addChild(panLabel);
|
||||
|
||||
var pinchLabel = new labelModule.Label();
|
||||
pinchLabel.height = labelHeight;
|
||||
pinchLabel.text = "Pinch here";
|
||||
pinchLabel.textWrap = true;
|
||||
stack.addChild(pinchLabel);
|
||||
|
||||
var rotaionLabel = new labelModule.Label();
|
||||
rotaionLabel.height = labelHeight;
|
||||
rotaionLabel.text = "Rotate here";
|
||||
rotaionLabel.textWrap = true;
|
||||
stack.addChild(rotaionLabel);
|
||||
|
||||
stopButton.on(button.Button.tapEvent, function () {
|
||||
@@ -81,25 +85,25 @@ export function createPage() {
|
||||
var observer3 = longpressLabel.getGestureObservers(gestures.GestureTypes.longPress)[0];
|
||||
|
||||
swipeLabel.on(gestures.GestureTypes.swipe, function (args: gestures.SwipeGestureEventData) {
|
||||
swipeLabel.text = "Swipe Direction: " + args.direction + ", " + (args.object === swipeLabel);
|
||||
swipeLabel.text = "Swipe Direction: " + args.direction + ", " + (args.object === swipeLabel) + getStateAsString(args.state);
|
||||
});
|
||||
|
||||
var observer4 = swipeLabel.getGestureObservers(gestures.GestureTypes.swipe)[0];
|
||||
|
||||
panLabel.on(gestures.GestureTypes.pan, function (args: gestures.PanGestureEventData) {
|
||||
panLabel.text = "Pan deltaX:" + args.deltaX + "; deltaY:" + args.deltaY + ";" + ", " + (args.object === panLabel);
|
||||
panLabel.text = "Pan deltaX:" + Math.round(args.deltaX) + "; deltaY:" + Math.round(args.deltaX) + ";" + ", " + (args.object === panLabel) + getStateAsString(args.state);
|
||||
});
|
||||
|
||||
var observer5 = panLabel.getGestureObservers(gestures.GestureTypes.pan)[0];
|
||||
|
||||
pinchLabel.on(gestures.GestureTypes.pinch, function (args: gestures.PinchGestureEventData) {
|
||||
pinchLabel.text = "Pinch Scale: " + args.scale + ", " + (args.object === pinchLabel);
|
||||
pinchLabel.text = "Pinch Scale: " + Math.round(args.scale) + ", " + (args.object === pinchLabel) + getStateAsString(args.state);
|
||||
});
|
||||
|
||||
var observer6 = pinchLabel.getGestureObservers(gestures.GestureTypes.pinch)[0];
|
||||
|
||||
rotaionLabel.on(gestures.GestureTypes.rotation, function (args: gestures.RotationGestureEventData) {
|
||||
rotaionLabel.text = "Rotation: " + args.rotation + ", " + (args.object === rotaionLabel);
|
||||
rotaionLabel.text = "Rotation: " + Math.round(args.rotation) + ", " + (args.object === rotaionLabel) + getStateAsString(args.state);
|
||||
});
|
||||
|
||||
var observer7 = rotaionLabel.getGestureObservers(gestures.GestureTypes.rotation)[0];
|
||||
@@ -107,4 +111,22 @@ export function createPage() {
|
||||
var page = new pages.Page();
|
||||
page.content = stack;
|
||||
return page;
|
||||
}
|
||||
|
||||
var states = new Array<string>();
|
||||
function getStateAsString(state: gestures.GestureStateTypes): string {
|
||||
if (state === gestures.GestureStateTypes.began) {
|
||||
states.length = 0;
|
||||
states.push("began");
|
||||
} else if (state === gestures.GestureStateTypes.cancelled) {
|
||||
states.push("cancelled");
|
||||
} else if (state === gestures.GestureStateTypes.changed) {
|
||||
if (states.indexOf("changed") === -1) {
|
||||
states.push("changed");
|
||||
}
|
||||
} else if (state === gestures.GestureStateTypes.ended) {
|
||||
states.push("ended");
|
||||
}
|
||||
|
||||
return ", states: " + states.join(",");
|
||||
}
|
||||
Reference in New Issue
Block a user