Skip to content

Add experimental Android support#1590

Open
SparkyTD wants to merge 33 commits intomarc2332:mainfrom
SparkyTD:android_fixes
Open

Add experimental Android support#1590
SparkyTD wants to merge 33 commits intomarc2332:mainfrom
SparkyTD:android_fixes

Conversation

@SparkyTD
Copy link
Contributor

@SparkyTD SparkyTD commented Mar 4, 2026

This PR introduces some fixes and changes that are required for Android support.

Summary of changes

  • Add support for user-specified custom EventLoopBuilder at window creation. This will be required in order to create a custom event loop using EventLoop::with_android_app(app: AndroidApp).
  • Fix a hit-testing issue in is_point_inside() by multiplying the hit rect size by the scale factor. This does not pose an issue on Desktop, but breaks hit-testing completely on the high scaling factor on most Android device. Likely due to internal floating point or rounding error in Skia. (Already fixed by Fix pointer enter/leave hit-testing for rects at large coordinates #1583)
  • Properly integrate touch events into the pointer press and global event handling logic.
  • Recreate the app window rendering context when the app is "resumed", i.e. when the user moves the app into the background, and then re-opens it on Android.
  • Handle global touch capture events on the Slider component (Already fixed by feat(core): Global pointer events #1591)
  • Add support for ScrollView and VirtualScrollView touch scrolling on Android
  • Add an example project that can be built for both Android and Desktop

Currently known issues

  • No soft keyboard / IME support

Issues

@SparkyTD SparkyTD requested a review from marc2332 as a code owner March 4, 2026 22:06
@codecov
Copy link

codecov bot commented Mar 4, 2026

Codecov Report

❌ Patch coverage is 72.32376% with 106 lines in your changes missing coverage. Please review.
✅ Project coverage is 61.03%. Comparing base (a23ee88) to head (68745c9).

Files with missing lines Patch % Lines
examples/android/src/app.rs 0.00% 32 Missing ⚠️
...a-components/src/scrollviews/virtual_scrollview.rs 36.11% 23 Missing ⚠️
crates/freya-winit/src/renderer.rs 0.00% 23 Missing ⚠️
crates/freya-winit/src/config.rs 0.00% 8 Missing ⚠️
examples/android/src/main.rs 0.00% 8 Missing ⚠️
crates/freya-winit/src/window.rs 0.00% 6 Missing ⚠️
crates/freya-winit/src/drivers/gl.rs 0.00% 3 Missing ⚠️
crates/freya-winit/src/lib.rs 0.00% 3 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1590      +/-   ##
==========================================
+ Coverage   60.90%   61.03%   +0.12%     
==========================================
  Files         290      292       +2     
  Lines       35837    36213     +376     
==========================================
+ Hits        21826    22101     +275     
- Misses      14011    14112     +101     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@marc2332 marc2332 moved this to Pending for Review in Freya Planning Mar 4, 2026
@marc2332 marc2332 added this to the 0.4.0 milestone Mar 4, 2026
@marc2332 marc2332 added the enhancement 🔥 New feature or request label Mar 4, 2026
@marc2332
Copy link
Owner

marc2332 commented Mar 5, 2026

Merged #1591, you should be able to revert those changes related to touch events :)

@SparkyTD SparkyTD force-pushed the android_fixes branch 3 times, most recently from 95f82cd to 0e207f9 Compare March 6, 2026 17:08
Copy link
Owner

@marc2332 marc2332 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very cool, works very nicely. Just a few things:

  • Let's add scrolling to VirtualScrollView too, just like you did in SrollView
  • Format code using just f

Copy link
Owner

@marc2332 marc2332 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

rest lgtm

@marc2332 marc2332 self-requested a review March 7, 2026 21:26
@SparkyTD SparkyTD changed the title Minor fixes and improvements needed for experimental Android support Add experimental Android support Mar 8, 2026
@marc2332 marc2332 self-requested a review March 14, 2026 10:04

window.pre_present_notify();
self.gr_context.flush_submit_and_sync_cpu();
self.gl_surface.swap_buffers(&self.gl_context).unwrap();
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is a silent error really the way to go? Wouldn't that be a bit of a fatal error?

Copy link
Owner

@marc2332 marc2332 Mar 14, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

or is it recoverable / fail to ignore?


pub fn with_event_loop_builder(
mut self,
event_loop_builder: EventLoopBuilder<NativeEvent>,
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since now NativeEvent can be used like this we should reexport it in freya/src/lib.rs L99 too


[dependencies]
freya = { workspace = true }
freya-winit = { workspace = true }
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This way we can remove this dependency

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you also mention the android sdk?

@marc2332 marc2332 moved this from Pending for Review to In Progress in Freya Planning Mar 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement 🔥 New feature or request

Projects

Status: In Progress

Development

Successfully merging this pull request may close these issues.

enhancement: Touch support for scrolling

3 participants