Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Stick to the safe area when rendering test app #1512

Merged
merged 1 commit into from
Sep 26, 2023

Conversation

JakeWharton
Copy link
Collaborator

Did I do any of this right? It looks right...

Screenshot 2023-09-25 at 4 32 18 PM

@JakeWharton JakeWharton marked this pull request as ready for review September 25, 2023 20:39
tv.translatesAutoresizingMaskIntoConstraints = false

self.view.addSubview(tv)
let safeGuide = self.view.safeAreaLayoutGuide
Copy link
Collaborator

@dnagler dnagler Sep 25, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think instead of all of this, you could maybe just do

tv.bounds = view.safeAreaLayoutGuide.layoutFrame

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh sweet. Will try.

Copy link
Collaborator

@dnagler dnagler Sep 25, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If this works, it's worth pointing out that it's a bit backwards/unconventional--a UIView's bounds rect is expressed relative to the view's own coordinate system, whereas its frame rect is expressed relative to its superview's coordinate system. It's more typical to declare mySubview.frame = mySuperview.bounds, to get mySubview to fill mySuperview's rect.

In this case, view.safeAreaLayoutGuide.layoutFrame is expressed view's coordinate system, not tv's.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like they're not exactly in the same coordinate system and the bound origin or something gets skewed by half the height/width. Even when I fix it (or try to) it occupies the whole screen still rather than only the safe area.

Screenshot 2023-09-25 at 8 14 55 PM

Copy link
Collaborator Author

@JakeWharton JakeWharton Sep 26, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Going to merge as-is. Hopefully soon we'll have a scaffolding-like composable in this app which gets us a traditional top/nav bar on Android and iOS (and will allow drawing edge-to-edge again).

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good to know--it was worth a shot. Definitely safe to merge as is!

@JakeWharton JakeWharton enabled auto-merge (squash) September 26, 2023 00:25
@JakeWharton JakeWharton merged commit 8d0a960 into trunk Sep 26, 2023
@JakeWharton JakeWharton deleted the jw.safe-area.2023-09-25 branch September 26, 2023 00:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants