Skip to content

Instantly share code, notes, and snippets.

@paulhimes
Last active March 9, 2021 02:04
Show Gist options
  • Save paulhimes/bd0fd6229b524552b87b4dba6e0bd9c4 to your computer and use it in GitHub Desktop.
Save paulhimes/bd0fd6229b524552b87b4dba6e0bd9c4 to your computer and use it in GitHub Desktop.
OnLayout Tutorial 06
struct MainView: View {
/// Controls the amount of padding above the scroll view's
/// content.
@State var titleBarHeight: CGFloat = 123
var body: some View {
ScrollView {
HStack {
Spacer()
Text("ScrollView Content")
.multilineTextAlignment(.center)
.foregroundColor(.white)
.background(Color.blue.brightness(0.2))
Spacer()
}
/// Pad the top of the content based on the value
/// of `titleBarHeight`.
.padding(.top, titleBarHeight)
}
.background(Color.blue)
.overlay(
TitleBar()
.background(
/// `proxy` will contain the size of the
/// title bar view.
GeometryReader { proxy in
Color.clear
.onAppear {
/// This updates the height when
/// the view first appears.
titleBarHeight = proxy.size.height
}
}
),
alignment: .top
)
.edgesIgnoringSafeArea(.all)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment