[Go to site: main page, start]

SwiftUI Table on iPhone Duo

I am using the Table view in my app. On iPhone it only shows the first column, on iPad and Mac it shows all the columns. Since the Table view does not have an API to determine if the columns are shown, I am using self.horizontalSizeClass == .compact to find out if I need to show all content in the one column.

Since the iPhone Duo is still an iPhone, even if it's unfolded, it only shows the one column, but the horizontalSizeClass is not compact. If we ignore that this all doesn't make any sense (why doesn't the Table just show the columns?!) my question is: how can I handle this case? Currently it just shows the first columns content.

When I hack around and show the same content in the first column as on a "normal" iPhone, it's not helpful:

Thanks for the question, what are you trying to accomplish? Are you using size classes like you're trying to go from one screen to opening the phone?

Can you describe your goal? Does not look like you are using ArrangementView, you are using a Split View in the screenshot.

Your horizontalSizeClass == .compact check is on this device but SwiftUI’s Table behavior is actually tied to a combination of both the User Interface Idiom and the Size Class, not just the size class alone. Take a look at https://developer.apple.com/videos/play/tech-talks/111463/

Do you check if the size class is compact?

Albert  WWDR

Hey Albert,

thank you for your answer.

I am trying to use the SwiftUI Table in my app on iPhone Duo. It works perfectly on iPad showing multiple columns and I would expect to do the same on iPhone Duo.

You are right that I am using Split View in my app and I don't see why that should be an issue or how ArrangmentView should help. It's clear from the linked video that ArrangementView is not the right choice for this UI.

The linked video does not say any word about SwiftUI Table. Are you sure you linked the right video?

Do you check if the size class is compact?

I am not sure if I understand what you mean by this question, as I clearly state that I check for the horizontalSizeClass being compact.

To summarize: I expect the SwiftUI Table to show a "real" table on iPhone Duo when unfolded. But as you can see from the screenshot (that is taken from the iPhone Duo in simulator) that doesn't work as expected.

My question would be: how do we correctly use SwiftUI Table on iPhone Duo? There is no information to be found on that. I think the current behaviour of the Table is a bug.

Best regards, Christian Beer

Thanks for your reply, I need to reproduce it on my end. It does not sound like a bug, sounds like a behavior of Table rather than a bug.

I'll invite engineers from the duo to comment on this thread in case I'm wrong or if they know a better way. I have been wrong before I believe.

The SwiftUI's Table is explicitly designed to collapse into a single-column List whenever the horizontalSizeClass is .compact. Because your app is in Split View on the iPhone Duo, the system assigns a .compact horizontal size class. Since the environment is .compact, Table automatically adapts by dropping the multi-column layout, regardless of the physical screen size of the unfolded device.

If you want to force a multi-column table inside that Split View pane on the iPhone Duo, I suggest you override the environment for that specific view to force it into a regular size class? I believe but need to check on my end and play a little I believe you can do it like .environment(\.horizontalSizeClass, .regular) but I didn’t even try to be honest. But I’ll be happy to take your sample and force it to behave the way you wanted?

If you think this is not the behavior you want for the duo we can work to file an enhancement request.

Albert  WWDR

The iPhone Duo doesn't report horizontalSizeClass == .compact if unfolded. That's one of the points.

So the Table behaves like on iPhone, but it doesn't report the compact horizontalSize class. That's why Table doesn't work at all on iPhone Duo.

Yes, I would love to create a ticket for this.

@chbeer Go ahead and make sure to submit a sample focused sample showing the issue.

Once you open the bug report, please post the FB number here for my reference.

If you have any questions about filing a bug report, take a look at Bug Reporting: How and Why?

Albert  WWDR

SwiftUI Table on iPhone Duo
 
 
Q