mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-11-05 13:26:48 +08:00
fix: update tap event data (#8415)
* Update tap event data object Adds a: - TabGestureEventData interface, which can be used for both tap and doubleTap events. - The event object returned by both tap and doubleTap events now have getX(), getY(), and getPointersCount() methods. These facilitate the same function as those of the touch event object. * ui(gesture): getX,getY in DIP Updates the getX() and getY() methods of Tap, doubleTap and touch events to return DIP instead of DP. * ui(gesture): tap event data includes location Tap and doubleTap event data now include getX and getY methods for event location. These are in DIP format. getPointerCount is also available. * Fix tslint errors * fix minor formatting issues for api-extrector
This commit is contained in:
@@ -2417,6 +2417,15 @@ export class TabViewItem extends ViewBase {
|
|||||||
public view: View;
|
public view: View;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// @public
|
||||||
|
export interface TapGestureEventData extends GestureEventData {
|
||||||
|
getPointerCount(): number;
|
||||||
|
|
||||||
|
getX(): number;
|
||||||
|
|
||||||
|
getY(): number;
|
||||||
|
}
|
||||||
|
|
||||||
// @public
|
// @public
|
||||||
export interface Template {
|
export interface Template {
|
||||||
(): View;
|
(): View;
|
||||||
@@ -2536,19 +2545,11 @@ export interface TimerInfo {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// @public
|
// @public
|
||||||
export interface TouchGestureEventData extends GestureEventData {
|
export interface TouchGestureEventData extends TapGestureEventData {
|
||||||
action: "up" | "move" | "down" | "cancel";
|
action: "up" | "move" | "down" | "cancel";
|
||||||
|
|
||||||
// Warning: (ae-forgotten-export) The symbol "Pointer" needs to be exported by the entry point index.d.ts
|
// Warning: (ae-forgotten-export) The symbol "Pointer" needs to be exported by the entry point index.d.ts
|
||||||
getActivePointers(): Array<Pointer>;
|
getActivePointers(): Array<Pointer>;
|
||||||
|
|
||||||
getAllPointers(): Array<Pointer>;
|
getAllPointers(): Array<Pointer>;
|
||||||
|
|
||||||
getPointerCount(): number;
|
|
||||||
|
|
||||||
getX(): number;
|
|
||||||
|
|
||||||
getY(): number;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// @public (undocumented)
|
// @public (undocumented)
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
// Definitions.
|
// Definitions.
|
||||||
import { DoubleTapGestureEventData, GestureEventData, GestureEventDataWithState, PanGestureEventData, RotationGestureEventData, SwipeGestureEventData } from ".";
|
import { GestureEventData, TapGestureEventData, SwipeGestureEventData, PanGestureEventData, RotationGestureEventData, GestureEventDataWithState } from ".";
|
||||||
import { View, EventData } from "../core/view";
|
import { View, EventData } from "../core/view";
|
||||||
|
|
||||||
// Types.
|
// Types.
|
||||||
@@ -71,14 +71,14 @@ function initializeTapAndDoubleTapGestureListener() {
|
|||||||
if (this._target.getGestureObservers(GestureTypes.doubleTap)) {
|
if (this._target.getGestureObservers(GestureTypes.doubleTap)) {
|
||||||
this._tapTimeoutId = timer.setTimeout(() => {
|
this._tapTimeoutId = timer.setTimeout(() => {
|
||||||
if (this._type & GestureTypes.tap) {
|
if (this._type & GestureTypes.tap) {
|
||||||
const args = _getArgs(GestureTypes.tap, this._target, motionEvent);
|
const args = _getTapArgs(GestureTypes.tap, this._target, motionEvent);
|
||||||
_executeCallback(this._observer, args);
|
_executeCallback(this._observer, args);
|
||||||
}
|
}
|
||||||
timer.clearTimeout(this._tapTimeoutId);
|
timer.clearTimeout(this._tapTimeoutId);
|
||||||
}, TapAndDoubleTapGestureListenerImpl.DoubleTapTimeout);
|
}, TapAndDoubleTapGestureListenerImpl.DoubleTapTimeout);
|
||||||
} else {
|
} else {
|
||||||
if (this._type & GestureTypes.tap) {
|
if (this._type & GestureTypes.tap) {
|
||||||
const args = _getArgs(GestureTypes.tap, this._target, motionEvent);
|
const args = _getTapArgs(GestureTypes.tap, this._target, motionEvent);
|
||||||
_executeCallback(this._observer, args);
|
_executeCallback(this._observer, args);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -89,7 +89,7 @@ function initializeTapAndDoubleTapGestureListener() {
|
|||||||
timer.clearTimeout(this._tapTimeoutId);
|
timer.clearTimeout(this._tapTimeoutId);
|
||||||
}
|
}
|
||||||
if (this._type & GestureTypes.doubleTap) {
|
if (this._type & GestureTypes.doubleTap) {
|
||||||
const args = _getDoubleTapArgs(this._target, motionEvent);
|
const args = _getTapArgs(GestureTypes.doubleTap, this._target, motionEvent);
|
||||||
_executeCallback(this._observer, args);
|
_executeCallback(this._observer, args);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -372,14 +372,17 @@ export class GesturesObserver extends GesturesObserverBase {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function _getArgs(type: GestureTypes, view: View, e: android.view.MotionEvent): GestureEventData {
|
function _getTapArgs(type: GestureTypes, view: View, e: android.view.MotionEvent): TapGestureEventData {
|
||||||
return <GestureEventData>{
|
return <TapGestureEventData>{
|
||||||
type: type,
|
type: type,
|
||||||
view: view,
|
view: view,
|
||||||
android: e,
|
android: e,
|
||||||
ios: undefined,
|
ios: undefined,
|
||||||
object: view,
|
object: view,
|
||||||
eventName: toString(type),
|
eventName: toString(type),
|
||||||
|
getPointerCount: () => e.getPointerCount(),
|
||||||
|
getX: () => layout.toDeviceIndependentPixels(e.getX()),
|
||||||
|
getY: () => layout.toDeviceIndependentPixels(e.getY())
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -395,19 +398,6 @@ function _getLongPressArgs(type: GestureTypes, view: View, state: GestureStateTy
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
function _getDoubleTapArgs(view: View, e: android.view.MotionEvent): DoubleTapGestureEventData {
|
|
||||||
return <DoubleTapGestureEventData>{
|
|
||||||
type: GestureTypes.doubleTap,
|
|
||||||
view: view,
|
|
||||||
android: e,
|
|
||||||
getX: () => e.getX() / layout.getDisplayDensity(),
|
|
||||||
getY: () => e.getY() / layout.getDisplayDensity(),
|
|
||||||
ios: undefined,
|
|
||||||
object: view,
|
|
||||||
eventName: toString(GestureTypes.doubleTap),
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
function _getSwipeArgs(direction: SwipeDirection, view: View,
|
function _getSwipeArgs(direction: SwipeDirection, view: View,
|
||||||
initialEvent: android.view.MotionEvent, currentEvent: android.view.MotionEvent): SwipeGestureEventData {
|
initialEvent: android.view.MotionEvent, currentEvent: android.view.MotionEvent): SwipeGestureEventData {
|
||||||
return <SwipeGestureEventData>{
|
return <SwipeGestureEventData>{
|
||||||
|
|||||||
70
nativescript-core/ui/gestures/gestures.d.ts
vendored
70
nativescript-core/ui/gestures/gestures.d.ts
vendored
@@ -1,4 +1,4 @@
|
|||||||
/**
|
/**
|
||||||
* Contains the GesturesObserver class, which lets you observe and respond to user gestures.
|
* Contains the GesturesObserver class, which lets you observe and respond to user gestures.
|
||||||
* @module "ui/gestures"
|
* @module "ui/gestures"
|
||||||
*/ /** */
|
*/ /** */
|
||||||
@@ -137,27 +137,30 @@ export interface GestureEventData extends EventData {
|
|||||||
/**
|
/**
|
||||||
* Provides gesture event data.
|
* Provides gesture event data.
|
||||||
*/
|
*/
|
||||||
export interface TouchGestureEventData extends GestureEventData {
|
export interface TapGestureEventData extends GestureEventData {
|
||||||
/**
|
|
||||||
* Gets action of the touch. Possible values: 'up', 'move', 'down', 'cancel'
|
|
||||||
*/
|
|
||||||
action: "up" | "move" | "down" | "cancel";
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Gets the X coordinate of this event inside the view that triggered the event.
|
|
||||||
*/
|
|
||||||
getX(): number;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Gets the Y coordinate of this event inside the view that triggered the event.
|
|
||||||
*/
|
|
||||||
getY(): number;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the number of pointers in the event.
|
* Gets the number of pointers in the event.
|
||||||
*/
|
*/
|
||||||
getPointerCount(): number;
|
getPointerCount(): number;
|
||||||
|
/**
|
||||||
|
* Gets the X coordinate of this event inside the view that triggered the event
|
||||||
|
*/
|
||||||
|
getX(): number;
|
||||||
|
/**
|
||||||
|
* Gets the Y coordinate of the event inside the view that triggered the event.
|
||||||
|
*/
|
||||||
|
getY(): number;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Provides gesture event data.
|
||||||
|
*/
|
||||||
|
export interface TouchGestureEventData extends TapGestureEventData {
|
||||||
|
/**
|
||||||
|
* Gets action of the touch. Possible values: 'up', 'move', 'down', 'cancel'
|
||||||
|
*/
|
||||||
|
action: "up" | "move" | "down" | "cancel";
|
||||||
/**
|
/**
|
||||||
* Gets the pointers that triggered the event.
|
* Gets the pointers that triggered the event.
|
||||||
* Note: In Android there is aways only one active pointer.
|
* Note: In Android there is aways only one active pointer.
|
||||||
@@ -193,6 +196,30 @@ export interface Pointer {
|
|||||||
* Gets the Y coordinate of the pointer inside the view that triggered the event.
|
* Gets the Y coordinate of the pointer inside the view that triggered the event.
|
||||||
*/
|
*/
|
||||||
getY(): number;
|
getY(): number;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gests the X coordinate of the pointer inside the view that triggered the event.
|
||||||
|
* @returns The X coordinate in _Device Pixels_.
|
||||||
|
*/
|
||||||
|
getXPixels(): number
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the X coordinate of the pointer inside the view that triggered the event.
|
||||||
|
* @returns The X coordinate in _Device Independent Pixels_.
|
||||||
|
*/
|
||||||
|
getXDIP(): number
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gests the Y coordinate of the pointer inside the view that triggered the event.
|
||||||
|
* @returns The Y coordinate in _Device Pixels_.
|
||||||
|
*/
|
||||||
|
getYPixels(): number
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the Y coordinate of the pointer inside the view that triggered the event.
|
||||||
|
* @returns The Y coordinate in _Device Independent Pixels_.
|
||||||
|
*/
|
||||||
|
getYDIP(): number
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -212,14 +239,6 @@ export interface PinchGestureEventData extends GestureEventDataWithState {
|
|||||||
getFocusY(): number;
|
getFocusY(): number;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Provides gesture event data for double tap gesture.
|
|
||||||
*/
|
|
||||||
export interface DoubleTapGestureEventData extends GestureEventData {
|
|
||||||
getX(): number;
|
|
||||||
getY(): number;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Provides gesture event data for swipe gesture.
|
* Provides gesture event data for swipe gesture.
|
||||||
*/
|
*/
|
||||||
@@ -307,3 +326,4 @@ export function toString(type: GestureTypes, separator?: string): string;
|
|||||||
* @param type - A string representation of a gesture type (e.g. Tap).
|
* @param type - A string representation of a gesture type (e.g. Tap).
|
||||||
*/
|
*/
|
||||||
export function fromString(type: string): GestureTypes;
|
export function fromString(type: string): GestureTypes;
|
||||||
|
|
||||||
@@ -1,10 +1,14 @@
|
|||||||
// Definitions.
|
// Definitions.
|
||||||
import { DoubleTapGestureEventData, GestureEventData, GestureEventDataWithState, SwipeGestureEventData, PanGestureEventData, RotationGestureEventData, PinchGestureEventData } from ".";
|
|
||||||
|
import { GestureEventData, TapGestureEventData, GestureEventDataWithState, SwipeGestureEventData, PanGestureEventData, RotationGestureEventData, PinchGestureEventData } from ".";
|
||||||
import { View, EventData } from "../core/view";
|
import { View, EventData } from "../core/view";
|
||||||
|
|
||||||
// Types.
|
// Types.
|
||||||
import { GesturesObserverBase, toString, TouchAction, GestureStateTypes, GestureTypes, SwipeDirection } from "./gestures-common";
|
import { GesturesObserverBase, toString, TouchAction, GestureStateTypes, GestureTypes, SwipeDirection } from "./gestures-common";
|
||||||
|
|
||||||
|
// Import layout from utils directly to avoid circular references
|
||||||
|
import { layout } from "../../utils/utils";
|
||||||
|
|
||||||
export * from "./gestures-common";
|
export * from "./gestures-common";
|
||||||
|
|
||||||
export function observe(target: View, type: GestureTypes, callback: (args: GestureEventData) => void, context?: any): GesturesObserver {
|
export function observe(target: View, type: GestureTypes, callback: (args: GestureEventData) => void, context?: any): GesturesObserver {
|
||||||
@@ -123,12 +127,14 @@ export class GesturesObserver extends GesturesObserverBase {
|
|||||||
const nativeView = <UIView>target.nativeViewProtected;
|
const nativeView = <UIView>target.nativeViewProtected;
|
||||||
|
|
||||||
if (type & GestureTypes.tap) {
|
if (type & GestureTypes.tap) {
|
||||||
nativeView.addGestureRecognizer(this._createRecognizer(GestureTypes.tap));
|
nativeView.addGestureRecognizer(this._createRecognizer(GestureTypes.tap, args => {
|
||||||
|
this._executeCallback(_getTapData(args));
|
||||||
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (type & GestureTypes.doubleTap) {
|
if (type & GestureTypes.doubleTap) {
|
||||||
nativeView.addGestureRecognizer(this._createRecognizer(GestureTypes.doubleTap, args => {
|
nativeView.addGestureRecognizer(this._createRecognizer(GestureTypes.doubleTap, args => {
|
||||||
this._executeCallback(_getDoubleTapData(args));
|
this._executeCallback(_getTapData(args));
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -300,19 +306,20 @@ function _getSwipeDirection(direction: UISwipeGestureRecognizerDirection): Swipe
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function _getDoubleTapData(args: GestureEventData): DoubleTapGestureEventData {
|
function _getTapData(args: GestureEventData): TapGestureEventData {
|
||||||
const recognizer = <UITapGestureRecognizer>args.ios;
|
const recognizer = <UITapGestureRecognizer>args.ios;
|
||||||
const location: CGPoint = recognizer.locationInView(args.view.nativeViewProtected);
|
const center = recognizer.locationInView(args.view.nativeViewProtected);
|
||||||
|
|
||||||
return <DoubleTapGestureEventData>{
|
return <TapGestureEventData>{
|
||||||
type: args.type,
|
type: args.type,
|
||||||
view: args.view,
|
view: args.view,
|
||||||
ios: args.ios,
|
ios: args.ios,
|
||||||
android: undefined,
|
android: undefined,
|
||||||
getX: () => location.x,
|
eventName: args.eventName,
|
||||||
getY: () => location.y,
|
object: args.object,
|
||||||
object: args.view,
|
getPointerCount: () => recognizer.numberOfTouches,
|
||||||
eventName: toString(args.type)
|
getX: () => layout.toDeviceIndependentPixels(center.x),
|
||||||
|
getY: () => layout.toDeviceIndependentPixels(center.y)
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
2
nativescript-core/ui/index.d.ts
vendored
2
nativescript-core/ui/index.d.ts
vendored
@@ -10,7 +10,7 @@ export { View, Template, KeyedTemplate, ShownModallyData } from "./core/view";
|
|||||||
export { DatePicker } from "./date-picker";
|
export { DatePicker } from "./date-picker";
|
||||||
export { EditableTextBase } from "./editable-text-base";
|
export { EditableTextBase } from "./editable-text-base";
|
||||||
export { Frame, NavigationEntry, NavigationContext, NavigationTransition, BackstackEntry, ViewEntry } from "./frame";
|
export { Frame, NavigationEntry, NavigationContext, NavigationTransition, BackstackEntry, ViewEntry } from "./frame";
|
||||||
export { GestureEventData, GestureEventDataWithState, GestureStateTypes, GestureTypes, GesturesObserver, PanGestureEventData, PinchGestureEventData, RotationGestureEventData, SwipeDirection, SwipeGestureEventData, TouchGestureEventData } from "./gestures";
|
export { GestureEventData, GestureEventDataWithState, GestureStateTypes, GestureTypes, GesturesObserver, TapGestureEventData, PanGestureEventData, PinchGestureEventData, RotationGestureEventData, SwipeDirection, SwipeGestureEventData, TouchGestureEventData } from "./gestures";
|
||||||
export { HtmlView } from "./html-view";
|
export { HtmlView } from "./html-view";
|
||||||
export { Image } from "./image";
|
export { Image } from "./image";
|
||||||
export { Cache as ImageCache, DownloadError, DownloadRequest, DownloadedData } from "./image-cache";
|
export { Cache as ImageCache, DownloadError, DownloadRequest, DownloadedData } from "./image-cache";
|
||||||
|
|||||||
@@ -22,12 +22,13 @@ export {
|
|||||||
GestureStateTypes,
|
GestureStateTypes,
|
||||||
GestureTypes,
|
GestureTypes,
|
||||||
GesturesObserver,
|
GesturesObserver,
|
||||||
|
TapGestureEventData,
|
||||||
PanGestureEventData,
|
PanGestureEventData,
|
||||||
PinchGestureEventData,
|
PinchGestureEventData,
|
||||||
RotationGestureEventData,
|
RotationGestureEventData,
|
||||||
SwipeDirection,
|
SwipeDirection,
|
||||||
SwipeGestureEventData,
|
SwipeGestureEventData,
|
||||||
TouchGestureEventData
|
TouchGestureEventData,
|
||||||
} from "./gestures";
|
} from "./gestures";
|
||||||
|
|
||||||
export { HtmlView } from "./html-view";
|
export { HtmlView } from "./html-view";
|
||||||
|
|||||||
Reference in New Issue
Block a user