Skip to content

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

Open

Description

@MartinZikmund

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

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).
  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.

Activity

  1. added
    kind/enhancement
    platform/ios 🍎
    area/skia ✏️
    on Sep 29, 2026
  2. MartinZikmund commented on Sep 29, 2026

    @MartinZikmund
    MemberAuthor

    Depends on #20027 (AppInstance activation)

    Build this on top of #20027. It is still a draft and rewrites the same UnoUISceneDelegate.WillConnect. Here's what it already provides and what this redesign still has to do:

    Already in #20027

    • WillConnect calls ReportConnectionActivation(connectionOptions) before window binding. URL contexts, shortcut items and universal links are reported to AppInstance (startup activation first, then SetOrRaiseActivation with Running).
    • OpenUrlContexts, ContinueUserActivity and windowScene:performActionForShortcutItem: are reported the same way. AppleUIKitActivation is shared by the app delegate and the scene delegate.

    Still needed here

    1. Scenes the user opens from iOS go through AppInstance.Activated, never a second OnLaunched. That keeps it non-breaking: apps that don't subscribe get today's behavior (the scene is destroyed).
    2. Plain new scenes raise an activation too. A scene with no URL, shortcut or activity (iPad "New Window", split-view drag) currently only calls MarkStartupActivationSettled() and is then destroyed. After startup, report it as a Launch activation.
    3. Bind a window created during the activation to the scene that caused it. If an Activated handler synchronously creates a Window, CreateWindow currently requests another scene. The connecting scene only ends up bound because the "oldest pending" fallback in TryTake(null) takes that window (and the extra scene is destroyed when it arrives). Removing the fallback breaks this. The binder must track "the scene currently being activated" and bind a newly created window to it, without sending a new scene request.
    4. DidDiscardSceneSessions: follow the UnoUISceneDelegate pattern. Seal the UIKit override in UnoUIApplicationDelegate and expose a protected On… hook, so an app subclass can't silently skip closing the window. Sealing breaks existing overrides, so do it before the scene support ships in a stable release.

    Breaking-change assessment

    The scene support (#19082) hasn't shipped in any release branch or tag yet. If this lands before it does, nothing breaks for users. If it ships first, these are the behavior changes to list in the release notes:

    • Window.Closed is no longer raised when iOS disconnects a scene. It's raised when the session is discarded or when the app calls Close().
    • OnSceneDisconnected can be followed by another OnSceneConnected for the same window. Update the XML docs.
    • IsVisible becomes true at Activate() rather than when the scene connects.
  3. added
    7.1
    on Oct 14, 2026
  4. removed
    7.1
    on Oct 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

area/skia ✏️kind/enhancementplatform/ios 🍎

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions