-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add implementation for AccessibilityNumber
- Loading branch information
Showing
4 changed files
with
120 additions
and
0 deletions.
There are no files selected for viewing
43 changes: 43 additions & 0 deletions
43
Sources/OpenSwiftUI/Accessibility/internal/AccessibilityNumber.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
// | ||
// AccessibilityNumber.swift | ||
// OpenSwiftUI | ||
// | ||
// Created by Kyle on 2023/12/2. | ||
// Lastest Version: iOS 15.5 | ||
// Status: Complete | ||
|
||
import Foundation | ||
|
||
struct AccessibilityNumber { | ||
var base: NSNumber | ||
} | ||
|
||
extension AccessibilityNumber: AccessibilityValue { | ||
var value: NSNumber { base } | ||
} | ||
|
||
extension AccessibilityNumber: ExpressibleByFloatLiteral { | ||
init(floatLiteral value: Double) { | ||
base = NSNumber(floatLiteral: value) | ||
} | ||
} | ||
|
||
extension AccessibilityNumber: ExpressibleByIntegerLiteral { | ||
init(integerLiteral value: Int) { | ||
base = NSNumber(integerLiteral: value) | ||
} | ||
} | ||
|
||
extension AccessibilityNumber: Codable { | ||
init(from decoder: Decoder) throws { | ||
let container = try decoder.singleValueContainer() | ||
let data = try container.decode(Data.self) | ||
self.base = try NSKeyedUnarchiver.unarchivedObject(ofClass: NSNumber.self, from: data)! | ||
} | ||
|
||
func encode(to encoder: Encoder) throws { | ||
let data = try NSKeyedArchiver.archivedData(withRootObject: base, requiringSecureCoding: true) | ||
var container = encoder.singleValueContainer() | ||
try container.encode(data) | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
Sources/OpenSwiftUI/Accessibility/internal/AccessibilityPlatformSafe.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
// | ||
// AccessibilityPlatformSafe.swift | ||
// OpenSwiftUI | ||
// | ||
// Created by Kyle on 2023/12/2. | ||
// Lastest Version: iOS 15.5 | ||
// Status: Complete | ||
|
||
import Foundation | ||
|
||
protocol AccessibilityPlatformSafe {} | ||
|
||
extension String: AccessibilityPlatformSafe {} | ||
extension Double: AccessibilityPlatformSafe {} | ||
extension Int: AccessibilityPlatformSafe {} | ||
extension UInt: AccessibilityPlatformSafe {} | ||
extension UInt8: AccessibilityPlatformSafe {} | ||
extension Bool: AccessibilityPlatformSafe {} | ||
extension NSNumber: AccessibilityPlatformSafe {} | ||
extension Optional: AccessibilityPlatformSafe where Wrapped: AccessibilityPlatformSafe {} |
35 changes: 35 additions & 0 deletions
35
Sources/OpenSwiftUI/Accessibility/internal/AccessibilityValue.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
// | ||
// AccessibilityValue.swift | ||
// OpenSwiftUI | ||
// | ||
// Created by Kyle on 2023/12/2. | ||
// Lastest Version: iOS 15.5 | ||
// Status: Complete | ||
|
||
import Foundation | ||
|
||
protocol AccessibilityValue: Equatable { | ||
associatedtype PlatformValue: AccessibilityPlatformSafe | ||
var localizedDescription: String? { get } | ||
var displayDescription: String? { get } | ||
var value: PlatformValue { get } | ||
var minValue: PlatformValue? { get } | ||
var maxValue: PlatformValue? { get } | ||
var step: PlatformValue? { get } | ||
static var type: AnyAccessibilityValueType { get } | ||
} | ||
|
||
extension AccessibilityValue where PlatformValue: NSNumber { | ||
var localizedDescription: String? { | ||
NumberFormatter.localizedString(from: value, number: .decimal) | ||
} | ||
|
||
var displayDescription: String? { | ||
NumberFormatter.localizedString(from: value, number: .decimal) | ||
} | ||
|
||
var minValue: NSNumber? { nil } | ||
var maxValue: NSNumber? { nil } | ||
var step: NSNumber? { nil } | ||
static var type: AnyAccessibilityValueType { .number } | ||
} |
22 changes: 22 additions & 0 deletions
22
Sources/OpenSwiftUI/Accessibility/internal/AnyAccessibilityValueType.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
// | ||
// AnyAccessibilityValueType.swift | ||
// OpenSwiftUI | ||
// | ||
// Created by Kyle on 2023/12/2. | ||
// Lastest Version: iOS 15.5 | ||
// Status: Complete | ||
|
||
enum AnyAccessibilityValueType: UInt { | ||
case int | ||
case double | ||
case bool | ||
case string | ||
case disclosure | ||
case toggle | ||
case slider | ||
case stepper | ||
case progress | ||
case boundedNumber | ||
case headingLevel | ||
case number | ||
} |