Skip to content

Commit

Permalink
Add AccessibilityBoundedNumber init implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
Kyle-Ye committed Dec 3, 2023
1 parent 8f6187d commit 8d5718b
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@ private protocol AbstractAnyAccessibilityValue: Codable {

// MARK: - AnyAccessibilityValue

struct AnyAccessibilityValue/*: AbstractAnyAccessibilityValue*/ {
struct AnyAccessibilityValue {
private var base: AbstractAnyAccessibilityValue

init<Value: Codable & AccessibilityValue>(_ base: Value) {
init(_ base: some Codable & AccessibilityValue) {
self.base = ConcreteBase(base: base)

Check warning on line 32 in Sources/OpenSwiftUI/Accessibility/internal/AccessibilityBoundedNumber.swift

View check run for this annotation

Codecov / codecov/patch

Sources/OpenSwiftUI/Accessibility/internal/AccessibilityBoundedNumber.swift#L31-L32

Added lines #L31 - L32 were not covered by tests
}
}
Expand Down Expand Up @@ -65,6 +65,23 @@ extension AnyAccessibilityValue: Codable {
}
}

extension AnyAccessibilityValue: AbstractAnyAccessibilityValue {
var localizedDescription: String? { base.localizedDescription }
var displayDescription: String? { base.displayDescription }
var value: Any { base.value }
var minValue: Any? { base.minValue }
var maxValue: Any? { base.maxValue }
var step: Any? { base.step }
var type: AnyAccessibilityValueType { base.type }
func `as`<Value>(_ type: Value.Type) -> Value? where Value: AccessibilityValue {
base.as(type)

Check warning on line 77 in Sources/OpenSwiftUI/Accessibility/internal/AccessibilityBoundedNumber.swift

View check run for this annotation

Codecov / codecov/patch

Sources/OpenSwiftUI/Accessibility/internal/AccessibilityBoundedNumber.swift#L69-L77

Added lines #L69 - L77 were not covered by tests
}

fileprivate func isEqual(to value: AbstractAnyAccessibilityValue) -> Bool {
base.isEqual(to: value)

Check warning on line 81 in Sources/OpenSwiftUI/Accessibility/internal/AccessibilityBoundedNumber.swift

View check run for this annotation

Codecov / codecov/patch

Sources/OpenSwiftUI/Accessibility/internal/AccessibilityBoundedNumber.swift#L80-L81

Added lines #L80 - L81 were not covered by tests
}
}

// MARK: AnyAccessibilityValue.ConcreateBase

extension AnyAccessibilityValue {
Expand All @@ -83,9 +100,10 @@ extension AnyAccessibilityValue.ConcreteBase: AbstractAnyAccessibilityValue {
var maxValue: Any? { base.maxValue }
var step: Any? { base.step }
var type: AnyAccessibilityValueType { Base.type }
func `as`<Value>(_ type: Value.Type) -> Value? where Value : AccessibilityValue {
func `as`<Value>(_: Value.Type) -> Value? where Value: AccessibilityValue {
base as? Value

Check warning on line 104 in Sources/OpenSwiftUI/Accessibility/internal/AccessibilityBoundedNumber.swift

View check run for this annotation

Codecov / codecov/patch

Sources/OpenSwiftUI/Accessibility/internal/AccessibilityBoundedNumber.swift#L96-L104

Added lines #L96 - L104 were not covered by tests
}

func isEqual(to value: AbstractAnyAccessibilityValue) -> Bool {
base == (value as? Self)?.base

Check warning on line 108 in Sources/OpenSwiftUI/Accessibility/internal/AccessibilityBoundedNumber.swift

View check run for this annotation

Codecov / codecov/patch

Sources/OpenSwiftUI/Accessibility/internal/AccessibilityBoundedNumber.swift#L107-L108

Added lines #L107 - L108 were not covered by tests
}
Expand All @@ -99,9 +117,22 @@ struct AccessibilityBoundedNumber {
var upperBound: AccessibilityNumber?
var stride: AccessibilityNumber?

// TODO
init?<S: Strideable>(for value: S, in range: ClosedRange<S>?, by stride: S.Stride?) {
return nil
init?<S: Strideable>(for value: S, in range: ClosedRange<S>?, by strideValue: S.Stride?) {
let clampedValue = range.map { value.clamped(to: $0) }
let newValue = clampedValue ?? value
guard let numericValue = newValue as? AccessibilityNumeric,
let numberValue = numericValue.asNumber() else {
return nil

Check warning on line 125 in Sources/OpenSwiftUI/Accessibility/internal/AccessibilityBoundedNumber.swift

View check run for this annotation

Codecov / codecov/patch

Sources/OpenSwiftUI/Accessibility/internal/AccessibilityBoundedNumber.swift#L125

Added line #L125 was not covered by tests
}
number = numberValue
if let range {
lowerBound = range.minimumValue?.asNumber()
upperBound = range.maximumValue?.asNumber()
}
if let strideValue,
let numericStride = strideValue as? AccessibilityNumeric {
stride = numericStride.asNumber()
}
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
extension ClosedRange where Bound: Strideable {
var minimumValue: AccessibilityNumeric? {
guard let value = lowerBound as? AccessibilityNumeric,
value.isValidMinValue else {
return nil

Check warning on line 5 in Sources/OpenSwiftUI/Accessibility/internal/ClosedRange+AccessibilityNumeric.swift

View check run for this annotation

Codecov / codecov/patch

Sources/OpenSwiftUI/Accessibility/internal/ClosedRange+AccessibilityNumeric.swift#L5

Added line #L5 was not covered by tests
}
return value
}

var maximumValue: AccessibilityNumeric? {
guard let value = upperBound as? AccessibilityNumeric,
value.isValidMaxValue else {
return nil

Check warning on line 13 in Sources/OpenSwiftUI/Accessibility/internal/ClosedRange+AccessibilityNumeric.swift

View check run for this annotation

Codecov / codecov/patch

Sources/OpenSwiftUI/Accessibility/internal/ClosedRange+AccessibilityNumeric.swift#L13

Added line #L13 was not covered by tests
}
return value
}
}

0 comments on commit 8d5718b

Please sign in to comment.