Priority enum#345
Conversation
MP0w
left a comment
There was a problem hiding this comment.
Can't approve as I'm not that experienced with the SnapKit codebase but the implementation LGTM, probably someone should decide if the old methods can be removed or not.
CI is failed but it's just the usual random erro 65 😞
I would add few tests to make sure the implementation of Strideable is correct
|
|
||
| public init?(rawValue: Float) { | ||
| // TODO: | ||
| // constrain to 0 <= x <= 1000 |
There was a problem hiding this comment.
since it's a failable initializer we should return nil for invalid priority (not completely sure that <0 or >1000 is invalid...)
| case .low: | ||
| return 250.0 | ||
| case .medium: | ||
| return 500.0 |
|
|
||
| @available(*, deprecated:3.0, message:"Use priority(_ amount: ConstraintPriorityTarget) instead.") | ||
| @discardableResult | ||
| public func priorityMedium() -> ConstraintMakerFinalizable { |
There was a problem hiding this comment.
Maybe we have to keep (but change the implementation) those deprecated methods? Otherwise will need to be a Breaking Change version
|
I agree with most of @MP0w's comments |
|
Will update this PR soon |
|
PR is updated! @robertjpayne @MP0w |
|
still the same |
|
TODO: Need to update this again so the old methods can use the new enum values instead of hardcoded values. |
| self = .custom(value: rawValue) | ||
| } | ||
|
|
||
| var macOSMedium: Float { |
There was a problem hiding this comment.
I would make it private or use it inline directly. The naming could be something different ? or is this because other platform don't really have medium priority? (AFAIK)
There was a problem hiding this comment.
It's mainly because the other platform don't really have a medium priority
MP0w
left a comment
There was a problem hiding this comment.
Ah, also we should change the deprecation message of thew old methods (priorityRequired(), etc) to suggest the new way
|
@robertjpayne please re-review! Should I update the warning messages? Or are those good to go? |
|
Any update? |
|
|
||
| public class ConstraintMakerPriortizable: ConstraintMakerFinalizable { | ||
|
|
||
| public enum Priority: Strideable, RawRepresentable, Equatable { |
There was a problem hiding this comment.
Oh, IMHO this enum should not be inside ConstraintMakerPriortizable.
We don't want to write ConstraintMakerPriortizable.Priority right?
|
|
||
| @available(*, deprecated:3.0, message:"Use priority(_ amount: ConstraintPriorityTarget) instead.") | ||
| @discardableResult | ||
| public func priority(level: Priority) -> ConstraintMakerFinalizable { |
There was a problem hiding this comment.
Not a fan of the label level.
.priority(.low) feels the natural candidate
| @available(*, deprecated:3.0, message:"Use priority(_ amount: ConstraintPriorityTarget) instead.") | ||
| @discardableResult | ||
| public func priority(level: Priority) -> ConstraintMakerFinalizable { | ||
| return self.priority(level: ConstraintMakerPriortizable.Priority(rawValue: level.rawValue)!) |
There was a problem hiding this comment.
Isn't this a loop??! (It's late but really looks like)
Also don't see the point of initializing a priority with another priority...
|
I'll get around to this sorry! I've been insanely busy. |
|
@robertjpayne Hey! Sorry to push but I feel like this improves the APIs and I'm missing it. |
|
Hey everyone @MP0w included I've merged this but I've also made some tweaks: Moved the Priority enum to a
|
|
Also I removed the stride able conformance, I can't see how that is actually useful? Is there a solid use case for that? EDIT: actually I can see how one may one EDIT2: |
* make 'layoutConstraints' public again (#382) * Fix wrong function call within contentCompressionResistanceHorizontalPriority (#387) * Missing property topMargin on ConstraintMakerExtendable (#393) This pull request adds the missing property "topMargin" to ConstraintMakerExtendable class. * Switched main target build settings' "skip install" default settings to YES. (#391) * Add an isActive API to Constraint * Priority enum (#345) * Adds ConstraintPriority enum to ConstraintMakerPrioritizable * Constraints priority is now more robust * Adds priority enum function * Fixes compile error * Adds failable initializer. Custom macOS medium priority. Adds back deleted methods * Updates depracation messages * Improve Priority API's * Add extra protocol conformances to ConstraintPriority * Tweak priority API's for offseting * Tweak priority API's some more and add tests * Prepare for release
|
I see the change to struct, the reason for strideable is that you are able to use for example priority(.low + 1), this improves a lot the usage IMHO. |
|
That was the implementation #324 (comment) |
|
@MP0w I couldn't get it to work w/o ambiguous API errors on the struct, I think it worked on the enum because enum cases are slightly different than static members for shorthand mode. |
|
I will try it out, otherwise would you reconsider using an enum? It can still be extended with static vars that return .custom(value) if the only argument was the extensibility |
|
@robertjpayne I tested it in a playground and seems to work https://gist.github.com/MP0w/4cd6df5558f8db2729035c0a25203398 |
This adds an enum for priority based constraints allowing users to write priority as:
Based on the issue #324