Skip to content

Commit

Permalink
Partial Revert "Refine UIKit to SwiftUI Measurement Strategies (#162)" (
Browse files Browse the repository at this point in the history
#164)

This reverts commit fb869c4.
  • Loading branch information
brynbodayle committed Mar 14, 2024
1 parent fb869c4 commit 06d9405
Show file tree
Hide file tree
Showing 4 changed files with 104 additions and 174 deletions.
2 changes: 0 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
approach to resolve an issue that could cause collection view cells to layout with
unexpected dimensions
- Made new layout-based SwiftUI cell rendering option the default.
- Fixed an issue where a UIKit view bridged to SwiftUI that wraps would always take up the proposed
size instead of its intrinsic width.

## [0.10.0](https://github.com/airbnb/epoxy-ios/compare/0.9.0...0.10.0) - 2023-06-29

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ extension SwiftUIMeasurementContainerStrategy: Identifiable, CaseIterable {
public static var allCases: [SwiftUIMeasurementContainerStrategy] = [
.automatic,
.proposed,
.intrinsicHeightProposedOrIntrinsicWidth,
.intrinsicHeightProposedWidth,
.intrinsicWidthProposedHeight,
.intrinsic,
Expand All @@ -82,8 +81,6 @@ extension SwiftUIMeasurementContainerStrategy: Identifiable, CaseIterable {
return "Automatic"
case .proposed:
return "Proposed"
case .intrinsicHeightProposedOrIntrinsicWidth:
return "Intrinsic Height, Proposed Width or Intrinsic Width"
case .intrinsicHeightProposedWidth:
return "Intrinsic Height, Proposed Width"
case .intrinsicWidthProposedHeight:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,16 +56,13 @@ extension MeasuringViewRepresentable {

// Creates a `CGSize` by replacing `nil`s with `UIView.noIntrinsicMetric`
uiView.proposedSize = .init(
width: (
children.first { $0.label == "width" }?
.value as? CGFloat ?? ViewType.noIntrinsicMetric).constraintSafeValue,
height: (
children.first { $0.label == "height" }?
.value as? CGFloat ?? ViewType.noIntrinsicMetric).constraintSafeValue)
width: children.first { $0.label == "width" }?.value as? CGFloat ?? ViewType.noIntrinsicMetric,
height: children.first { $0.label == "height" }?.value as? CGFloat ?? ViewType.noIntrinsicMetric)

size = uiView.measuredFittingSize
}

#if swift(>=5.7.1) // Proxy check for being built with the iOS 15 SDK
#if swift(>=5.7) // Proxy check for being built with the iOS 15 SDK
@available(iOS 16.0, tvOS 16.0, macOS 13.0, *)
public func sizeThatFits(
_ proposal: ProposedViewSize,
Expand All @@ -74,7 +71,12 @@ extension MeasuringViewRepresentable {
-> CGSize?
{
uiView.strategy = sizing
uiView.proposedSize = proposal.viewTypeValue

// Creates a size by replacing `nil`s with `UIView.noIntrinsicMetric`
uiView.proposedSize = .init(
width: proposal.width ?? ViewType.noIntrinsicMetric,
height: proposal.height ?? ViewType.noIntrinsicMetric)

return uiView.measuredFittingSize
}
#endif
Expand All @@ -89,14 +91,14 @@ extension MeasuringViewRepresentable {
nsView: NSViewType)
{
nsView.strategy = sizing

let children = Mirror(reflecting: proposedSize).children

// Creates a `CGSize` by replacing `nil`s with `UIView.noIntrinsicMetric`
nsView.proposedSize = .init(
width: (
children.first { $0.label == "width" }?
.value as? CGFloat ?? ViewType.noIntrinsicMetric).constraintSafeValue,
height: (
children.first { $0.label == "height" }?
.value as? CGFloat ?? ViewType.noIntrinsicMetric).constraintSafeValue)
width: children.first { $0.label == "width" }?.value as? CGFloat ?? ViewType.noIntrinsicMetric,
height: children.first { $0.label == "height" }?.value as? CGFloat ?? ViewType.noIntrinsicMetric)

size = nsView.measuredFittingSize
}

Expand All @@ -110,38 +112,14 @@ extension MeasuringViewRepresentable {
-> CGSize?
{
nsView.strategy = sizing
nsView.proposedSize = proposal.viewTypeValue

// Creates a size by replacing `nil`s with `UIView.noIntrinsicMetric`
nsView.proposedSize = .init(
width: proposal.width ?? ViewType.noIntrinsicMetric,
height: proposal.height ?? ViewType.noIntrinsicMetric)

return nsView.measuredFittingSize
}
#endif
}
#endif

#if swift(>=5.7.1) // Proxy check for being built with the iOS 15 SDK
@available(iOS 16.0, tvOS 16.0, macOS 13.0, *)
extension ProposedViewSize {
/// Creates a size suitable for the current platform's view building framework by capping infinite values to a significantly large value and
/// replacing `nil`s with `UIView.noIntrinsicMetric`
var viewTypeValue: CGSize {
.init(
width: width?.constraintSafeValue ?? ViewType.noIntrinsicMetric,
height: height?.constraintSafeValue ?? ViewType.noIntrinsicMetric)
}
}

#endif

extension CGFloat {
static var maxConstraintValue: CGFloat {
// On iOS 15 and below, configuring an auto layout constraint with the constant
// `.greatestFiniteMagnitude` exceeds an internal limit and logs an exception to console. To
// avoid, we use a significantly large value.
1_000_000
}

/// Returns a value suitable for configuring auto layout constraints
var constraintSafeValue: CGFloat {
isInfinite ? .maxConstraintValue : self
}

}
Loading

0 comments on commit 06d9405

Please sign in to comment.