#24814·uno

[iOS] Redesign scene/window binding: eager UIWindow, two-way SceneBinder, session-keyed rebind

Author: MartinZikmundCreated Sep 29, 2026Updated Sep 29, 2026
Labelskind/enhancementplatform/ios 🍎area/skia ✏️

What would you like to be added?

Replace the "pending window" design of the iOS scene lifecycle (#19082) with a two-way scene ↔ window binder, an eagerly created UIWindow, and bindings keyed by UISceneSession.PersistentIdentifier. This fixes #24812 and #24813 and removes most of the current pending-state handling.

Current design (for context)

Piece File Role
SceneWindowRegistry src/Uno.UI.Runtime.Skia.AppleUIKit/UI/Xaml/Window/SceneWindowRegistry.cs List of (guid, wrapper) windows waiting for a scene; TryTake falls back to the oldest pending window
NativeWindowFactoryExtension .../UI/Xaml/Window/NativeWindowFactoryExtension.cs Registers every scene-backed wrapper; for secondary windows, sends a scene request carrying an NSUserActivity with the GUID
UnoUISceneDelegate src/Uno.UI.Runtime.Skia.AppleUIKit/UnoUISceneDelegate.cs WillConnect takes a pending wrapper, or destroys the session; DidDisconnect closes the window
NativeWindowWrapper .../UI/Xaml/Window/AppleUIKitWindowWrapper.cs _nativeWindow is null until the scene connects, hence _isPendingShow/_pendingShowActivate, placeholder Bounds, _requiresScene branches
UnoUIApplicationDelegate src/Uno.UI.Runtime.Skia.AppleUIKit/UnoUIApplicationDelegate.cs No DidDiscardSceneSessions override

Problems: only the window side can wait (#24812), disconnect is treated as close (#24813), the launch scene is matched only through the fallback, scenes the app didn't request are always discarded, and the wrapper has to handle a null native window throughout.

Proposed design

1. Eager UIWindow, attached to the scene later

UIWindow.windowScene is settable (iOS 13+). The wrapper constructor always creates AppleUIKitWindow (the same path the non-scene lifecycle uses today). Binding becomes nativeWindow.WindowScene = windowScene.

  • _nativeWindow is never null, so _isPendingShow, _pendingShowActivate, the placeholder Bounds and the _requiresScene branch in the constructor can be deleted.
  • Show() no longer needs an override. IsVisible turning true slightly before anything is on screen matches other Skia desktop hosts.
  • Check that FrameChanged/RaiseNativeSizeChanged fires when the scene is attached, so the first real size is reported, and that TryCreateExtendedSplashScreen/MakeKeyAndVisible on a window with no scene is harmless.
  • ALC-hosted windows (Window.ContentHostOverride) stay as they are: they never bind to a scene.

2. Two-way SceneBinder (replaces SceneWindowRegistry)

Two collections, both on the UI thread: unbound windows (GUID → wrapper) and unbound scenes (UIWindowScenes that connected with no window to claim them).

Event Action
Scene connects with an Uno GUID Bind it to that window
Scene connects whose session is already known (reconnect) Bind it to the window for that PersistentIdentifier (see 3)
Launch scene (first connect, no GUID) Bind it to Window.InitialWindow if that exists, otherwise hold the scene until the initial window registers
Scene the app didn't request, after launch (iPad "New Window", split-view drag, extra restored sessions) Raise an activation through the AppInstance route so the app can create a Window, and hold the scene for it. Destroy it only if no window claims it (see open questions)
Window created If it's the initial window and a launch scene is held, bind now. Secondary windows send a scene request with their GUID, as today
Scene request fails Remove the window from the unbound set (as today)

Remove the "oldest pending window" fallback entirely: every case above is matched explicitly.

3. Bindings keyed by the session, and disconnect ≠ close

  • After the first bind, map session.PersistentIdentifier → wrapper.
  • DidDisconnect: detach only. Stop rendering, clear WindowScene, report IsVisible = false/background. Don't close the XAML Window.
  • Reconnect of the same session: rebind the same wrapper and resume rendering.
  • UnoUIApplicationDelegate.DidDiscardSceneSessions (new override): close the matching windows (uncancellable, as _isSceneDisconnected handles today).
  • Window.Close() from the app: RequestSceneSessionDestruction as today, and remove the session mapping.

Expected result

  • The pending state in the wrapper (_isPendingShow and friends) goes away, and SceneWindowRegistry becomes a small binder with no fallback guesswork.
  • An app whose OnLaunched awaits before creating its window works (#24812).
  • Backgrounded windows survive memory reclamation (#24813).
  • The app can respond to scenes the user opens from the OS instead of silently losing them.

Why is this needed?

The current design is fragile in exactly the scenarios iPad multi-window users hit: an async startup, backgrounding, the app switcher and "New Window". See #24812 and #24813. It also leaves the rest of the wrapper handling a native window that may be null.

Renderer

  • Skia
  • Native

For which platforms ️

iOS (tvOS shares the code; confirm it still compiles and behaves with SupportsMultipleScenes == false)

Anything else we need to know?

Implementation plan (for whoever picks this up on a Mac)

Test-first where possible. Fix and test go in separate commits.

  1. Reproduce the two bugs in SamplesApp on the iPad simulator (the scene manifest is already enabled in src/SamplesApp/SamplesApp/Platforms/iOS/Info.plist).
    • #24812: temporarily add await Task.Delay(100) before window creation in the SamplesApp OnLaunched.
    • #24813: open a secondary window, background it, simulate a memory warning or force a disconnect, then return from the app switcher.
    • Record whether the suspected behavior really happens before changing anything.
  2. Eager UIWindow (section 1) with no change to binding yet. Check that the initial window and secondary windows still show and size correctly, including rotation, split view and Stage Manager resizing.
  3. SceneBinder (section 2): launch-scene holding and removing the fallback first, then routing scenes the app didn't request through the activation path.
  4. Session keying + DidDiscardSceneSessions (section 3).
  5. Tests
    • Unit-test SceneBinder as a pure state machine. Keep UIKit types behind a thin seam, so both arrival orders, reconnects, discards and failed requests can be covered without a device.
    • Runtime tests under src/Uno.UI.RuntimeTests for secondary window open/close on the iOS leg, where the environment allows.
  6. Manual matrix (iPad simulator, iOS 17+ and the minimum supported iOS for the RequestSceneSessionActivation path): cold launch, async OnLaunched, open/close secondary window, app-switcher close, background + memory warning + return, "New Window" from the app switcher/Dock, relaunch with restored sessions, iPhone (single scene) unaffected, and an app without a scene manifest unaffected.

Open questions

  • What activation should a scene the app didn't request raise (Launch with the same args, or a new kind via AppInstance)? And what should happen when the app ignores it: destroy the scene, and when?
  • Should stateRestorationActivity store the Uno GUID so restored sessions can be matched back to a window the app recreates on relaunch?
  • InputPane is shared across windows (every window's keyboard observers update InputPane.GetForCurrentView()). Decide whether to make it per-scene as part of this or leave it for later.

Related: #19082 (original SceneDelegate support), #8341 (multi-window epic), #24812, #24813.