FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

feat: add ability to pass touch event thru parent view by manoldonev · Pull Request #6204 · NativeScript/NativeScript · GitHub

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .ts  (9) .xml  (1) All 2 file types selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
1 change: 1 addition & 0 deletions apps/app/ui-tests-app/layouts/main-page.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ export function loadExamples() {
examples.set("pgrid", "layouts-percent/grid");
examples.set("pstack", "layouts-percent/stack");
examples.set("pwrap", "layouts-percent/wrap");
examples.set("passThroughParent", "layouts/passThroughParent");
examples.set("stacklayout-6059", "layouts/stacklayout-6059");

return examples;
Expand Down
19 changes: 19 additions & 0 deletions apps/app/ui-tests-app/layouts/passThroughParent.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
export function onOuterWrapLayoutTap() {
console.log("on outer wrap layout tap");
}

export function onStackLayoutThrowTap() {
throw new Error("Should not tap layout with IsPassThroughParentEnabled=true");
}

export function onUserInteractionDisabledTap() {
throw new Error("Should not tap button with IsUserInteractionEnabled=false");
}

export function onDisabledThrowTap() {
throw new Error("Should not tap button with IsEnabled=false");
}

export function onTap() {
console.log("on button tap");
}
24 changes: 24 additions & 0 deletions apps/app/ui-tests-app/layouts/passThroughParent.xml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<Page class="page" actionBarHidden="true" xmlns="http://schemas.nativescript.org/tns.xsd">

<WrapLayout tap="onOuterWrapLayoutTap" backgroundColor="#bed3f4">

<StackLayout tap="onStackLayoutThrowTap" backgroundColor="#f3f9db" height="200" isPassThroughParentEnabled="true">
<Label text="isPassThroughParentEnabled='true'" isUserInteractionEnabled="false" />
<Button isUserInteractionEnabled="false" tap="onUserInteractionDisabledThrowTap" text="isUserInteractionEnabled='false'"></Button>
<Button isEnabled="false" tap="onDisabledThrowTap" text="isEnabled='false'"></Button>
<Button tap="onTap" text="TAP"></Button>
</StackLayout>

<StackLayout tap="onStackLayoutThrowTap" style.margin="20" height="300" width="300" backgroundColor="#f5edf7" isPassThroughParentEnabled="true">
<Label text="isPassThroughParentEnabled='true'" isUserInteractionEnabled="false" />
<StackLayout tap="onStackLayoutThrowTap" backgroundColor="#f3f9db" height="200" isPassThroughParentEnabled="true">
<Label text="isPassThroughParentEnabled='true'" isUserInteractionEnabled="false" />
<Button isUserInteractionEnabled="false" tap="onUserInteractionDisabledThrowTap" text="isUserInteractionEnabled='false'"></Button>
<Button isEnabled="false" tap="onDisabledThrowTap" text="isEnabled='false'"></Button>
<Button tap="onTap" text="TAP"></Button>
</StackLayout>
</StackLayout>

</WrapLayout>

</Page>
2 changes: 1 addition & 1 deletion tns-core-modules/ui/core/view/view-common.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -1021,4 +1021,4 @@ export const isEnabledProperty = new Property<ViewCommon, boolean>({
isEnabledProperty.register(ViewCommon);

export const isUserInteractionEnabledProperty = new Property<ViewCommon, boolean>({ name: "isUserInteractionEnabled", defaultValue: true, valueConverter: booleanConverter });
isUserInteractionEnabledProperty.register(ViewCommon);
isUserInteractionEnabledProperty.register(ViewCommon);
32 changes: 15 additions & 17 deletions tns-core-modules/ui/core/view/view.android.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -357,15 +357,20 @@ export class View extends ViewCommon {
}

private setOnTouchListener() {
if (this.nativeViewProtected && this.hasGestureObservers()) {
this.touchListenerIsSet = true;
if (this.nativeViewProtected.setClickable) {
this.nativeViewProtected.setClickable(true);
}
if (!this.nativeViewProtected || !this.hasGestureObservers()) {
return;
}

// do not set noop listener that handles the event (disabled listener) if IsUserInteractionEnabled is
// false as we might need the ability for the event to pass through to a parent view
initializeTouchListener();
this.touchListener = this.touchListener || new TouchListener(this);
this.nativeViewProtected.setOnTouchListener(this.touchListener);

this.touchListenerIsSet = true;

initializeTouchListener();
this.touchListener = this.touchListener || new TouchListener(this);
this.nativeViewProtected.setOnTouchListener(this.touchListener);
if (this.nativeViewProtected.setClickable) {
this.nativeViewProtected.setClickable(this.isUserInteractionEnabled);
}
}

Expand Down Expand Up @@ -605,15 +610,8 @@ export class View extends ViewCommon {
}

[isUserInteractionEnabledProperty.setNative](value: boolean) {
if (!value) {
initializeDisabledListener();
// User interaction is disabled -- we stop it and we do not care whether someone wants to listen for gestures.
this.nativeViewProtected.setOnTouchListener(disableUserInteractionListener);
} else {
this.setOnTouchListener();
if (!this.touchListenerIsSet) {
this.nativeViewProtected.setOnTouchListener(null);
}
if (this.nativeViewProtected.setClickable) {
this.nativeViewProtected.setClickable(value);
}
}

Expand Down
2 changes: 1 addition & 1 deletion tns-core-modules/ui/core/view/view.ios.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Definitions.
// Definitions.
import { Point, View as ViewDefinition, dip } from ".";
import { ViewBase } from "../view-base";

Expand Down
4 changes: 4 additions & 0 deletions tns-core-modules/ui/layouts/layout-base-common.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ export class LayoutBaseCommon extends CustomLayoutView implements LayoutBaseDefi
}

public clipToBounds: boolean;
public isPassThroughParentEnabled: boolean;

public _childIndexToNativeChildIndex(index?: number): number {
if (index === undefined) {
Expand Down Expand Up @@ -151,3 +152,6 @@ export class LayoutBaseCommon extends CustomLayoutView implements LayoutBaseDefi

export const clipToBoundsProperty = new Property<LayoutBaseCommon, boolean>({ name: "clipToBounds", defaultValue: true, valueConverter: booleanConverter });
clipToBoundsProperty.register(LayoutBaseCommon);

export const isPassThroughParentEnabledProperty = new Property<LayoutBaseCommon, boolean>({ name: "isPassThroughParentEnabled", defaultValue: false, valueConverter: booleanConverter });
isPassThroughParentEnabledProperty.register(LayoutBaseCommon);
6 changes: 5 additions & 1 deletion tns-core-modules/ui/layouts/layout-base.android.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {
LayoutBaseCommon, clipToBoundsProperty,
LayoutBaseCommon, clipToBoundsProperty, isPassThroughParentEnabledProperty,
paddingLeftProperty, paddingTopProperty, paddingRightProperty, paddingBottomProperty, Length
} from "./layout-base-common";

Expand All @@ -25,6 +25,10 @@ export class LayoutBase extends LayoutBaseCommon {
console.warn(`clipToBounds with value false is not supported on Android. You can use this.android.getParent().setClipChildren(false) as an alternative`);
}

[isPassThroughParentEnabledProperty.setNative](value: boolean) {
(<any>this.nativeViewProtected).setPassThroughParent(value);
}

[paddingTopProperty.getDefault](): Length {
return { value: this._defaultPaddingTop, unit: "px" };
}
Expand Down
8 changes: 8 additions & 0 deletions tns-core-modules/ui/layouts/layout-base.d.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,14 @@ export class LayoutBase extends CustomLayoutView {
* Gets or sets a value indicating whether to clip the content of this layout.
*/
clipToBounds: boolean;

/**
* Gets or sets a value indicating whether touch event should pass through to a parent view of the
* layout container in case an interactive child view did not handle it.
* Default value of this property is false. This does not affect the appearance of the view.
*/
isPassThroughParentEnabled: boolean;
}

export const clipToBoundsProperty: Property<LayoutBase, boolean>;
export const isPassThroughParentEnabledProperty: Property<LayoutBase, boolean>;
8 changes: 7 additions & 1 deletion tns-core-modules/ui/layouts/layout-base.ios.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import { LayoutBaseCommon, clipToBoundsProperty, View } from "./layout-base-common";
import {
LayoutBaseCommon, clipToBoundsProperty, isPassThroughParentEnabledProperty, View
} from "./layout-base-common";

export * from "./layout-base-common";

Expand Down Expand Up @@ -34,4 +36,8 @@ export class LayoutBase extends LayoutBaseCommon {
[clipToBoundsProperty.setNative](value: boolean) {
this._setNativeClipToBounds();
}

[isPassThroughParentEnabledProperty.setNative](value: boolean) {
(<any>this.nativeViewProtected).setPassThroughParent(value);
}
}

Back | FazBrowse Home | New Git URL