Skip to content
Merged
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

## Next

- Add SwiftUI extension `View+FrameSize` ([#153](https://github.com/AckeeCZ/ACKategories/pull/153), kudos to @lukashromadnik)
- Add `readSize` and `readFrame` to SwiftUI views ([#150](https://github.com/AckeeCZ/ACKategories/pull/150), kudos to @olejnjak)
- Add `WithLayoutMargins` to SwiftUI extensions ([#150](https://github.com/AckeeCZ/ACKategories/pull/151), kudos to @komkovla)

Expand Down
17 changes: 17 additions & 0 deletions Sources/ACKategories/SwiftUIExtensions/View+FrameSize.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import SwiftUI

@available(iOS 13, macOS 10.15, tvOS 13.0, watchOS 6.0, *)
extension View {

public func frame(size: CGSize) -> some View {
assert(size.width.isFinite)
assert(size.width >= 0)
assert(size.height.isFinite)
assert(size.height >= 0)
return frame(width: size.width, height: size.height)
}

public func frame(size: CGSize, alignment: Alignment) -> some View {
frame(width: size.width, height: size.height, alignment: alignment)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also we have some asserts in the variant without alignment, so we should rather be consistent and have in both variants or omit it.

}
}