Skip to content

Android (S2): touch input and the system long-press delay #2649

Done

Description

@pascalandr

Follow-up to #2484 (slice S2 of the native Android host series on https://github.com/NeuralNomadsAI/rune; builds on S1).

Gap on dev (3e46617e5)

  • No host forwards Android MotionEvents to Rune.
  • crates/rune/src/runtime/input/touch.rs:19 hardcodes LONG_PRESS at 0.5 s, whereas Android's system long-press timeout is 400 ms by default and up to 1.5 s with the accessibility Touch & hold delay setting.
  • Cx::touch_controls is false on Android.

Slice (+655 −438 over S1, mostly kit-gallery's main.rs split into lib.rs)

  • RuneView.onTouchEvent forwards every pointer and batched historical samples.
  • Pure Android action-to-phase mapping with host tests.
  • Runtime::set_touch_long_press to pass the system's long-press timeout.
  • touch_controls / hover_none enabled on Android.
  • examples/android-gallery.

Checked

  • Host: 61 touch and Android tests, including hold arming at a host-supplied delay and invalid delays falling back to the default.
  • Emulator (x86_64 API 35): tap toggles switches; gallery scrolls under the finger and coasts after lift; hold arms at Android's 400 ms.
  • Also verified merged onto current dev (3e46617e5) in android/next (03f8c0ff1, including compatibility with upstream touch focus-on-lift fix(touch): defer focus, blur, and selection changes to tap-up #2558).
  • Not checked in S2: pinch, fling curve parity against RecyclerView.

Reference branch

Questions

  1. Flings use Rune's own momentum rather than ViewConfiguration's fling constants. Do you want Android's velocity bounds and friction fed in too?
  2. Tx::popup_menu currently returns None on Android (no native menu), so apps render their own. Is that the intended behavior on Android?

Activity

  1. opencodejr commented on Nov 27, 2026

    @opencodejr
    Contributor

    this slice builds on #2647 (s0) and #2648 (s1), which are not on dev yet (platform/android/ and RuneView are not in the tree), and raises two product/api decisions alongside Runtime::set_touch_long_press (only the shared runtime hooks could land ahead of s1; Runtime::set_touch_controls already exists in crates/rune/src/runtime/api.rs:397, matching ios in crates/rune/src/platform/embed.rs:241).

    thoughts from the current codebase (crates/rune/src/runtime/input/touch.rs, crates/rune/src/runtime/scroll/touch.rs, crates/rune/src/runtime/motion/tracks.rs, crates/rune/src/popup_menu/mod.rs, crates/rune/src/runtime/input/popup_fallback.rs, crates/rune/src/platform/embed_frame.rs, PLAN.md):

    1. touch fling physics (runtime/scroll/touch.rs): touch flings currently share one curve across web, ios, and touchscreens (±8000 pt/s clamp, exponential decay SCROLL_DECAY = 2.002 from runtime/motion/tracks.rs:6, no minimum fling threshold). PLAN.md lists scroll momentum under native behaviour, and android's ViewConfiguration exposes scaledMinimumFlingVelocity (50 dp/s), scaledMaximumFlingVelocity (8000 dp/s), and scrollFriction (0.015, driving OverScroller's spline curve rather than plain exponential decay). keeping rune's shared momentum for s2 matches ios/web and avoids adding a second physics path now, while passing ViewConfiguration bounds or matching OverScroller would add a host-configurable fling api on Runtime beside set_touch_long_press.
    2. Tx::popup_menu on android (popup_menu/mod.rs, runtime/input/popup_fallback.rs, platform/embed_frame.rs): popup_menu_supported() is true only on macos and windows, so returning None by default on android matches linux and ios (and rune's own-look direction in PLAN.md). note that linux also supports opt-in in-window menus via App::on_popup_menu (Presenter::open_core checks popup_menu_fallback_active), whereas embed_frame::flush_requests (platform/embed_frame.rs:226-228) currently calls rt.cancel_popups(app) unconditionally, so App::on_popup_menu is bypassed on LayerHost hosts (ios and android) even though App::on_field_menu runs in field_menu.rs:147.

    questions for maintainers:

    • should android touch flings keep rune's shared momentum curve (SCROLL_DECAY = 2.002, ±8000 pt/s) for s2, or expose a Runtime hook for ViewConfiguration's velocity bounds / friction (or OverScroller curve)?
    • should popup_menu_supported() stay false on android (no native PopupMenu), and should embed_frame::flush_requests honor App::on_popup_menu on LayerHost (android and ios) the same way desktop linux does?
  2. pascalandr commented on Nov 27, 2026

    @pascalandr
    Author
    1. Flings: the fork keeps the shared curve. On a 120 Hz phone it held its frames; it was not compared side by side with a native list. Keeping it for S2 is fine by us.
    2. Tx::popup_menu: popup_menu_supported() stays false in the fork. Text's own menus (a field's, selected text's Copy) are left to the host, which shows them as Android's floating selection toolbar (a later slice, host.text_menus); every other menu is cancelled by flush_requests, so App::on_popup_menu is bypassed there as you describe. Honoring it on LayerHost would be welcome and does not conflict with the toolbar.
  3. Hona commented on Nov 28, 2026

    @Hona
    Member

    Shipped in PR #2709 (86189625b).

    Design decisions

    • Touch forwarding & system long-press delay: RuneView.onTouchEvent forwards all pointers and batched historical ACTION_MOVE samples in chronological order across JNI (nativeTouch), mapped through a pure cross-platform action/flag/coordinate module (crates/rune/src/platform/android/touch.rs, including API 33+ MotionEvent.FLAG_CANCELED -> TouchPhase::Cancelled). Added Runtime::set_touch_long_press / Runtime::touch_long_press (default 0.5 s; invalid non-positive or non-finite values fall back to 0.5 s) and wired ViewConfiguration.getLongPressTimeout() on view init and resume so Android's 400 ms default and accessibility Touch & hold delay changes take effect.
    • Touch fling physics: Kept Rune's shared fling momentum curve (SCROLL_DECAY = 2.002, ±8000 pt/s) for S2, matching iOS and web.
    • Tx::popup_menu & App::on_popup_menu on LayerHost: Kept popup_menu_supported() false on Android and iOS, and updated embed_frame::flush_requests to honor App::on_popup_menu when registered instead of unconditionally cancelling open/queued fallback pop-up menus (apps without on_popup_menu still resolve to None immediately).
    • Example: Split examples/kit-gallery into lib.rs + thin main.rs and added examples/android-gallery (dev.rune.gallery).

    Verification

    • Verified locally on Windows host: runtime::input::touch (53 tests including 400 ms / 1500 ms / invalid long-press fallback), platform::android (21 tests including action/flag mapping, batched touch pipeline, and state-machine frame deduplication), platform::embed_frame (10 tests including App::on_popup_menu preservation and missed_step delivery), set_touch_long_press doctest, android-gallery unit test, and kit-gallery check.
    • Verified in CI: Android NDK cross-checks (aarch64-linux-android, x86_64-linux-android including android-gallery), Kotlin/DEX/APK packaging (android-hello), check, and size all passed.
    • Not run on real Android hardware or an Android emulator (no Android device/emulator available on this host). Please reopen if anything behaves unexpectedly on device.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions