bevyengine / bevyengine/bevy

Use raw_window_handle from Bevy

Open
#10,006 1 comment 0 reactions 0 assignees View on GitHub
A-Windowing C-Feature
Dominant language
Rust
Stars
48.2k
Forks
4.8k
Avg merge
3d 16h
Merged PRs (30d)
171

Description

Having this implementation of a UIViewController which is loading and showing an ad in full screen.

```
@interface ViewController : UIViewController
@property(nonatomic, strong) GADInterstitialAd *interstitial;
@end

@implementation ViewController

- (void)viewDidLoad {
[super viewDidLoad];

GADRequest *request = [GADRequest request];
[GADInterstitialAd loadWithAdUnitID:@"APP_ID"
request:request
completionHandler:^(GADInterstitialAd *ad, NSError *error) {
if (error) {
NSLog(@"Failed to load interstitial ad with error: %@", [error localizedDescription]);
return;
}
NSLog(@"Interstitial initialised");
self.interstitial = ad;
self.interstitial.fullScreenContentDelegate = self;
[self.interstitial presentFromRootViewController:self];
}];
}

```
I need to use the UIWindow from winit to being able to present this UIViewController until is closed

```
ViewController *mainViewController = [[ViewController alloc] init];
window.rootViewController = mainViewController;
[window makeKeyAndVisible];
```

where window is the UIWindow obtain from winit

Once the add is closed in the callback I can set the old UIViewController that I had created initially by winit.

```
- (void)adDidDismissFullScreenContent:(GADInterstitialAd *)ad {
NSLog(@"Interstitial was dismissed.");
window.rootViewController = oldWinitViewController;
}
```

Currently, my challenge stems from my lack of knowledge about winit, and I'm uncertain if pursuing this direction is practical.

Any practical example of documentation how to obtain the `UIWindow` and `UIViewController` created by winit?

So far checking raw-window-handler I implement this code in bevy

```
let entity = window_query.single();
let raw_window:&winit::window::Window = windows.get_window(entity).unwrap();
unsafe {
let handler = raw_window.raw_window_handle();
match handler {
RawWindowHandle::UiKit(ios_handler) => {
/// Logic here
}
_=>()
}
};
```

But for some reason I cannot understand, even those classes are in the project because are imported, my` winit::window::Window` it cannot find `raw_window_handle` in compilation time, even the IDE can. The same happens with
`UiKit` enum type, it cannot resolve it.

I don't know if there is any limit scope from Bevy or what happens there.

Regards

Contributor guide

Open the contributing guide

Research direction

Start with Bevy's window_query entry point and the winit raw_window_handle call, then inspect how the UiKit handle relates to the UIWindow and UIViewController described in the issue. Confirm whether the documented path resolves raw_window_handle and UiKit, and provide a practical example or clarify the limitation.

Written by the indexing model from the issue text.

Assessment

Tech stack
ios, rust
Domain
game-dev, mobile-dev
Issue type
Documentation
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.