Skip to content

Commit

Permalink
can hide status bar on iOS (#17179)
Browse files Browse the repository at this point in the history
# 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
  • Loading branch information
mockersf authored Jan 6, 2025
1 parent 1162e03 commit 94b9fe3
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 0 deletions.
11 changes: 11 additions & 0 deletions crates/bevy_window/src/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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,
}
}
}
Expand Down
2 changes: 2 additions & 0 deletions crates/bevy_winit/src/winit_windows.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 2 additions & 0 deletions examples/mobile/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit 94b9fe3

Please sign in to comment.