Is it possible to specify a default window size for a 2D window in visionOS? I know this is normally achieved by modifying the WindowGroup
with .defaultSize(width:height:)
, but I get an error that this was not included in "xrOS". I am able to specify .defaultSize(width:height:depth:)
for a volumetric window, but this doesn't have any effect when applied to a 2D one.
VisionOS Set Default Window Size
Same error for me
Having the same issue, did you guys figure anything out?
Reported: FB12507146
You have to define the window style before adding the default size
WindowGroup() {
ContentView()
}.windowStyle(.plain).defaultSize(width: <#T##CGFloat#>, height: <#T##CGFloat#>, depth: <#T##CGFloat#>)
The issue has been partially resolved in the second beta version of visionOS. The defaultSize()
modifier is now functional. However, the startup loading view remains fixed at 2m×1m.
The size of the first window an app presents is defined by the UILaunchPlacementParameters
and PreferredLaunchSize
keys in the Info.plist file.
This size is also used while the app is still loading.
I couldn't find this documented anywhere, so it's possible it will change in the future.
The UILaunchPlacementParameters
approach no longer works in visionOS 1.0 beta 4.
As of visionOS 1.0 beta 4, even though defaultSize
results in a janky resize animation when the app launches, it you force-quit the app by killing it from Terminal and relaunch it from the visionOS home screen ... twice ... then visionOS somehow seems to remember what the window's last runtime default size was and your app's launch window will reflect that size for future runs. This state is lost each time you launch the app from Xcode.
I have no idea if apps have this behavior on the device, or what the behavior will be the first time an app is launched after being installed from the App Store.
None of Apple's system apps, like Safari or Settings, appear to feature the awkward launch window resize animation problem. It would be nice to know what Apple's plan is for visionOS launch window sizes for third party apps.
Till visionOS 1.0 beta 7, there is still no way to set the loading window size.
The following worked for me:
struct MyApp: App {
var body: some SwiftUI.Scene {
WindowGroup {
ContentView()
}
.defaultSize(CGSize(width: 1000, height: 250))
}
}