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

Unnest Box.CornerStyle #508

Merged
merged 4 commits into from
Aug 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public struct AccessibilityElement: Element {
public var identifier: String?
public var traits: Set<Trait>
public var accessibilityFrameSize: CGSize?
public var accessibilityFrameCornerStyle: Box.CornerStyle
public var accessibilityFrameCornerStyle: CornerStyle
public var wrappedElement: Element

/// Used to provide custom behaviour when activated by voiceover. This will override the default behavior of issuing a tap event at the accessibility activation point.
Expand All @@ -34,7 +34,7 @@ public struct AccessibilityElement: Element {
hint: String? = nil,
identifier: String? = nil,
accessibilityFrameSize: CGSize? = nil,
accessibilityFrameCornerStyle: Box.CornerStyle = .square,
accessibilityFrameCornerStyle: CornerStyle = .square,
customActions: [AccessibilityElement.CustomAction] = [],
customContent: [AccessibilityElement.CustomContent] = [],
wrapping element: Element,
Expand Down Expand Up @@ -92,7 +92,7 @@ public struct AccessibilityElement: Element {

private final class AccessibilityView: UIView, AXCustomContentProvider {
var accessibilityFrameSize: CGSize?
var accessibilityFrameCornerStyle: Box.CornerStyle = .square
var accessibilityFrameCornerStyle: CornerStyle = .square
var accessibilityCustomContent: [AXCustomContent]! = [] // The exclamation `!` is in the protodol definition and required.

var increment: (() -> Void)?
Expand Down Expand Up @@ -175,7 +175,7 @@ extension Element {
hint: String? = nil,
identifier: String? = nil,
accessibilityFrameSize: CGSize? = nil,
accessibilityFrameCornerStyle: Box.CornerStyle = .square,
accessibilityFrameCornerStyle: CornerStyle = .square,
customActions: [AccessibilityElement.CustomAction] = [],
customContent: [AccessibilityElement.CustomContent] = []
) -> AccessibilityElement {
Expand Down
65 changes: 1 addition & 64 deletions BlueprintUICommonControls/Sources/Box.swift
Original file line number Diff line number Diff line change
Expand Up @@ -129,70 +129,7 @@ public struct Box: Element {

extension Box {

public enum CornerStyle: Equatable {
case square
case capsule
case rounded(radius: CGFloat, corners: Corners = .all)

public struct Corners: OptionSet, Equatable {
public let rawValue: UInt8

public init(rawValue: UInt8) {
self.rawValue = rawValue
}

public static let topLeft = Corners(rawValue: 1)
public static let topRight = Corners(rawValue: 1 << 1)
public static let bottomLeft = Corners(rawValue: 1 << 2)
public static let bottomRight = Corners(rawValue: 1 << 3)

public static let all: Corners = [.topLeft, .topRight, .bottomLeft, .bottomRight]
public static let top: Corners = [.topRight, .topLeft]
public static let left: Corners = [.topLeft, .bottomLeft]
public static let bottom: Corners = [.bottomLeft, .bottomRight]
public static let right: Corners = [.topRight, .bottomRight]

var toCACornerMask: CACornerMask {
var mask: CACornerMask = []
if contains(.topLeft) {
mask.update(with: .layerMinXMinYCorner)
}

if contains(.topRight) {
mask.update(with: .layerMaxXMinYCorner)
}

if contains(.bottomLeft) {
mask.update(with: .layerMinXMaxYCorner)
}

if contains(.bottomRight) {
mask.update(with: .layerMaxXMaxYCorner)
}
return mask
}

var toUIRectCorner: UIRectCorner {
var rectCorner: UIRectCorner = []
if contains(.topLeft) {
rectCorner.update(with: .topLeft)
}

if contains(.topRight) {
rectCorner.update(with: .topRight)
}

if contains(.bottomLeft) {
rectCorner.update(with: .bottomLeft)
}

if contains(.bottomRight) {
rectCorner.update(with: .bottomRight)
}
return rectCorner
}
}
}
public typealias CornerStyle = BlueprintUICommonControls.CornerStyle

/// Specifies the curve style when showing rounded corners on a `Box`.
public enum CornerCurve: Equatable {
Expand Down
67 changes: 67 additions & 0 deletions BlueprintUICommonControls/Sources/CornerStyle.swift
kyleve marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
import BlueprintUI
import UIKit

public enum CornerStyle: Equatable {
case square
case capsule
case rounded(radius: CGFloat, corners: Corners = .all)

public struct Corners: OptionSet, Equatable {
public let rawValue: UInt8

public init(rawValue: UInt8) {
self.rawValue = rawValue
}

public static let topLeft = Corners(rawValue: 1)
public static let topRight = Corners(rawValue: 1 << 1)
public static let bottomLeft = Corners(rawValue: 1 << 2)
public static let bottomRight = Corners(rawValue: 1 << 3)

public static let all: Corners = [.topLeft, .topRight, .bottomLeft, .bottomRight]
public static let top: Corners = [.topRight, .topLeft]
public static let left: Corners = [.topLeft, .bottomLeft]
public static let bottom: Corners = [.bottomLeft, .bottomRight]
public static let right: Corners = [.topRight, .bottomRight]

var toCACornerMask: CACornerMask {
var mask: CACornerMask = []
if contains(.topLeft) {
mask.update(with: .layerMinXMinYCorner)
}

if contains(.topRight) {
mask.update(with: .layerMaxXMinYCorner)
}

if contains(.bottomLeft) {
mask.update(with: .layerMinXMaxYCorner)
}

if contains(.bottomRight) {
mask.update(with: .layerMaxXMaxYCorner)
}
return mask
}

var toUIRectCorner: UIRectCorner {
var rectCorner: UIRectCorner = []
if contains(.topLeft) {
rectCorner.update(with: .topLeft)
}

if contains(.topRight) {
rectCorner.update(with: .topRight)
}

if contains(.bottomLeft) {
rectCorner.update(with: .bottomLeft)
}

if contains(.bottomRight) {
rectCorner.update(with: .bottomRight)
}
return rectCorner
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ extension UIBezierPath {

public convenience init(
rect: CGRect,
corners: Box.CornerStyle
corners: CornerStyle
) {
switch corners {
case .square:
Expand Down
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Changed

- Moved `CornerStyle` out of the `Box` namespace, and is now a root type in `BlueprintUICommonControls`. `Box.CornerStyle` is still available as a typealias.

### Deprecated

### Security
Expand Down
Loading