Android: fix first frame not being translated after a rotation

This commit is contained in:
Olivier Goffart 2024-02-26 15:45:57 +01:00
parent 2c5e654dd0
commit b8f302464c
2 changed files with 17 additions and 12 deletions

View file

@ -25,7 +25,7 @@ pub struct AndroidWindowAdapter {
pub(crate) dark_color_scheme: core::pin::Pin<Box<Property<bool>>>,
pub(crate) fullscreen: Cell<bool>,
/// The offset at which the Slint view is drawn in the native window (account for status bar)
pub(crate) offset: Cell<PhysicalPosition>,
pub offset: Cell<PhysicalPosition>,
}
impl WindowAdapter for AndroidWindowAdapter {
@ -198,7 +198,7 @@ impl AndroidWindowAdapter {
) => self.resize(),
PollEvent::Main(MainEvent::RedrawNeeded { .. }) => {
self.pending_redraw.set(false);
self.renderer.render()?;
self.do_render()?;
}
PollEvent::Main(MainEvent::GainedFocus) => {
self.window.dispatch_event(WindowEvent::WindowActiveChanged(true));
@ -334,6 +334,19 @@ impl AndroidWindowAdapter {
});
self.offset.set(offset);
}
pub fn do_render(&self) -> Result<(), PlatformError> {
if let Some(win) = self.app.native_window() {
let o = self.offset.get();
self.renderer.render_transformed_with_post_callback(
0.,
(o.x as f32, o.y as f32),
PhysicalSize { width: win.width() as _, height: win.height() as _ },
None,
)?;
}
Ok(())
}
}
fn position_for_event(motion_event: &MotionEvent, offset: PhysicalPosition) -> PhysicalPosition {

View file

@ -13,7 +13,7 @@ use android_activity::PollEvent;
pub use android_activity::{self, AndroidApp};
use androidwindowadapter::AndroidWindowAdapter;
use core::ops::ControlFlow;
use i_slint_core::api::{EventLoopError, PhysicalSize, PlatformError};
use i_slint_core::api::{EventLoopError, PlatformError};
use i_slint_core::platform::WindowAdapter;
use i_slint_renderer_skia::SkiaRendererExt;
use std::cell::RefCell;
@ -114,15 +114,7 @@ impl i_slint_core::platform::Platform for AndroidPlatform {
return Ok(());
}
if self.window.pending_redraw.take() {
if let Some(win) = self.app.native_window() {
let o = self.window.offset.get();
self.window.renderer.render_transformed_with_post_callback(
0.,
(o.x as f32, o.y as f32),
PhysicalSize { width: win.width() as _, height: win.height() as _ },
None,
)?;
}
self.window.do_render()?;
}
}
}