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
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions test-app/ios-uikit/TestApp/TestAppViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,7 @@ class TestAppViewController : UIViewController {
super.viewDidLoad()

view.backgroundColor = .white
}

override func loadView() {
let testAppLauncher = TestAppLauncher(nsurlSession: urlSession, hostApi: IosHostApi())
let treehouseApp = testAppLauncher.createTreehouseApp()
let widgetSystem = TestSchemaWidgetSystem()
Expand All @@ -42,7 +40,15 @@ class TestAppViewController : UIViewController {
codeListener: CodeListener()
)
ExposedKt.bindWhenReady(content: content, view: treehouseView)
view = treehouseView.view

let tv = treehouseView.view
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!

tv.heightAnchor.constraint(equalTo: safeGuide.heightAnchor).isActive = true
tv.widthAnchor.constraint(equalTo: safeGuide.widthAnchor).isActive = true
tv.topAnchor.constraint(equalTo: safeGuide.topAnchor).isActive = true
}
}

Expand Down