mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-11-05 13:26:48 +08:00
Merge pull request #299 from NativeScript/nnikolov/CodeSnippetsChanges
Changed gestures enums like other enums.
This commit is contained in:
@@ -2,30 +2,30 @@
|
||||
import view = require("ui/core/view");
|
||||
|
||||
export enum GestureTypes {
|
||||
Tap = 1 << 0,
|
||||
DoubleTap = 1 << 1,
|
||||
Pinch = 1 << 2,
|
||||
Pan = 1 << 3,
|
||||
Swipe = 1 << 4,
|
||||
Rotation = 1 << 5,
|
||||
LongPress = 1 << 6
|
||||
tap = 1 << 0,
|
||||
doubleTap = 1 << 1,
|
||||
pinch = 1 << 2,
|
||||
pan = 1 << 3,
|
||||
swipe = 1 << 4,
|
||||
rotation = 1 << 5,
|
||||
longPress = 1 << 6
|
||||
}
|
||||
|
||||
export enum GestureStateTypes {
|
||||
Possible = 1 << 0,
|
||||
Recognized = 1 << 1,
|
||||
Failed = 1 << 2,
|
||||
Cancelled = 1 << 3,
|
||||
Began = 1 << 4,
|
||||
Changed = 1 << 5,
|
||||
Ended = 1 << 6
|
||||
possible = 1 << 0,
|
||||
recognized = 1 << 1,
|
||||
failed = 1 << 2,
|
||||
cancelled = 1 << 3,
|
||||
began = 1 << 4,
|
||||
changed = 1 << 5,
|
||||
ended = 1 << 6
|
||||
}
|
||||
|
||||
export enum SwipeDirection {
|
||||
Right = 1 << 0,
|
||||
Left = 1 << 1,
|
||||
Up = 1 << 2,
|
||||
Down = 1 << 3
|
||||
right = 1 << 0,
|
||||
left = 1 << 1,
|
||||
up = 1 << 2,
|
||||
down = 1 << 3
|
||||
}
|
||||
|
||||
export function observe(target: view.View, type: number, callback: (args: definition.GestureEventData) => void): definition.GesturesObserver {
|
||||
@@ -37,32 +37,32 @@ export function observe(target: view.View, type: number, callback: (args: defini
|
||||
export function toString(type: GestureTypes, separator?: string): string {
|
||||
var types = new Array<string>();
|
||||
|
||||
if (type & definition.GestureTypes.Tap) {
|
||||
types.push("Tap");
|
||||
if (type & definition.GestureTypes.tap) {
|
||||
types.push("tap");
|
||||
}
|
||||
|
||||
if (type & definition.GestureTypes.DoubleTap) {
|
||||
types.push("DoubleTap");
|
||||
if (type & definition.GestureTypes.doubleTap) {
|
||||
types.push("doubleTap");
|
||||
}
|
||||
|
||||
if (type & definition.GestureTypes.Pinch) {
|
||||
types.push("Pinch");
|
||||
if (type & definition.GestureTypes.pinch) {
|
||||
types.push("pinch");
|
||||
}
|
||||
|
||||
if (type & definition.GestureTypes.Pan) {
|
||||
types.push("Pan");
|
||||
if (type & definition.GestureTypes.pan) {
|
||||
types.push("pan");
|
||||
}
|
||||
|
||||
if (type & definition.GestureTypes.Swipe) {
|
||||
types.push("Swipe");
|
||||
if (type & definition.GestureTypes.swipe) {
|
||||
types.push("swipe");
|
||||
}
|
||||
|
||||
if (type & definition.GestureTypes.Rotation) {
|
||||
types.push("Rotation");
|
||||
if (type & definition.GestureTypes.rotation) {
|
||||
types.push("rotation");
|
||||
}
|
||||
|
||||
if (type & definition.GestureTypes.LongPress) {
|
||||
types.push("LongPress");
|
||||
if (type & definition.GestureTypes.longPress) {
|
||||
types.push("longPress");
|
||||
}
|
||||
|
||||
return types.join(separator);
|
||||
@@ -72,19 +72,19 @@ export function fromString(type: string): definition.GestureTypes {
|
||||
var t = type.trim().toLowerCase();
|
||||
|
||||
if (t === "tap") {
|
||||
return definition.GestureTypes.Tap;
|
||||
return definition.GestureTypes.tap;
|
||||
} else if (t === "doubletap") {
|
||||
return definition.GestureTypes.DoubleTap;
|
||||
return definition.GestureTypes.doubleTap;
|
||||
} else if (t === "pinch") {
|
||||
return definition.GestureTypes.Pinch;
|
||||
return definition.GestureTypes.pinch;
|
||||
} else if (t === "pan") {
|
||||
return definition.GestureTypes.Pan;
|
||||
return definition.GestureTypes.pan;
|
||||
} else if (t === "swipe") {
|
||||
return definition.GestureTypes.Swipe;
|
||||
return definition.GestureTypes.swipe;
|
||||
} else if (t === "rotation") {
|
||||
return definition.GestureTypes.Rotation;
|
||||
return definition.GestureTypes.rotation;
|
||||
} else if (t === "longpress") {
|
||||
return definition.GestureTypes.LongPress;
|
||||
return definition.GestureTypes.longPress;
|
||||
}
|
||||
|
||||
return undefined;
|
||||
|
||||
@@ -83,19 +83,19 @@ export class GesturesObserver implements definition.GesturesObserver {
|
||||
trace.write(this._target + "._attach() android:" + this._target.android, "gestures");
|
||||
this._dettach();
|
||||
|
||||
if (type & definition.GestureTypes.Tap || type & definition.GestureTypes.DoubleTap || type & definition.GestureTypes.LongPress) {
|
||||
if (type & definition.GestureTypes.tap || type & definition.GestureTypes.doubleTap || type & definition.GestureTypes.longPress) {
|
||||
this._simpleGestureDetector = new android.support.v4.view.GestureDetectorCompat(target._context, new TapAndDoubleTapGestureListener(this, this._target));
|
||||
}
|
||||
|
||||
if (type & definition.GestureTypes.Pinch) {
|
||||
if (type & definition.GestureTypes.pinch) {
|
||||
this._scaleGestureDetector = new android.view.ScaleGestureDetector(target._context, new PinchGestureListener(this, this._target));
|
||||
}
|
||||
|
||||
if (type & definition.GestureTypes.Swipe) {
|
||||
if (type & definition.GestureTypes.swipe) {
|
||||
this._swipeGestureDetector = new android.support.v4.view.GestureDetectorCompat(target._context, new SwipeGestureListener(this, this._target));
|
||||
}
|
||||
|
||||
if (type & definition.GestureTypes.Pan) {
|
||||
if (type & definition.GestureTypes.pan) {
|
||||
this._panGestureDetector = new android.support.v4.view.GestureDetectorCompat(target._context, new PanGestureListener(this, this._target));
|
||||
}
|
||||
|
||||
@@ -124,7 +124,7 @@ export class GesturesObserver implements definition.GesturesObserver {
|
||||
owner._panGestureDetector.onTouchEvent(motionEvent);
|
||||
}
|
||||
|
||||
if (type & definition.GestureTypes.Rotation && motionEvent.getPointerCount() === 2) {
|
||||
if (type & definition.GestureTypes.rotation && motionEvent.getPointerCount() === 2) {
|
||||
|
||||
var deltaX = motionEvent.getX(0) - motionEvent.getX(1);
|
||||
var deltaY = motionEvent.getY(0) - motionEvent.getY(1);
|
||||
@@ -132,7 +132,7 @@ export class GesturesObserver implements definition.GesturesObserver {
|
||||
var degrees = radians * (180 / Math.PI);
|
||||
|
||||
var args = <definition.RotationGestureEventData>{
|
||||
type: definition.GestureTypes.Rotation,
|
||||
type: definition.GestureTypes.rotation,
|
||||
view: owner._target,
|
||||
android: motionEvent,
|
||||
rotation: degrees,
|
||||
@@ -164,7 +164,7 @@ function _getArgs(type: definition.GestureTypes, view: view.View, e: android.vie
|
||||
function _getSwipeArgs(direction: definition.SwipeDirection, view: view.View,
|
||||
initialEvent: android.view.MotionEvent, currentEvent: android.view.MotionEvent): definition.SwipeGestureEventData {
|
||||
return <definition.SwipeGestureEventData>{
|
||||
type: definition.GestureTypes.Swipe,
|
||||
type: definition.GestureTypes.swipe,
|
||||
view: view,
|
||||
android: { initial: initialEvent, current: currentEvent },
|
||||
direction: direction
|
||||
@@ -174,7 +174,7 @@ function _getSwipeArgs(direction: definition.SwipeDirection, view: view.View,
|
||||
function _getPanArgs(deltaX: number, deltaY: number, view: view.View,
|
||||
initialEvent: android.view.MotionEvent, currentEvent: android.view.MotionEvent): definition.PanGestureEventData {
|
||||
return <definition.PanGestureEventData>{
|
||||
type: definition.GestureTypes.Pan,
|
||||
type: definition.GestureTypes.pan,
|
||||
view: view,
|
||||
android: { initial: initialEvent, current: currentEvent },
|
||||
deltaX: deltaX,
|
||||
@@ -201,13 +201,13 @@ class TapAndDoubleTapGestureListener extends android.view.GestureDetector.Simple
|
||||
}
|
||||
|
||||
public onSingleTapConfirmed(motionEvent: android.view.MotionEvent): boolean {
|
||||
var args = _getArgs(definition.GestureTypes.Tap, this._target, motionEvent);
|
||||
var args = _getArgs(definition.GestureTypes.tap, this._target, motionEvent);
|
||||
_executeCallback(this._observer, args);
|
||||
return true;
|
||||
}
|
||||
|
||||
public onDoubleTap(motionEvent: android.view.MotionEvent): boolean {
|
||||
var args = _getArgs(definition.GestureTypes.DoubleTap, this._target, motionEvent);
|
||||
var args = _getArgs(definition.GestureTypes.doubleTap, this._target, motionEvent);
|
||||
_executeCallback(this._observer, args);
|
||||
return true;
|
||||
}
|
||||
@@ -217,7 +217,7 @@ class TapAndDoubleTapGestureListener extends android.view.GestureDetector.Simple
|
||||
}
|
||||
|
||||
public onLongPress(motionEvent: android.view.MotionEvent): boolean {
|
||||
var args = _getArgs(definition.GestureTypes.LongPress, this._target, motionEvent);
|
||||
var args = _getArgs(definition.GestureTypes.longPress, this._target, motionEvent);
|
||||
_executeCallback(this._observer, args);
|
||||
return true;
|
||||
}
|
||||
@@ -238,7 +238,7 @@ class PinchGestureListener extends android.view.ScaleGestureDetector.SimpleOnSca
|
||||
|
||||
public onScale(detector: android.view.ScaleGestureDetector): boolean {
|
||||
var args = <definition.PinchGestureEventData>{
|
||||
type: definition.GestureTypes.Pinch,
|
||||
type: definition.GestureTypes.pinch,
|
||||
view: this._target,
|
||||
android: detector,
|
||||
scale: detector.getScaleFactor()
|
||||
@@ -280,13 +280,13 @@ class SwipeGestureListener extends android.view.GestureDetector.SimpleOnGestureL
|
||||
|
||||
if (deltaX > 0) {
|
||||
|
||||
args = _getSwipeArgs(definition.SwipeDirection.Right, this._target, initialEvent, currentEvent);
|
||||
args = _getSwipeArgs(definition.SwipeDirection.right, this._target, initialEvent, currentEvent);
|
||||
_executeCallback(this._observer, args);
|
||||
|
||||
result = true;
|
||||
} else {
|
||||
|
||||
args = _getSwipeArgs(definition.SwipeDirection.Left, this._target, initialEvent, currentEvent);
|
||||
args = _getSwipeArgs(definition.SwipeDirection.left, this._target, initialEvent, currentEvent);
|
||||
_executeCallback(this._observer, args);
|
||||
|
||||
result = true;
|
||||
@@ -300,13 +300,13 @@ class SwipeGestureListener extends android.view.GestureDetector.SimpleOnGestureL
|
||||
|
||||
if (deltaY > 0) {
|
||||
|
||||
args = _getSwipeArgs(definition.SwipeDirection.Down, this._target, initialEvent, currentEvent);
|
||||
args = _getSwipeArgs(definition.SwipeDirection.down, this._target, initialEvent, currentEvent);
|
||||
_executeCallback(this._observer, args);
|
||||
|
||||
result = true;
|
||||
} else {
|
||||
|
||||
args = _getSwipeArgs(definition.SwipeDirection.Up, this._target, initialEvent, currentEvent);
|
||||
args = _getSwipeArgs(definition.SwipeDirection.up, this._target, initialEvent, currentEvent);
|
||||
_executeCallback(this._observer, args);
|
||||
|
||||
result = true;
|
||||
|
||||
22
ui/gestures/gestures.d.ts
vendored
22
ui/gestures/gestures.d.ts
vendored
@@ -11,31 +11,31 @@ declare module "ui/gestures" {
|
||||
/**
|
||||
* Denotes tap (click) gesture.
|
||||
*/
|
||||
Tap,
|
||||
tap,
|
||||
/**
|
||||
* Denotes double tap gesture.
|
||||
*/
|
||||
DoubleTap,
|
||||
doubleTap,
|
||||
/**
|
||||
* Denotes pinch gesture.
|
||||
*/
|
||||
Pinch,
|
||||
pinch,
|
||||
/**
|
||||
* Denotes pan gesture.
|
||||
*/
|
||||
Pan,
|
||||
pan,
|
||||
/**
|
||||
* Denotes swipe gesture.
|
||||
*/
|
||||
Swipe,
|
||||
swipe,
|
||||
/**
|
||||
* Denotes rotation gesture.
|
||||
*/
|
||||
Rotation,
|
||||
rotation,
|
||||
/**
|
||||
* Denotes long press gesture.
|
||||
*/
|
||||
LongPress
|
||||
longPress
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -45,19 +45,19 @@ declare module "ui/gestures" {
|
||||
/**
|
||||
* Denotes right direction for swipe gesture.
|
||||
*/
|
||||
Right,
|
||||
right,
|
||||
/**
|
||||
* Denotes left direction for swipe gesture.
|
||||
*/
|
||||
Left,
|
||||
left,
|
||||
/**
|
||||
* Denotes up direction for swipe gesture.
|
||||
*/
|
||||
Up,
|
||||
up,
|
||||
/**
|
||||
* Denotes down direction for swipe gesture.
|
||||
*/
|
||||
Down
|
||||
down
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -70,43 +70,43 @@ export class GesturesObserver implements definition.GesturesObserver {
|
||||
if (this._target && this._target.ios && this._target.ios.addGestureRecognizer) {
|
||||
var nativeView = <UIView>this._target.ios;
|
||||
|
||||
if (type & definition.GestureTypes.Tap) {
|
||||
nativeView.addGestureRecognizer(this._createRecognizer(definition.GestureTypes.Tap));
|
||||
if (type & definition.GestureTypes.tap) {
|
||||
nativeView.addGestureRecognizer(this._createRecognizer(definition.GestureTypes.tap));
|
||||
}
|
||||
|
||||
if (type & definition.GestureTypes.DoubleTap) {
|
||||
var r = <UITapGestureRecognizer>this._createRecognizer(definition.GestureTypes.DoubleTap);
|
||||
if (type & definition.GestureTypes.doubleTap) {
|
||||
var r = <UITapGestureRecognizer>this._createRecognizer(definition.GestureTypes.doubleTap);
|
||||
r.numberOfTapsRequired = 2;
|
||||
|
||||
nativeView.addGestureRecognizer(r);
|
||||
}
|
||||
|
||||
if (type & definition.GestureTypes.Pinch) {
|
||||
nativeView.addGestureRecognizer(this._createRecognizer(definition.GestureTypes.Pinch, args => {
|
||||
if (type & definition.GestureTypes.pinch) {
|
||||
nativeView.addGestureRecognizer(this._createRecognizer(definition.GestureTypes.pinch, args => {
|
||||
this._executeCallback(_getPinchData(args));
|
||||
}));
|
||||
}
|
||||
|
||||
if (type & definition.GestureTypes.Pan) {
|
||||
nativeView.addGestureRecognizer(this._createRecognizer(definition.GestureTypes.Pan, args => {
|
||||
if (type & definition.GestureTypes.pan) {
|
||||
nativeView.addGestureRecognizer(this._createRecognizer(definition.GestureTypes.pan, args => {
|
||||
this._executeCallback(_getPanData(args, this._target.ios));
|
||||
}));
|
||||
}
|
||||
|
||||
if (type & definition.GestureTypes.Swipe) {
|
||||
nativeView.addGestureRecognizer(this._createRecognizer(definition.GestureTypes.Swipe, args => {
|
||||
if (type & definition.GestureTypes.swipe) {
|
||||
nativeView.addGestureRecognizer(this._createRecognizer(definition.GestureTypes.swipe, args => {
|
||||
this._executeCallback(_getSwipeData(args));
|
||||
}));
|
||||
}
|
||||
|
||||
if (type & definition.GestureTypes.Rotation) {
|
||||
nativeView.addGestureRecognizer(this._createRecognizer(definition.GestureTypes.Rotation, args => {
|
||||
if (type & definition.GestureTypes.rotation) {
|
||||
nativeView.addGestureRecognizer(this._createRecognizer(definition.GestureTypes.rotation, args => {
|
||||
this._executeCallback(_getRotationData(args));
|
||||
}));
|
||||
}
|
||||
|
||||
if (type & definition.GestureTypes.LongPress) {
|
||||
nativeView.addGestureRecognizer(this._createRecognizer(definition.GestureTypes.LongPress));
|
||||
if (type & definition.GestureTypes.longPress) {
|
||||
nativeView.addGestureRecognizer(this._createRecognizer(definition.GestureTypes.longPress));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -165,19 +165,19 @@ interface RecognizerCache {
|
||||
function _getUIGestureRecognizerType(type: definition.GestureTypes): any {
|
||||
var nativeType = null;
|
||||
|
||||
if (type === definition.GestureTypes.Tap) {
|
||||
if (type === definition.GestureTypes.tap) {
|
||||
nativeType = UITapGestureRecognizer;
|
||||
} else if (type === definition.GestureTypes.DoubleTap) {
|
||||
} else if (type === definition.GestureTypes.doubleTap) {
|
||||
nativeType = UITapGestureRecognizer;
|
||||
} else if (type === definition.GestureTypes.Pinch) {
|
||||
} else if (type === definition.GestureTypes.pinch) {
|
||||
nativeType = UIPinchGestureRecognizer;
|
||||
} else if (type === definition.GestureTypes.Pan) {
|
||||
} else if (type === definition.GestureTypes.pan) {
|
||||
nativeType = UIPanGestureRecognizer;
|
||||
} else if (type === definition.GestureTypes.Swipe) {
|
||||
} else if (type === definition.GestureTypes.swipe) {
|
||||
nativeType = UISwipeGestureRecognizer;
|
||||
} else if (type === definition.GestureTypes.Rotation) {
|
||||
} else if (type === definition.GestureTypes.rotation) {
|
||||
nativeType = UIRotationGestureRecognizer;
|
||||
} else if (type === definition.GestureTypes.LongPress) {
|
||||
} else if (type === definition.GestureTypes.longPress) {
|
||||
nativeType = UILongPressGestureRecognizer;
|
||||
}
|
||||
|
||||
@@ -186,13 +186,13 @@ function _getUIGestureRecognizerType(type: definition.GestureTypes): any {
|
||||
|
||||
function _getSwipeDirection(direction: UISwipeGestureRecognizerDirection): definition.SwipeDirection {
|
||||
if (direction === UISwipeGestureRecognizerDirection.UISwipeGestureRecognizerDirectionDown) {
|
||||
return definition.SwipeDirection.Down;
|
||||
return definition.SwipeDirection.down;
|
||||
} else if (direction === UISwipeGestureRecognizerDirection.UISwipeGestureRecognizerDirectionLeft) {
|
||||
return definition.SwipeDirection.Left;
|
||||
return definition.SwipeDirection.left;
|
||||
} else if (direction === UISwipeGestureRecognizerDirection.UISwipeGestureRecognizerDirectionRight) {
|
||||
return definition.SwipeDirection.Right;
|
||||
return definition.SwipeDirection.right;
|
||||
} else if (direction === UISwipeGestureRecognizerDirection.UISwipeGestureRecognizerDirectionUp) {
|
||||
return definition.SwipeDirection.Up;
|
||||
return definition.SwipeDirection.up;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
|
||||
var lv = new lvm.ListView();
|
||||
lv.items = data;
|
||||
lv.on("itemLoading", function(args){
|
||||
lv.on(lvm.knownEvents.itemLoading, function(args){
|
||||
var label = args.view;
|
||||
if(!label) {
|
||||
label = new lm.Label();
|
||||
|
||||
@@ -9,11 +9,11 @@ export class SlideOutControl extends common.SlideOutControl {
|
||||
|
||||
this._ios = new UIView();
|
||||
|
||||
this.observe(gestures.GestureTypes.Swipe, (args) => {
|
||||
this.observe(gestures.GestureTypes.swipe, (args) => {
|
||||
var swipeArgs = <gestures.SwipeGestureEventData>args;
|
||||
if (swipeArgs.direction === gestures.SwipeDirection.Left) {
|
||||
if (swipeArgs.direction === gestures.SwipeDirection.left) {
|
||||
this._toggleSlideContentVisibility(false);
|
||||
} else if (swipeArgs.direction === gestures.SwipeDirection.Right) {
|
||||
} else if (swipeArgs.direction === gestures.SwipeDirection.right) {
|
||||
this._toggleSlideContentVisibility(true);
|
||||
}
|
||||
});
|
||||
@@ -59,14 +59,14 @@ export class SlideOutControl extends common.SlideOutControl {
|
||||
if (view === this.slideContent) {
|
||||
view.ios.hidden = true;
|
||||
|
||||
view.observe(gestures.GestureTypes.Tap | gestures.GestureTypes.Swipe, (args) => {
|
||||
if (args.type & gestures.GestureTypes.Tap) {
|
||||
view.observe(gestures.GestureTypes.tap | gestures.GestureTypes.swipe, (args) => {
|
||||
if (args.type & gestures.GestureTypes.tap) {
|
||||
this._toggleSlideContentVisibility(false);
|
||||
}
|
||||
|
||||
if (args.type & gestures.GestureTypes.Swipe) {
|
||||
if (args.type & gestures.GestureTypes.swipe) {
|
||||
var swipeArgs = <gestures.SwipeGestureEventData>args;
|
||||
if (swipeArgs.direction === gestures.SwipeDirection.Left) {
|
||||
if (swipeArgs.direction === gestures.SwipeDirection.left) {
|
||||
this._toggleSlideContentVisibility(false);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user