-
Notifications
You must be signed in to change notification settings - Fork 13
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
Showing
6 changed files
with
33 additions
and
12 deletions.
There are no files selected for viewing
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
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
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
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
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
21 changes: 21 additions & 0 deletions
21
Sources/ACKategories/SwiftUIExtensions/View+ReadSize.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,21 @@ | ||
import SwiftUI | ||
|
||
@available(iOS 13.0, macOS 10.15, watchOS 6.0, tvOS 13.0, *) | ||
public extension View { | ||
func readSize( | ||
onChange: @escaping (CGSize) -> Void | ||
) -> some View { | ||
background( | ||
GeometryReader { geometryProxy in | ||
Color.clear | ||
.preference(key: SizePreferenceKey.self, value: geometryProxy.size) | ||
} | ||
) | ||
.onPreferenceChange(SizePreferenceKey.self, perform: onChange) | ||
} | ||
} | ||
|
||
private struct SizePreferenceKey: PreferenceKey { | ||
static var defaultValue: CGSize = .zero | ||
static func reduce(value: inout CGSize, nextValue: () -> CGSize) { } | ||
} |