mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-08-26 22:00:17 +08:00
fix(gestures)propagate touch to parent so that gestures can work (#6171)
* propagate gesture touch to parent so that gestures can work * test: swipe passtrough test
This commit is contained in:

committed by
Alexander Vakrilov

parent
bd91bfb28a
commit
8a5f73055e
@ -14,6 +14,7 @@ export function loadExamples() {
|
|||||||
examples.set("gestures", "events/gestures");
|
examples.set("gestures", "events/gestures");
|
||||||
examples.set("touch", "events/touch-event");
|
examples.set("touch", "events/touch-event");
|
||||||
examples.set("pan", "events/pan-event");
|
examples.set("pan", "events/pan-event");
|
||||||
|
examples.set("swipe-passtrough", "events/swipe-event-passtrough");
|
||||||
examples.set("handlers", "events/handlers");
|
examples.set("handlers", "events/handlers");
|
||||||
examples.set("console", "events/console");
|
examples.set("console", "events/console");
|
||||||
examples.set("i61", "events/i61");
|
examples.set("i61", "events/i61");
|
||||||
|
22
apps/app/ui-tests-app/events/swipe-event-passtrough.ts
Normal file
22
apps/app/ui-tests-app/events/swipe-event-passtrough.ts
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
import { EventData } from "tns-core-modules/data/observable";
|
||||||
|
import { Page } from "tns-core-modules/ui/page";
|
||||||
|
import { SwipeGestureEventData } from "tns-core-modules/ui/gestures";
|
||||||
|
import { TextView } from "tns-core-modules/ui/text-view";
|
||||||
|
|
||||||
|
let outputText: TextView;
|
||||||
|
export function navigatingTo(args: EventData) {
|
||||||
|
var page = <Page>args.object;
|
||||||
|
outputText = page.getViewById<TextView>("output");
|
||||||
|
}
|
||||||
|
|
||||||
|
export function onSwipe(data: SwipeGestureEventData) {
|
||||||
|
const msg = `swipe state:${data.direction}`;
|
||||||
|
console.log(msg);
|
||||||
|
outputText.text += msg + "\n";
|
||||||
|
}
|
||||||
|
|
||||||
|
export function onTap(args) {
|
||||||
|
const msg = `tapEvent triggered`;
|
||||||
|
console.log(msg);
|
||||||
|
outputText.text += msg + "\n";
|
||||||
|
}
|
10
apps/app/ui-tests-app/events/swipe-event-passtrough.xml
Normal file
10
apps/app/ui-tests-app/events/swipe-event-passtrough.xml
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
<Page navigatingTo="navigatingTo">
|
||||||
|
<GridLayout rows="*, *" columns="*, *, *" swipe="onSwipe" backgroundColor="lightgreen">
|
||||||
|
<StackLayout row="0" col="1" text="swipe here" tap="onTap" backgroundColor="lightblue">
|
||||||
|
<Label text="swipe/tap inside" verticalAlignement="top"/>
|
||||||
|
</StackLayout>
|
||||||
|
<Label row="1" colSpan="3"
|
||||||
|
text="" textWrap="true"
|
||||||
|
id="output" automationText="output" style="font-size: 10, font-family: monospace;"/>
|
||||||
|
</GridLayout>
|
||||||
|
</Page>
|
@ -72,12 +72,7 @@ function initializeTouchListener(): void {
|
|||||||
|
|
||||||
onTouch(view: android.view.View, event: android.view.MotionEvent): boolean {
|
onTouch(view: android.view.View, event: android.view.MotionEvent): boolean {
|
||||||
const owner = this.owner;
|
const owner = this.owner;
|
||||||
for (let type in owner._gestureObservers) {
|
owner.handleGestureTouch(event);
|
||||||
let list = owner._gestureObservers[type];
|
|
||||||
list.forEach(element => {
|
|
||||||
element.androidOnTouchEvent(event);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
let nativeView = owner.nativeViewProtected;
|
let nativeView = owner.nativeViewProtected;
|
||||||
if (!nativeView || !nativeView.onTouchEvent) {
|
if (!nativeView || !nativeView.onTouchEvent) {
|
||||||
@ -320,6 +315,18 @@ export class View extends ViewCommon {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public handleGestureTouch(event: android.view.MotionEvent): any {
|
||||||
|
for (let type in this._gestureObservers) {
|
||||||
|
let list = this._gestureObservers[type];
|
||||||
|
list.forEach(element => {
|
||||||
|
element.androidOnTouchEvent(event);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
if (this.parent instanceof View) {
|
||||||
|
this.parent.handleGestureTouch(event);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private hasGestureObservers() {
|
private hasGestureObservers() {
|
||||||
return this._gestureObservers && Object.keys(this._gestureObservers).length > 0
|
return this._gestureObservers && Object.keys(this._gestureObservers).length > 0
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user