From aca30bfe6a12cee47b18511bc210ebd3cd0a1e5b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9C=D0=B8=D1=85=D0=B0=D0=B8=D0=BB=20=D0=9A=D0=B0=D0=BF?= =?UTF-8?q?=D0=B5=D0=BB=D1=8C=D0=BA=D0=BE?= Date: Thu, 22 Oct 2026 15:55:54 +0300 Subject: [PATCH] some --- components/render/ios/RenderIOS.swift | 47 +++++++++++++++++++-------- 1 file changed, 33 insertions(+), 14 deletions(-) diff --git a/components/render/ios/RenderIOS.swift b/components/render/ios/RenderIOS.swift index 0344012..cd7a7f9 100644 --- a/components/render/ios/RenderIOS.swift +++ b/components/render/ios/RenderIOS.swift @@ -2,10 +2,17 @@ import SwiftUI import UIKit // The prebuilt raylib iOS framework owns the app entry point (main()/ -// AppDelegate/SceneDelegate in rcore_ios.c), so our SwiftUI @main shell is -// not used on iOS. Instead the C bridge calls rcios_present_overlay() from -// ios_ready(), and we stack a transparent window hosting ChkgfxView above -// raylib's window. +// AppDelegate/SceneDelegate in rcore_ios.c). Its SceneDelegate creates the +// window, installs GameViewController as the root and only then calls +// ios_ready(), so by the time rcios_present_overlay() runs there is already a +// key window with a GL-backed root view. +// +// We deliberately do NOT create a second UIWindow: that would sit at a fixed +// windowLevel and break alerts/buttons later. Instead we add the SwiftUI +// content as a child UIViewController of raylib's root view controller, so: +// - buttons receive touches through the normal responder chain; +// - .alert / sheets present correctly in the same window; +// - rotation and geometry changes apply to both layers at once. // // ChkgfxComponent/ChkgfxVM live here because the component lifecycle is // otherwise driven by the (iOS-unavailable) SwiftUI app shell. @@ -32,24 +39,36 @@ public func rciosPresentOverlay() { .compactMap({ $0 as? UIWindowScene }).first else { return } + // raylib's SceneDelegate made its window key before calling ios_ready(). + guard let window = scene.windows.first(where: { $0.isKeyWindow }) + ?? scene.windows.first, + let host = window.rootViewController + else { return } + let root = ChkgfxView(RenderIOS.chkgfxVM) .frame(maxWidth: .infinity, maxHeight: .infinity, alignment: .top) let hosting = UIHostingController(rootView: root) hosting.view.backgroundColor = .clear + // The UI is a passive title for now. Once it gains buttons, drop this + // line; touches will then stay in the SwiftUI layer over the whole + // screen instead of reaching raylib's GameViewController. + hosting.view.isUserInteractionEnabled = false - let overlay = UIWindow(windowScene: scene) - overlay.rootViewController = hosting - overlay.backgroundColor = .clear - overlay.windowLevel = .alert + 1 - overlay.isUserInteractionEnabled = false - overlay.isHidden = false + host.addChild(hosting) + hosting.view.frame = host.view.bounds + hosting.view.autoresizingMask = [.flexibleWidth, .flexibleHeight] + host.view.addSubview(hosting.view) + hosting.didMove(toParent: host) - OverlayWindow.retained = overlay + // addChild retains the hosting controller for as long as it stays + // attached, so no extra strong reference is needed here. + OverlayHost.retained = hosting } } -// UIWindow is not retained by UIKit once we drop our reference, so hold it. -private enum OverlayWindow { - static var retained: UIWindow? +// Optional handle for later use (e.g. presenting an alert from the hosting +// controller). The parent view controller keeps it alive while attached. +private enum OverlayHost { + static weak var retained: UIViewController? }