Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions changelog.d/android-overflow-touch-routing.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
### Fixed

- Keep off-target clickable Android views from stealing touches (#2310 by @J4ck1e2000).
2 changes: 1 addition & 1 deletion docs/architecture/interaction.md
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ Apps opt into gamepad focus navigation explicitly with `gamepad.EnableFocusNavig
- `driver.IntoView` undoes a view's transform by unprojecting its drawn plane; a collapsed plane takes no pointer. `ReachView` checks its local bounds, slop and pointer events, and the children by the area or, once flagged, anywhere.
- Windows and Linux share the view tree traversal for presses, pointer paths and scrollbars. Press lookup can pass through a view that does not match. Pointer paths and scrollbar lookup skip fully transparent views and stop at the frontmost subtree that takes the pointer. Each backend converts points through its current view transforms and supplies its scrollbar geometry.
- macOS overrides `hitTest:` and undoes the layer's presentation transform itself, since AppKit's view conversion leaves it out; a layer never transformed is taken as it is laid out without asking Core Animation. iOS uses UIKit's transformed coordinate conversion and searches the children outside the bounds by the area and flag too. A press ends as a press in the slop too. A macOS scroll view's container asks only the children a point may reach. The raw hit test for window drags, drops, selections and scroll bars returns the deepest view rather than its pressable ancestor, with the same pointer events.
- Android's `Group` hands a touch outside every child's bounds, each child's transform undone, to the topmost child whose slop or area holds it or that is a group not clipping its children, for the rest of the gesture; `None` declines the touch, `BoxNone` leaves it to the children and `BoxOnly` intercepts theirs. A child that declines the probe keeps no `childrenOnly` flag and no gesture views from it, and a finished routed gesture clears the flag too.
- Android's `Group` checks children from front to back with each child's transform undone. It leaves in-bounds touches to native dispatch and routes a hit in a child's slop or overflow to that child for the gesture. An overflow probe lets a `Group` dispatch only to its children; other native containers, including text nodes, receive the probe only when a descendant is actually hit. `None` declines a touch, `BoxNone` leaves it to the children and `BoxOnly` intercepts theirs. A declined probe leaves neither a `childrenOnly` flag nor gesture candidates; a finished routed gesture clears the flag too.
- The web needs no area, since the browser finds children outside their parent itself. `pointer-events` classes carry `PointerEvents`, and a slop is a pseudo-element around the view.
- A slop works where the parent's bounds or area hold it, as in UIKit and React Native.
- Long presses wait 500 ms, or the view's `DelayLongPress`: a timer on macOS, iOS, the web and Linux, which no longer uses GTK's long press gesture, and on Android when the delay is the view's own, the system's long click then only taking the press. Windows reports press down, up and long presses from the left button itself and finds the press's view by its own hit test at the release, as Linux does.
Expand Down
3 changes: 3 additions & 0 deletions internal/platform/android/java/dev/oneo/nsgo/NsgoView.java
Original file line number Diff line number Diff line change
Expand Up @@ -7012,6 +7012,9 @@ private View route(MotionEvent e) {
|| c.area != null && x >= c.area[0] * density && y >= c.area[1] * density
&& x < (c.area[0] + c.area[2]) * density && y < (c.area[1] + c.area[3]) * density;
if (!slop && !area) continue;
// Group can probe outside its bounds without taking the touch itself. Other
// ViewGroups (such as clickable text) need a descendant the touch actually hits.
if (!slop && !(child instanceof Group) && touchHit(child, x, y) == null) continue;
if (child instanceof Group) ((Group) child).childrenOnly = !slop;
int candidates = gestures.candidates();
if (deliver(child, e)) return child;
Expand Down
28 changes: 28 additions & 0 deletions internal/testhost/testdata/press/routing_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,34 @@ func TestPressRoutingDoesNotDisableSiblings(t *testing.T) {
}
}

func TestClickableTextDoesNotStealSiblingTouches(t *testing.T) {
var buttonPresses, linkPresses int
app := nsgotest.Start(t, func(*core.Scope) core.Node {
return core.View{Style: core.Style{Width: core.Pt(300), Height: core.Pt(200)}, Children: []core.Node{
core.View{Style: core.Style{Padding: core.All(12), Gap: 8}, Children: []core.Node{
core.Input{TestID: "field", Style: core.Style{Height: core.Pt(36)}},
core.View{TestID: "button", Style: core.Style{Height: core.Pt(36)},
OnPress: func(core.PressEvent) { buttonPresses++ }},
}},
core.View{Style: core.Style{Padding: core.All(12)}, Children: []core.Node{
core.Text{TestID: "link", Content: "Link", OnPress: func(core.PressEvent) { linkPresses++ }},
}},
}}
}, nsgotest.Size(300, 200))
app.Press("id:field")
if !app.Find("id:field").Focused || linkPresses != 0 {
t.Fatalf("tap on field: focused=%v, link presses=%d", app.Find("id:field").Focused, linkPresses)
}
app.Press("id:button")
if buttonPresses != 1 || linkPresses != 0 {
t.Fatalf("tap on button: button presses=%d, link presses=%d", buttonPresses, linkPresses)
}
app.Press("id:link")
if linkPresses != 1 {
t.Fatalf("tap on link: link presses=%d, want 1", linkPresses)
}
}

// A sibling probed for a touch outside it, which declines it, must not take the touch's pan from the views it lands on.
func TestDeclinedRoutingLeavesPansToTheTouchedViews(t *testing.T) {
var outer, sibling, presses int
Expand Down
Loading