-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b71236b
commit 095344c
Showing
1 changed file
with
26 additions
and
0 deletions.
There are no files selected for viewing
26 changes: 26 additions & 0 deletions
26
Sources/Turbocharger/Sources/ViewModifier/ProposedSizeObserver.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
// | ||
// Copyright (c) Nathan Tannar | ||
// | ||
|
||
import SwiftUI | ||
|
||
@available(iOS 14.0, macOS 11.0, tvOS 14.0, watchOS 7.0, *) | ||
public struct ProposedSizeObserver: ViewModifier { | ||
@Binding var size: ProposedSize | ||
|
||
public init(size: Binding<ProposedSize>) { | ||
self._size = size | ||
} | ||
|
||
public func body(content: Content) -> some View { | ||
content | ||
.background( | ||
GeometryReader { proxy in | ||
Color.clear | ||
.hidden() | ||
.onAppearAndChange(of: proxy.size) { size = ProposedSize(size: $0) } | ||
.onDisappear { size = .unspecified } | ||
} | ||
) | ||
} | ||
} |