Skip to content

Commit

Permalink
[SwiftUI] Add automatic sizing option for UIKit in SwiftUI (#113)
Browse files Browse the repository at this point in the history
* Added automatic sizing for SwiftUI measured views

* Improve automatic sizing behavior

* Add changelog.md entry

* Cleanup

* Address comments

Co-authored-by: Bryn Bodayle <[email protected]>
  • Loading branch information
erichoracek and brynbodayle authored Jul 28, 2022
1 parent 9b9b1d3 commit 5233d20
Show file tree
Hide file tree
Showing 4 changed files with 206 additions and 55 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Updated to have Swift 5.4 as the minimum supported Swift version (previously Swift 5.3).
- Updated `HGroupView` and `VGroupView` to have `insetsLayoutMarginsFromSafeArea = false` by default
- Gated an old autoresizing-mask-related bug workaround to only run on iOS versions 13 and below
- The `swiftUIView(…)` methods now default to an automatic sizing behavior that makes a best effort
at sizing the view based on heuristics, rather than defaulting to intrinsic height and proposed
width.

## [0.7.0](https://github.com/airbnb/epoxy-ios/compare/0.6.0...0.7.0) - 2021-12-09

Expand Down
14 changes: 7 additions & 7 deletions Sources/EpoxyCore/SwiftUI/EpoxyableView+SwiftUIView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ extension StyledView
/// ```
/// MyView.swiftUIView(…).sizing(.intrinsicSize)
/// ```
/// The sizing defaults to `.intrinsicHeightProposedWidth`.
/// The sizing defaults to `.automatic`.
public static func swiftUIView(
style: Style,
behaviors: Behaviors? = nil)
Expand Down Expand Up @@ -115,10 +115,10 @@ extension StyledView
/// ```
/// MyView.swiftUIView(…).sizing(.intrinsicSize)
/// ```
/// The sizing defaults to `.intrinsicHeightProposedWidth`.
/// The sizing defaults to `.automatic`.
public static func swiftUIView(
behaviors: Behaviors? = nil,
sizing: SwiftUIMeasurementContainerStrategy = .intrinsicHeightProposedWidth)
sizing: SwiftUIMeasurementContainerStrategy = .automatic)
-> SwiftUIStylelessContentlessEpoxyableView<Self>
{
.init(behaviors: behaviors, sizing: sizing)
Expand All @@ -135,7 +135,7 @@ public struct SwiftUIEpoxyableView<View>: MeasuringUIViewRepresentable, UIViewCo
var content: View.Content
var style: View.Style
var behaviors: View.Behaviors?
public var sizing = SwiftUIMeasurementContainerStrategy.intrinsicHeightProposedWidth
public var sizing = SwiftUIMeasurementContainerStrategy.automatic
public var configurations: [(View) -> Void] = []

public func updateUIView(_ wrapper: SwiftUIMeasurementContainer<Self, View>, context: Context) {
Expand Down Expand Up @@ -189,7 +189,7 @@ public struct SwiftUIStylelessEpoxyableView<View>: MeasuringUIViewRepresentable,
{
var content: View.Content
var behaviors: View.Behaviors?
public var sizing = SwiftUIMeasurementContainerStrategy.intrinsicHeightProposedWidth
public var sizing = SwiftUIMeasurementContainerStrategy.automatic
public var configurations: [(View) -> Void] = []

public func updateUIView(_ wrapper: SwiftUIMeasurementContainer<Self, View>, context: Context) {
Expand Down Expand Up @@ -234,7 +234,7 @@ public struct SwiftUIContentlessEpoxyableView<View>: MeasuringUIViewRepresentabl
{
var style: View.Style
var behaviors: View.Behaviors?
public var sizing = SwiftUIMeasurementContainerStrategy.intrinsicHeightProposedWidth
public var sizing = SwiftUIMeasurementContainerStrategy.automatic
public var configurations: [(View) -> Void] = []

public func updateUIView(_ wrapper: SwiftUIMeasurementContainer<Self, View>, context _: Context) {
Expand Down Expand Up @@ -278,7 +278,7 @@ public struct SwiftUIStylelessContentlessEpoxyableView<View>: MeasuringUIViewRep
{
public var configurations: [(View) -> Void] = []
var behaviors: View.Behaviors?
public var sizing = SwiftUIMeasurementContainerStrategy.intrinsicHeightProposedWidth
public var sizing = SwiftUIMeasurementContainerStrategy.automatic

public func updateUIView(_ wrapper: SwiftUIMeasurementContainer<Self, View>, context _: Context) {
wrapper.view = self
Expand Down
Loading

0 comments on commit 5233d20

Please sign in to comment.