From 9df2b01f4e0ee9e44350232de60a23713b5ee44f Mon Sep 17 00:00:00 2001 From: Michael Hills Date: Sat, 12 Sep 2020 01:43:38 +1000 Subject: [PATCH] Fix view frame in portrait when starting iOS app in landscape --- CHANGELOG.md | 1 + src/platform_impl/ios/ffi.rs | 2 +- src/platform_impl/ios/view.rs | 13 +++++++++++-- 3 files changed, 13 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e45560f816d..994435564ac 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -32,6 +32,7 @@ - **Breaking:** `primary_monitor` now returns `Option`. - On macOS, updated core-* dependencies and cocoa. - Bump `parking_lot` to 0.11 +- On iOS, fixed starting the app in landscape where the view still had portrait dimensions. # 0.22.2 (2020-05-16) diff --git a/src/platform_impl/ios/ffi.rs b/src/platform_impl/ios/ffi.rs index 071b586795f..f38e82c61d9 100644 --- a/src/platform_impl/ios/ffi.rs +++ b/src/platform_impl/ios/ffi.rs @@ -36,7 +36,7 @@ pub struct CGPoint { } #[repr(C)] -#[derive(Debug, Clone)] +#[derive(Debug, Clone, PartialEq)] pub struct CGSize { pub width: CGFloat, pub height: CGFloat, diff --git a/src/platform_impl/ios/view.rs b/src/platform_impl/ios/view.rs index 5481b8eff54..53e2b6ff8de 100644 --- a/src/platform_impl/ios/view.rs +++ b/src/platform_impl/ios/view.rs @@ -123,17 +123,26 @@ unsafe fn get_view_class(root_view_class: &'static Class) -> &'static Class { let window: id = msg_send![object, window]; assert!(!window.is_null()); - let bounds: CGRect = msg_send![window, bounds]; + let window_bounds: CGRect = msg_send![window, bounds]; let screen: id = msg_send![window, screen]; let screen_space: id = msg_send![screen, coordinateSpace]; let screen_frame: CGRect = - msg_send![object, convertRect:bounds toCoordinateSpace:screen_space]; + msg_send![object, convertRect:window_bounds.clone() toCoordinateSpace:screen_space]; let scale_factor: CGFloat = msg_send![screen, scale]; let size = crate::dpi::LogicalSize { width: screen_frame.size.width as f64, height: screen_frame.size.height as f64, } .to_physical(scale_factor.into()); + + // If the app is started in landscape, the view frame and window bounds can be mismatched. + // The view frame will be in portrait and the window bounds in landscape. So apply the + // window bounds to the view frame to make it consistent. + let view_frame: CGRect = msg_send![object, frame]; + if view_frame.size != window_bounds.size { + let () = msg_send![object, setFrame:window_bounds]; + } + app_state::handle_nonuser_event(EventWrapper::StaticEvent(Event::WindowEvent { window_id: RootWindowId(window.into()), event: WindowEvent::Resized(size),