Skip to content

Instantly share code, notes, and snippets.

@paulhimes
paulhimes / OnLayout Tutorial 11.swift
Created March 9, 2021 02:01
OnLayout Tutorial 11
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()
@paulhimes
paulhimes / OnLayout Tutorial 10.swift
Created March 9, 2021 01:59
OnLayout Tutorial 10
struct LayoutActionModifier: ViewModifier {
/// This action is run after each time the view changes.
let action: ((GeometryProxy) -> Void)?
func body(content: Content) -> some View {
content
.background(
GeometryReader { proxy in
layoutWatcher(proxy)
@paulhimes
paulhimes / OnLayout Tutorial 09.swift
Last active March 9, 2021 02:23
OnLayout Tutorial 09
func layoutWatcher(_ proxy: GeometryProxy) -> some View {
/// This updates the height after each time the view
/// is updated.
DispatchQueue.main.async {
titleBarHeight = proxy.size.height
}
return Color.clear
.onAppear {
/// This updates the height when the view first
/// appears.
@paulhimes
paulhimes / OnLayout Tutorial 08.swift
Last active March 9, 2021 02:05
OnLayout Tutorial 08
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()
@paulhimes
paulhimes / OnLayout Tutorial 07.swift
Last active March 9, 2021 02:04
OnLayout Tutorial 07
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()
@paulhimes
paulhimes / OnLayout Tutorial 06.swift
Last active March 9, 2021 02:04
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()
@paulhimes
paulhimes / OnLayout Tutorial 05.swift
Last active March 9, 2021 02:04
OnLayout Tutorial 05
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()
@paulhimes
paulhimes / OnLayout Tutorial 04.swift
Last active March 9, 2021 02:03
OnLayout Tutorial 04
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()
@paulhimes
paulhimes / OnLayout Tutorial 03.swift
Last active March 9, 2021 02:03
OnLayout Tutorial 03
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()
@paulhimes
paulhimes / OnLayout Tutorial 02.swift
Last active March 9, 2021 02:03
OnLayout Tutorial 02
struct MainView: View {
var body: some View {
ScrollView {
HStack {
Spacer()
Text("ScrollView Content")
.multilineTextAlignment(.center)
.foregroundColor(.white)
.background(Color.blue.brightness(0.2))
Spacer()