Horizontal size class of popovers in Catalyst?

175 views Asked by At

If I present a view controller as a popover on iPad (by setting its modalPresentationStyle to .popover), it will report its horizontal size class as .compact. But if I run the same code in a Catalyst app, the view controller in the popover reports a horizontal size class of .regular. Compact is what I expect. Setting overrideTraitCollection on the popoverPresentationController of the view controller before I present it works to make the size class regular on iPad, but it won't make it compact on Catalyst.

How can I make a view controller in a popover correctly report a compact horizontal size class in Catalyst?

2

There are 2 answers

2
Tom Hamming On BEST ANSWER

I asked an Apple engineer this in a WWDC 2021 lab on Catalyst and he said it's a bug. I've filed it as Feedback FB9124431.

1
Wil Shipley On

I would assume the Catalyst authors set the default to .regular on Macs since popovers can be a lot bigger in general.

If you want to override it just on Macs I’d use an #ifdef, eg:

#if targetEnvironment(macCatalyst)
// set ‘overrideTraitCollection’ so it forces '.compact’ on the popover
#endif