Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ or

```toml
# always pin to the same exact version you also of the Swift package
bevy_ios_safearea = { version = "=0.3.0" }
bevy_ios_safearea = { version = "=0.4.0" }
```

### 3. Setup Plugin in Bevy
Expand Down Expand Up @@ -81,7 +81,8 @@ fn bevy_system(safe_area: IosSafeArea) {

|bevy|crate|
|----|---|
|0.16|0.3,main|
|0.17|0.4,main|
|0.16|0.3|
|0.15|0.1,0.2|

# License
Expand Down
5 changes: 2 additions & 3 deletions bevy_ios_safearea/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "bevy_ios_safearea"
version = "0.3.0"
version = "0.4.0"
edition = "2024"
license = "MIT"
authors = ["extrawurst <mail@rusticorn.com>"]
Expand All @@ -19,13 +19,12 @@ targets = [
]

[dependencies]
bevy = { version = "0.16", default-features = false, features = [
bevy = { version = "0.17", default-features = false, features = [
"bevy_window",
"bevy_winit",
"bevy_log",
] }
winit = { version = "0.30", default-features = false, features = ["rwh_06"] }


[lints.rust]
missing_docs = "warn"
46 changes: 24 additions & 22 deletions bevy_ios_safearea/src/plugin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ impl Plugin for IosSafeAreaPlugin {

#[cfg(target_os = "ios")]
fn init(
windows: NonSend<bevy::winit::WinitWindows>,
_non_send_marker: bevy::ecs::system::NonSendMarker,
window: Single<Entity, With<bevy::window::PrimaryWindow>>,
mut commands: Commands,
) {
Expand All @@ -93,30 +93,32 @@ fn init(

tracing::debug!("safe area updating");

let raw_window = windows.get_window(*window).expect("invalid window handle");
if let Ok(handle) = raw_window.window_handle() {
if let winit::raw_window_handle::RawWindowHandle::UiKit(handle) = handle.as_raw() {
let ui_view: *mut std::ffi::c_void = handle.ui_view.as_ptr();
bevy::winit::WINIT_WINDOWS.with_borrow(|windows| {
let raw_window = windows.get_window(*window).expect("invalid window handle");
if let Ok(handle) = raw_window.window_handle() {
if let winit::raw_window_handle::RawWindowHandle::UiKit(handle) = handle.as_raw() {
let ui_view: *mut std::ffi::c_void = handle.ui_view.as_ptr();

let (top, bottom, left, right) = unsafe {
(
crate::native::swift_safearea_top(ui_view),
crate::native::swift_safearea_bottom(ui_view),
crate::native::swift_safearea_left(ui_view),
crate::native::swift_safearea_right(ui_view),
)
};
let (top, bottom, left, right) = unsafe {
(
crate::native::swift_safearea_top(ui_view),
crate::native::swift_safearea_bottom(ui_view),
crate::native::swift_safearea_left(ui_view),
crate::native::swift_safearea_right(ui_view),
)
};

let safe_area = IosSafeAreaResource {
top,
bottom,
left,
right,
};
let safe_area = IosSafeAreaResource {
top,
bottom,
left,
right,
};

tracing::debug!("safe area updated: {:?}", safe_area);
tracing::debug!("safe area updated: {:?}", safe_area);

commands.insert_resource(safe_area);
commands.insert_resource(safe_area);
}
}
}
});
}