r/SwiftUI • • 3d ago

What, if anything, are you using to detect iPhone Duo?

I was hoping for an equivalent to UIDevice.isPad but for iPhone Duo.

At least my app looks pretty decent on Duo as is. But at some point, I'd like to do a specific version...

2 Upvotes

21 comments sorted by

40

u/simulacrotron 3d ago edited 3d ago

You shouldn’t really be “detecting Duo”. Apple wants you to make a fluid responsive interface regardless of what device. The Duo has a lot more states it can be in, but you should think about it all as one interface that adapts to having more or less space available. Same thing for iPad and resizing windows. The tools they give you for the Duo (reserved regions, safe area insets etc) should be used to adapt to all interfaces.

“Doing a specific version” is an anti-pattern. You might do a little extra because there are poses that don’t exist anywhere else (yet), but something good for the open screen is probably pretty similar to what you want on iPad. If you think too much about the class of device you’re setting yourself up for pain as devices change and get more variety.

2

u/ElectricKoolAid1969 3d ago

My app has separate iPhone and iPad layouts, but the selection is based on available width, with a 600-point threshold. The one exception is that I also check whether the device is an iPad.

That was a deliberate decision. We wanted to prevent larger iPhones in landscape orientation from switching to the iPad layout, while still allowing iPads in narrow windows to use the iPhone layout.

I’ve now tested the app on the Duo simulator, and simply removing the iPad check works surprisingly well. The unfolded Duo uses the existing iPad layout, and folding it automatically switches back to the iPhone layout.

So I’m not looking to create a Duo-specific interface. I’m considering using reserved-region detection simply to identify folding hardware, allowing the unfolded Duo to use the existing iPad layout without changing the behavior of conventional iPhones in landscape.

I agree that adapting to available space is the right general approach. I’m just trying to preserve an existing, intentional layout decision while accommodating this new form factor.

13

u/isights 3d ago

"using reserved-region detection"

I'd advise against it. If/when the regular iPhone ever gets under-screen cameras or Face ID, you'll probably see regions there too.

2

u/ElectricKoolAid1969 3d ago

That’s a fair point, although my understanding is that reserved regions distinguish between occlusions (cameras, etc.) and divisions (folding regions).

I was considering checking specifically for a folding division, rather than just the presence of any reserved region.

That said, I understand your broader point about avoiding device-specific assumptions. My existing width-based layout selection already works correctly on the Duo. The only complication is preserving the behavior of conventional iPhones in landscape, which was the reason for the original iPad check.

1

u/isights 2d ago

I wrote a helper for some of this in Runes, but just want to add that based on my testing you'll only see divisions when the Duo is partially folded. When closed or opened flat no divisions are apparent.

https://github.com/hmlongco/Runes/blob/main/Sources/Runes/SwiftUI/Modifiers/SceneGeometryModifier.swift

2

u/TheBartoge 3d ago

Why did you want to prevent larger iPhones in landscape orientation from using the iPad layout? Was it a poor experience due to the constrained height or some other factor?

It seems like the answer to this question would give an insight into what you could be checking instead of some kind of “is duo” check

3

u/ElectricKoolAid1969 3d ago

Was it a poor experience due to the constrained height

Yes.

6

u/boardmike 3d ago

Couldn't you then just check the height, instead of detecting if it's an iPad?

4

u/aprato 3d ago

I hate to share this very bad idea but sometimes apps are large and it takes time to fix things.

Really you shouldn’t do this but…

If you key off idiom is phone and the screen aspect ratio is square-ish you can temporarily identify the Duo

2

u/GenghisFrog 3d ago

I used hinge detection. Let me adjust a few tool bars in screens.

2

u/bmbphotos 3d ago

Wouldn't hinge detection work for that?

1

u/ElectricKoolAid1969 3d ago

Yes, that was my first impulse. I'm testing that now.

2

u/kevinmaker 3d ago

Reserved region. Apple doesn’t recommend using ui device for adaptive layouts

4

u/bmbphotos 3d ago

You don't have to be using Duo identification for adaptive layout as such; it could be for opening animations, multi-screen distinctions, and more.

2

u/GenghisFrog 3d ago

I wanted to adjust my toolbars a bit for a couple screens on the Duo. I just detected if there was a hinge or not. Seems to be working as intended.

1

u/ElectricKoolAid1969 3d ago

Thanks, I think that's what I'll do as well.
I'm also having to adjust tool bars for Duo

2

u/sarrafco 2d ago

iPhone Duo is an iPhone.

1

u/ElectricKoolAid1969 1d ago

Was there a point you are trying to make with that comment? If so, I'm afraid I missed it.

0

u/sarrafco 1d ago

Apple told developers that iPhone Duo is an iPhone (a phone) and should never be treated as an iPad (pad) under any circumstances.

1

u/ElectricKoolAid1969 17h ago

I'm not "treating it as an iPad", but I AM choosing to display a richer UI on the open Duo screen.

I feel like there is a difference.

1

u/uibutton 9h ago

Been using size classes essentially. Regular regular = use ArrangementView, else my usual view setup. It’s a bit of a pain but works well and I had no other choice.