-
Notifications
You must be signed in to change notification settings - Fork 57
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Varadic range support #140
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changes to how we call the new dimensionRange
Source/Models/BrickDimension.swift
Outdated
@@ -18,39 +18,106 @@ public struct BrickSize { | |||
} | |||
} | |||
|
|||
public typealias RangeDimensionPair = (dimension: BrickDimension, minimumLength: CGFloat) | |||
|
|||
public struct BrickRangeDimention { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should be Dimension
Source/Models/BrickDimension.swift
Outdated
indirect case auto(estimate: BrickDimension) | ||
indirect case orientation(landscape: BrickDimension, portrait: BrickDimension) | ||
indirect case horizontalSizeClass(regular: BrickDimension, compact: BrickDimension) | ||
indirect case verticalSizeClass(regular: BrickDimension, compact: BrickDimension) | ||
|
||
indirect case dimensionRange(range: BrickRangeDimention) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ideally this would be
indirect case dimensionRange(minimum: BrickDimension, additionalRangePairs: [RangeDimensionPair]?)
Source/Models/BrickDimension.swift
Outdated
case .verticalSizeClass(let regular, let compact): | ||
let isRegular = BrickDimension.verticalInterfaceSizeClass == .regular | ||
return (isRegular ? regular : compact).dimension | ||
return (isRegular ? regular : compact).dimension(withValue: value) | ||
case .dimensionRange(let dimensionRange): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
With the change to the indirect case, you now initialize the BrickRangeDimension here instead
let additionalRangePairs1: [RangeDimensionPair] = [(dimension: .ratio(ratio: 1/2), minimumLength: CGFloat(350))] | ||
let dimensionRange1: BrickDimension = .dimensionRange(range: BrickRangeDimention(minimum: .ratio(ratio: 1.0), additionalRangePairs: additionalRangePairs1)) | ||
let additionalRangePairs2: [RangeDimensionPair] = [(dimension: .ratio(ratio: 0.5), minimumLength: CGFloat(350))] | ||
let dimensionRange2: BrickDimension = .dimensionRange(range: BrickRangeDimention(minimum: .ratio(ratio: 0.5 + 0.5), additionalRangePairs: additionalRangePairs2)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not a fan of calling enum .dimensionRange and then initializing an object that is BrickRangeDimension, provided comments on how to adjust this call so that it's similar to the other BrickDimension cases we have
Codecov Report
@@ Coverage Diff @@
## master #140 +/- ##
=========================================
+ Coverage 93.25% 93.35% +0.1%
=========================================
Files 38 38
Lines 3097 3144 +47
=========================================
+ Hits 2888 2935 +47
Misses 209 209
Continue to review full report at Codecov.
|
Source/Models/BrickDimension.swift
Outdated
@@ -18,39 +18,106 @@ public struct BrickSize { | |||
} | |||
} | |||
|
|||
public typealias RangeDimensionPair = (dimension: BrickDimension, minimumLength: CGFloat) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is Length
the correct term? Should we use minimumWidth
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was uncertain about this one for a while, too. I wanted this to be applicable for height-based dimensions, too. However, I noticed in the code that we only support direct cases for height brick dimensions. I don't know if that's by design or a shortcoming. There's no good generic term that would encompass both width and height. For example, size is already reserved for a struct that contains both width and height.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We're already using size
for .fixed(size: 200)
? I think if we come up with the right terms, we should change it there too (might be some refactor on the WayfairApp though)...
Source/Models/BrickDimension.swift
Outdated
|
||
internal var dimensionPairs : [RangeDimensionPair] | ||
|
||
public init(minimum dimension: BrickDimension, additionalRangePairs: [RangeDimensionPair]?) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
could we use default
instead of minimum
? Or fallBack
?
Source/Models/BrickDimension.swift
Outdated
|
||
internal var dimensionPairs : [RangeDimensionPair] | ||
|
||
public init(minimum dimension: BrickDimension, additionalRangePairs: [RangeDimensionPair]?) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could we make it non-optional and default it to []
?
Source/Models/BrickDimension.swift
Outdated
} | ||
} | ||
|
||
public func dimension(forWidth width: CGFloat?) -> BrickDimension { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is width
optional?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It returns the default/minimum one if one isn't provided.
Source/Models/BrickDimension.swift
Outdated
indirect case auto(estimate: BrickDimension) | ||
indirect case orientation(landscape: BrickDimension, portrait: BrickDimension) | ||
indirect case horizontalSizeClass(regular: BrickDimension, compact: BrickDimension) | ||
indirect case verticalSizeClass(regular: BrickDimension, compact: BrickDimension) | ||
|
||
indirect case dimensionRange(minimum: BrickDimension, additionalRangePairs: [RangeDimensionPair]?) | ||
|
||
public var isEstimate: Bool { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could we pass the width
here too?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Swift doesn't allow you to provide default arguments for an enum case.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
could we make it a func
instead?
public func isEstimate(withValue value: CGFloat) -> Bool
case .auto(_): return true | ||
default: return false | ||
} | ||
} | ||
|
||
var dimension: BrickDimension { | ||
func dimension(withValue value: CGFloat? = nil) -> BrickDimension { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can we make it non-optional?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The concern here is that only one case actually needs to use a value. We'd be forcing people to provide a completely unused value for all the other cases.
Source/Models/BrickDimension.swift
Outdated
return lhs.dimension == rhs.dimension && almostEqualRelative(first: lhs.minimumLength, second: rhs.minimumLength) | ||
} | ||
|
||
public func ==(lhs: BrickRangeDimension, rhs: BrickRangeDimension) -> Bool { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there no unit test for this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There were but the last commit ended up modifying the coverage. I'll add additional tests to handle the additional cases.
…l unit tests for more complete code coverage.
Source/Models/BrickDimension.swift
Outdated
default: return self | ||
} | ||
} | ||
|
||
func value(for otherDimension: CGFloat, startingAt origin: CGFloat) -> CGFloat { | ||
let actualDimension = dimension | ||
let actualDimension: BrickDimension = dimension(withValue: otherDimension) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need this type here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It did at one point. I can remove it.
Can you add an example playground |
Allows the BrickKit collection view controller to apply different dimensions based upon how wide the brick is. Starting with a minimum dimension that would be applicable to all widths, the app can the specify different dimensions for any additional widths.
100% code coverage for all additional code.
Added code to sample app to demonstrate support for it.