From db4a74be76fd92500a3e42f64ab654a508303f06 Mon Sep 17 00:00:00 2001 From: Sou1gh0st Date: Fri, 1 Nov 2024 00:09:30 +0800 Subject: [PATCH] Support prefers_home_indicator_hidden (#16005) # Objective - Fixes #15757 ## Solution - Add the platform specific property `prefers_home_indicator_hidden` to bevy's Window configuration, and applying it by invoking `with_prefers_home_indicator_hidden` in `winit`. ## Testing - I have tested the `bevy_mobile_example` on the iOS platform. ## Showcase - Currently, the `prefers_home_indicator_hidden` is enabled in the bevy_mobile_example demo. You can test it with an iOS device. The home indicator will disappear after several seconds of inactivity in the bottom areas. --------- Co-authored-by: Alice Cecile --- crates/bevy_window/src/window.rs | 11 +++++++++++ crates/bevy_winit/src/winit_windows.rs | 7 +++++++ examples/mobile/src/lib.rs | 2 ++ 3 files changed, 20 insertions(+) diff --git a/crates/bevy_window/src/window.rs b/crates/bevy_window/src/window.rs index 7b62b013f2..97e4cf3c3e 100644 --- a/crates/bevy_window/src/window.rs +++ b/crates/bevy_window/src/window.rs @@ -388,6 +388,16 @@ pub struct Window { /// /// [`WindowAttributesExtMacOS::with_titlebar_buttons_hidden`]: https://docs.rs/winit/latest/x86_64-apple-darwin/winit/platform/macos/trait.WindowAttributesExtMacOS.html#tymethod.with_titlebar_buttons_hidden pub titlebar_show_buttons: bool, + /// Sets whether the Window prefers the home indicator hidden. + /// + /// Corresponds to [`WindowAttributesExtIOS::with_prefers_home_indicator_hidden`]. + /// + /// # Platform-specific + /// + /// - Only used on iOS. + /// + /// [`WindowAttributesExtIOS::with_prefers_home_indicator_hidden`]: https://docs.rs/winit/latest/x86_64-apple-darwin/winit/platform/ios/trait.WindowAttributesExtIOS.html#tymethod.with_prefers_home_indicator_hidden + pub prefers_home_indicator_hidden: bool, } impl Default for Window { @@ -429,6 +439,7 @@ impl Default for Window { titlebar_transparent: false, titlebar_show_title: true, titlebar_show_buttons: true, + prefers_home_indicator_hidden: false, } } } diff --git a/crates/bevy_winit/src/winit_windows.rs b/crates/bevy_winit/src/winit_windows.rs index 7023fb211a..c4d76aa084 100644 --- a/crates/bevy_winit/src/winit_windows.rs +++ b/crates/bevy_winit/src/winit_windows.rs @@ -140,6 +140,13 @@ impl WinitWindows { .with_titlebar_buttons_hidden(!window.titlebar_show_buttons); } + #[cfg(target_os = "ios")] + { + use winit::platform::ios::WindowAttributesExtIOS; + winit_window_attributes = winit_window_attributes + .with_prefers_home_indicator_hidden(window.prefers_home_indicator_hidden); + } + let display_info = DisplayInfo { window_physical_resolution: ( window.resolution.physical_width(), diff --git a/examples/mobile/src/lib.rs b/examples/mobile/src/lib.rs index 4756a027b9..d9c1f3c770 100644 --- a/examples/mobile/src/lib.rs +++ b/examples/mobile/src/lib.rs @@ -27,6 +27,8 @@ fn main() { // on iOS, gestures must be enabled. // This doesn't work on Android recognize_rotation_gesture: true, + // Only has an effect on iOS + prefers_home_indicator_hidden: true, ..default() }), ..default()