Skip to content
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

[Box] Add support for boxes with semicircular edges #145

Merged
merged 3 commits into from Sep 14, 2020

Conversation

nononoah
Copy link
Contributor

@nononoah nononoah commented Sep 12, 2020

Summary

This PR adds the capsule case to Box.CornerStyle. This case sugars the following pattern

GeometryReader { geometry in
  Box(cornerStyle: .rounded(geometry.constraint.height.maximum / 2.0))
}

into

Box(cornerStyle: .capsule)

Given the effect of GeometryReader's closure on rightward drift and capture semantics and the relative ubiquity of this design element, I believe that this sugar is merited. I would further argue that this change comes at a small cost: a slight expansion of API surface area, and almost no implementation disruption.

Changes

  • updates var radius: CGFloat on Box.CornerStyle to func radius(for:) -> CGFloat
  • extends and organizes relevant snapshot tests

Additional comments

This is my first PR, so I'm likely to have made a few process mistakes. Please correct me where I've gone wrong.

Copy link
Collaborator

@kyleve kyleve left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good! Can you also update the Changelog.md in the root of the repo with this change?

@@ -102,6 +102,7 @@ extension Box {

public enum CornerStyle {
case square
case semicircular
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if “pill” might be clearer? No preference, but in my head that makes me more immediately realize what it does.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm open to changing it of course, but biased towards semicircular because

  • it fits grammatically with the other cases (as an adjective)
  • it is a generally understood geometric term (like square)

In my mind, pill is jargon and no different than chip, what Google's Material calls it. If you're familiar with the argot, it's familiar. Since most people working with Blueprint share this familiarity, I think it's a fine choice.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Way overthought bikeshed:

I think part of the issue here is that the existing cases are purely the corner style where this new case is wanting to describe a shape as a whole (that is, affecting more than each corner individually). And I think we're left trying avoid using a “shape” word to describe a “corner.”

And my mind still reads it as a shape and expects a half a circle that's flat on the other side (that is to say, a literal semicircle).

FWIW SwiftUI avoids this issue by having this as a shape type (called Capsule) rather than a corner style.

I could see a few options:

  1. Rename this type/property to be “Shape” and then something like “Capsule” or “Pill” seems more right to me
  2. Put this into its own element type altogether (again, as Pill or Capsule IMO)
  3. Land as-is with the same or a different name (in which case I'd probably still lean against “semicircle” and just accept conflating shape and corner a bit)

(And Google's wrong, “chip” is a weird name)

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

capsule is also a good name for this property

I wouldn't make this a different element since we'd have to duplicate all the shadow and border style stuff.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Given the enthusiasm for capsule , I updated it. Still, I think it stands in contrast to its sibling cases.

And my mind still reads it as a shape and expects a half a circle that's flat on the other side (that is to say, a literal semicircle).

That's fair, though this is one impression I tried to avoid when renaming it from semicircle to semicircular. The latter may be ascribed to an object forming a semicircle, which is a fair attribution to such corners. This is similar if not identical semantically to square, I'd argue.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, we've definitely got a less than idea parallelism here. I think were this has landed is more intuitive, though less … precise.

@nononoah
Copy link
Contributor Author

Pending additional review, this is ready to be merged.

If someone with write access would like to bring it home, I'd appreciate that.

switch self {
case .square:
return 0
case .semicircular:
return bounds.height / 2.0
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should use the min of height and width so it works for vertical rects too

Copy link
Contributor Author

@nononoah nononoah Sep 14, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good call. Updated and added a snapshot test for it.

@@ -18,13 +18,31 @@ class BoxTests: XCTestCase {
identifier: "clear")
}

func test_cornerRadius() {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you delete the old image please?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you mean this file, which has been deleted, though it's a bit tricky to tell from Github.

Screen Shot 2020-09-13 at 11 55 12 PM

Please let me know if you're referring to another one.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh oops, yeah sorry. GitHub on my phone really didn't want me to see it. Thanks!

@@ -102,6 +102,7 @@ extension Box {

public enum CornerStyle {
case square
case semicircular
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, we've definitely got a less than idea parallelism here. I think were this has landed is more intuitive, though less … precise.

@kylebshr kylebshr merged commit af5c605 into square:main Sep 14, 2020
@nononoah nononoah deleted the noahb/box-rounded-corners branch September 17, 2020 20:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants