GestureDetector
GestureDetector is the low-level input wrapper for pointer-style interactions.
It lets you attach actions for taps, secondary clicks, long presses, drag lifecycle events, hover enter and exit, and drop interactions. That makes it useful for custom surfaces, dismissal backdrops, context menus, drag targets, and other interaction patterns that are not already covered by a higher-level widget.
Use GestureDetector when you need this level of control. Do not reach for it first when a higher-level widget already expresses the interaction. A Button, Checkbox, or dedicated input widget usually gives you clearer semantics with less work.
Example
use fission::prelude::*;
let widget: Widget = GestureDetector {
child:
Container::new(Text::new("Open context menu").into())
.padding_all(12.0)
.into(),
,
on_secondary_click: Some(show_context_menu_action),
..Default::default()
}
.into();
This is a good use case because the interaction is more specific than a plain button press.
Field table
| | | |
|---|
| | | |
| | The wrapped child that receives gesture detection. | Required. Default uses an empty spacer child. |
| | | When present, the lowered semantics become focusable. |
| | | |
| | | |
| | | |
| | Action for drag movement. | |
| | | |
| | Action when the pointer enters the bounds. | Useful on desktop and web. |
| | Action when the pointer leaves the bounds. | Useful on desktop and web. |
| | Action when a drag payload is dropped on this widget. | |
| | Action for right click or equivalent secondary click. | |
| | Action when a drag enters the target bounds. | |
| | Action when a drag leaves the target bounds. | |
| | Opaque bytes attached to drag sources. | Defaults to None. Also marks the widget as draggable. |
Interaction and semantics behavior
GestureDetector lowers to a semantics node rather than a visual node. That matters because it means the wrapped child keeps its layout and appearance, while the detector adds interaction triggers around it.
The lowered semantics also advertise drag capability when drag handlers or drag payload are present. That is what makes it a useful building block for custom drag-and-drop flows.
Specific advice
Prefer higher-level widgets when possible. If a control is conceptually a button, use a button. If a control is conceptually a text input, use a text input. GestureDetector is best when the gesture itself is the important abstraction, not when it is only a way to simulate a more specific control.
For drop targets, keep the payload format documented and stable. The runtime only carries opaque bytes here; your application still needs a clear meaning for those bytes.
Production checklist
For GestureDetector, review the fields that change behavior before treating the widget as finished: id, child, on_tap, on_double_tap, on_long_press, on_drag_start. The goal is to make the product rule visible in state and actions, not hidden inside ad-hoc construction code.
Bind on_tap, on_double_tap, on_long_press, on_drag_start to explicit reducer actions and test that the reducer handles unavailable, duplicate, or invalid input safely.
When child widgets are generated from data, give reordered or filtered rows an explicit WidgetId so retained local state and scroll behavior do not drift between items.
Set id only when identity must be stable across filtering, reordering, diagnostics, or tests; otherwise let Fission derive identity from structure.
Check the semantics tree for the user-facing label or role that makes this widget understandable without relying only on pixels.
Add at least one component or harness test that confirms the visible text, semantic role, action dispatch, and layout constraint that matter for this widget in context.
If a screen starts repeating the same GestureDetector setup, extract a named component around this widget. That keeps the reference API small while making product code easier to read and safer for generated code to copy.
Button, Overlay, Positioned, and Popover.