Repository navigation
Horizontally, Vertically & All with margin parameter #111
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
Changes from all commits
dc773c3
58013f8
b917a49
d9a37a5
f0f3fb7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -24,6 +24,19 @@ extension PinLayoutImpl { | |
| internal func top(_ context: Context) { | ||
| setTop(0, context) | ||
| } | ||
|
|
||
| @discardableResult | ||
| internal func top(_ value: CGFloat, _ context: Context) -> PinLayout { | ||
| setTop(value, context) | ||
| return self | ||
| } | ||
|
|
||
| @discardableResult | ||
| internal func top(_ percent: Percent, _ context: Context) -> PinLayout { | ||
| guard let layoutSuperviewRect = layoutSuperviewRect(context) else { return self } | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could you update the method |
||
| setTop(percent.of(layoutSuperviewRect.height), context) | ||
| return self | ||
| } | ||
|
|
||
| internal func setTop(_ value: CGFloat, _ context: Context) { | ||
| if let _bottom = _bottom, let height = height { | ||
|
|
@@ -134,6 +147,13 @@ extension PinLayoutImpl { | |
| setBottom(layoutSuperviewRect.height - value, context) | ||
| return self | ||
| } | ||
|
|
||
| @discardableResult | ||
| internal func bottom(_ percent: Percent, _ context: Context) -> PinLayout { | ||
| guard let layoutSuperviewRect = layoutSuperviewRect(context) else { return self } | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could you update the method |
||
| setBottom(layoutSuperviewRect.height - percent.of(layoutSuperviewRect.height), context) | ||
| return self | ||
| } | ||
|
|
||
| internal func setBottom(_ value: CGFloat, _ context: Context) { | ||
| if let _top = _top, let height = height { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -469,6 +469,11 @@ class PinEdgesSpec: QuickSpec { | |
| aView.pin.all().margin(10) | ||
| expect(aView.frame).to(equal(CGRect(x: 10.0, y: 10.0, width: 380.0, height: 380.0))) | ||
| } | ||
|
|
||
| it("should adjust the aView") { | ||
| aView.pin.all(10) | ||
| expect(aView.frame).to(equal(CGRect(x: 10.0, y: 10.0, width: 380.0, height: 380.0))) | ||
| } | ||
|
|
||
| it("should adjust the bViewChild") { | ||
| bViewChild.pin.all() | ||
|
|
@@ -479,6 +484,11 @@ class PinEdgesSpec: QuickSpec { | |
| bViewChild.pin.all().margin(10) | ||
| expect(bViewChild.frame).to(equal(CGRect(x: 10.0, y: 10.0, width: 90.0, height: 60.0))) | ||
| } | ||
|
|
||
| it("should adjust the bViewChild") { | ||
| bViewChild.pin.all(10) | ||
| expect(bViewChild.frame).to(equal(CGRect(x: 10.0, y: 10.0, width: 90.0, height: 60.0))) | ||
| } | ||
|
|
||
| it("should warn") { | ||
| aView.pin.top(20).all() | ||
|
|
@@ -512,6 +522,16 @@ class PinEdgesSpec: QuickSpec { | |
| aView.pin.horizontally().margin(10) | ||
| expect(aView.frame).to(equal(CGRect(x: 10.0, y: 100.0, width: 380.0, height: 100.0))) | ||
| } | ||
|
|
||
| it("should adjust the aView") { | ||
| aView.pin.horizontally(10) | ||
| expect(aView.frame).to(equal(CGRect(x: 10.0, y: 100.0, width: 380.0, height: 100.0))) | ||
| } | ||
|
|
||
| it("should adjust the aView") { | ||
| aView.pin.horizontally(10%) | ||
| expect(aView.frame).to(equal(CGRect(x: 40.0, y: 100.0, width: 320.0, height: 100.0))) | ||
| } | ||
|
|
||
| it("should adjust the bViewChild") { | ||
| bViewChild.pin.horizontally() | ||
|
|
@@ -522,6 +542,16 @@ class PinEdgesSpec: QuickSpec { | |
| bViewChild.pin.horizontally().margin(10) | ||
| expect(bViewChild.frame).to(equal(CGRect(x: 10.0, y: 10.0, width: 90.0, height: 20.0))) | ||
| } | ||
|
|
||
| it("should adjust the bViewChild") { | ||
| bViewChild.pin.horizontally(10) | ||
| expect(bViewChild.frame).to(equal(CGRect(x: 10.0, y: 10.0, width: 90.0, height: 20.0))) | ||
| } | ||
|
|
||
| it("should adjust the bViewChild") { | ||
| bViewChild.pin.horizontally(10%) | ||
| expect(bViewChild.frame).to(equal(CGRect(x: 11.0, y: 10.0, width: 88.0, height: 20.0))) | ||
| } | ||
|
|
||
| it("should warn") { | ||
| aView.pin.left(20).horizontally() | ||
|
|
@@ -531,6 +561,22 @@ class PinEdgesSpec: QuickSpec { | |
| aView.pin.right(20).horizontally() | ||
| expect(Pin.lastWarningText).to(contain(["horizontally() right coordinate", "won't be applied", "already been set to 20"])) | ||
| } | ||
| it("should warn") { | ||
| aView.pin.left(10).horizontally(20) | ||
| expect(Pin.lastWarningText).to(contain(["horizontally(20.0) left coordinate", "won't be applied", "already been set to 10"])) | ||
| } | ||
| it("should warn") { | ||
| aView.pin.right(10).horizontally(20) | ||
| expect(Pin.lastWarningText).to(contain(["horizontally(20.0) right coordinate", "won't be applied", "already been set to 10"])) | ||
| } | ||
| it("should warn") { | ||
| aView.pin.left(10).horizontally(10%) | ||
| expect(Pin.lastWarningText).to(contain(["horizontally(10%) left coordinate", "won't be applied", "already been set to 10"])) | ||
| } | ||
| it("should warn") { | ||
| aView.pin.right(10).horizontally(10%) | ||
| expect(Pin.lastWarningText).to(contain(["horizontally(10%) right coordinate", "won't be applied", "already been set to 10"])) | ||
| } | ||
| } | ||
|
|
||
| // | ||
|
|
@@ -546,6 +592,16 @@ class PinEdgesSpec: QuickSpec { | |
| aView.pin.vertically().margin(10) | ||
| expect(aView.frame).to(equal(CGRect(x: 140.0, y: 10.0, width: 200.0, height: 380.0))) | ||
| } | ||
|
|
||
| it("should adjust the aView") { | ||
| aView.pin.vertically(10) | ||
| expect(aView.frame).to(equal(CGRect(x: 140.0, y: 10.0, width: 200.0, height: 380.0))) | ||
| } | ||
|
|
||
| it("should adjust the aView") { | ||
| aView.pin.vertically(10%) | ||
| expect(aView.frame).to(equal(CGRect(x: 140.0, y: 40.0, width: 200.0, height: 320.0))) | ||
| } | ||
|
|
||
| it("should adjust the bViewChild") { | ||
| bViewChild.pin.vertically() | ||
|
|
@@ -565,6 +621,22 @@ class PinEdgesSpec: QuickSpec { | |
| aView.pin.bottom(20).vertically() | ||
| expect(Pin.lastWarningText).to(contain(["vertically() bottom coordinate", "won't be applied", "already been set to 20"])) | ||
| } | ||
| it("should warn") { | ||
| aView.pin.top(10).vertically(20) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Once you have updated the method context, thanks to updating expectations, here it should contain |
||
| expect(Pin.lastWarningText).to(contain(["vertically(20.0) top coordinate", "won't be applied", "already been set to 10"])) | ||
| } | ||
| it("should warn") { | ||
| aView.pin.bottom(10).vertically(20) | ||
| expect(Pin.lastWarningText).to(contain(["vertically(20.0) bottom coordinate", "won't be applied", "already been set to 10"])) | ||
| } | ||
| it("should warn") { | ||
| aView.pin.top(10).vertically(10%) | ||
| expect(Pin.lastWarningText).to(contain(["vertically(10%) top coordinate", "won't be applied", "already been set to 10"])) | ||
| } | ||
| it("should warn") { | ||
| aView.pin.bottom(10).vertically(10%) | ||
| expect(Pin.lastWarningText).to(contain(["vertically(10%) bottom coordinate", "won't be applied", "already been set to 10"])) | ||
| } | ||
| } | ||
| } | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.
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.
You don't need to add this method if you call
setTop(value, context), setBottom(value, context) ...infunc all(_ value: CGFloat),horizontally(...)andvertically(...)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.
Ah, ok you can keep it that way, I use this pattern somewhere else 😊
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 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.
But could you update the method
func top(_ value: CGFloat) -> PinLayoutin PinLayoutImpl.swift to: