can hide status bar on iOS (#17179)

# Objective

- I want to hide the clock and the battery indicator on iOS

## Solution

- Add the platform specific property `prefers_status_bar_hidden` on
Window creation, and map it to `with_prefers_status_bar_hidden` in
winit.

## Testing

- Tested on iOS
This commit is contained in:
François Mockers 2025-01-06 20:19:56 +01:00 committed by GitHub
parent 1162e03cec
commit 94b9fe384f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 15 additions and 0 deletions

View File

@ -412,6 +412,16 @@ pub struct Window {
///
/// [`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,
/// Sets whether the Window prefers the status bar hidden.
///
/// Corresponds to [`WindowAttributesExtIOS::with_prefers_status_bar_hidden`].
///
/// # Platform-specific
///
/// - Only used on iOS.
///
/// [`WindowAttributesExtIOS::with_prefers_status_bar_hidden`]: https://docs.rs/winit/latest/x86_64-apple-darwin/winit/platform/ios/trait.WindowAttributesExtIOS.html#tymethod.with_prefers_status_bar_hidden
pub prefers_status_bar_hidden: bool,
}
impl Default for Window {
@ -454,6 +464,7 @@ impl Default for Window {
titlebar_show_title: true,
titlebar_show_buttons: true,
prefers_home_indicator_hidden: false,
prefers_status_bar_hidden: false,
}
}
}

View File

@ -147,6 +147,8 @@ impl WinitWindows {
use winit::platform::ios::WindowAttributesExtIOS;
winit_window_attributes = winit_window_attributes
.with_prefers_home_indicator_hidden(window.prefers_home_indicator_hidden);
winit_window_attributes = winit_window_attributes
.with_prefers_status_bar_hidden(window.prefers_status_bar_hidden);
}
let display_info = DisplayInfo {

View File

@ -30,6 +30,8 @@ fn main() {
recognize_rotation_gesture: true,
// Only has an effect on iOS
prefers_home_indicator_hidden: true,
// Only has an effect on iOS
prefers_status_bar_hidden: true,
..default()
}),
..default()