Skip to content

Commit

Permalink
Add implementation for AccessibilityNumber
Browse files Browse the repository at this point in the history
  • Loading branch information
Kyle-Ye committed Dec 2, 2023
1 parent 011659b commit e00092b
Show file tree
Hide file tree
Showing 4 changed files with 120 additions and 0 deletions.
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)
}
}
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 {}
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 }
}
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
}

0 comments on commit e00092b

Please sign in to comment.