-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
31 changed files
with
243 additions
and
90 deletions.
There are no files selected for viewing
20 changes: 0 additions & 20 deletions
20
Sources/OpenSwiftUI/DataAndStorage/EnvironmentValues/EnvironmentValues+controlSize.swift
This file was deleted.
Oops, something went wrong.
20 changes: 0 additions & 20 deletions
20
Sources/OpenSwiftUI/DataAndStorage/EnvironmentValues/EnvironmentValues+isEnabled.swift
This file was deleted.
Oops, something went wrong.
30 changes: 30 additions & 0 deletions
30
...tUI/DataAndStorage/EnvironmentValues/Internal/TODO/_EnvironmentKeyTransformModifier.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,30 @@ | ||
protocol _GraphInputsModifier {} | ||
|
||
@frozen | ||
public struct _EnvironmentKeyTransformModifier<Value> : ViewModifier, _GraphInputsModifier { | ||
public var keyPath: Swift.WritableKeyPath<EnvironmentValues, Value> | ||
public var transform: (inout Value) -> Swift.Void | ||
|
||
@inlinable | ||
public init(keyPath: Swift.WritableKeyPath<EnvironmentValues, Value>, transform: @escaping (inout Value) -> Swift.Void) { | ||
self.keyPath = keyPath | ||
self.transform = transform | ||
} | ||
public static func _makeInputs(modifier: _GraphValue<_EnvironmentKeyTransformModifier<Value>>, inputs: inout _GraphInputs) { | ||
|
||
} | ||
public typealias Body = Never | ||
} | ||
|
||
extension View { | ||
@inlinable | ||
public func transformEnvironment<V>( | ||
_ keyPath: WritableKeyPath<EnvironmentValues, V>, | ||
transform: @escaping (inout V) -> Void | ||
) -> some View { | ||
modifier(_EnvironmentKeyTransformModifier( | ||
keyPath: keyPath, | ||
transform: transform | ||
)) | ||
} | ||
} |
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,7 @@ | ||
@inlinable | ||
@inline(__always) | ||
func asOptional<Value>(_ value: Value) -> Value? { | ||
func unwrap<T>() -> T { value as! T } | ||
let optionalValue: Value? = unwrap() | ||
return optionalValue | ||
} |
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
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
28 changes: 28 additions & 0 deletions
28
Sources/OpenSwiftUI/Views/Controls/ControlSize/ControlSize.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,28 @@ | ||
// | ||
// ControlSize.swift | ||
// OpenSwiftUI | ||
// | ||
// Created by Kyle on 2023/12/5. | ||
// Lastest Version: iOS 17.0 | ||
// Status: Complete | ||
|
||
/// The size classes, like regular or small, that you can apply to controls | ||
/// within a view. | ||
@available(tvOS, unavailable) | ||
public enum ControlSize: CaseIterable, Sendable { | ||
/// A control version that is minimally sized. | ||
case mini | ||
|
||
/// A control version that is proportionally smaller size for space-constrained views. | ||
case small | ||
|
||
/// A control version that is the default size. | ||
case regular | ||
|
||
/// A control version that is prominently sized. | ||
case large | ||
|
||
case extraLarge | ||
} | ||
|
||
extension ControlSize: Hashable {} |
76 changes: 76 additions & 0 deletions
76
Sources/OpenSwiftUI/Views/Controls/ControlSize/ControlSizeKey.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,76 @@ | ||
// | ||
// ControlSizeKey.swift | ||
// OpenSwiftUI | ||
// | ||
// Created by Kyle on 2023/11/5. | ||
// Lastest Version: iOS 15.5 | ||
// Status: Complete | ||
// ID: 50E368DED9ACE8B6BEC08FF7781AF4B1 | ||
|
||
private struct ControlSizeKey: EnvironmentKey { | ||
static let defaultValue: ControlSize = .regular | ||
} | ||
|
||
extension EnvironmentValues { | ||
/// The size to apply to controls within a view. | ||
/// | ||
/// The default is ``ControlSize/regular``. | ||
@available(tvOS, unavailable) | ||
public var controlSize: ControlSize { | ||
get { self[ControlSizeKey.self] } | ||
set { self[ControlSizeKey.self] = newValue } | ||
} | ||
} | ||
|
||
@available(tvOS, unavailable) | ||
extension View { | ||
/// Sets the size for controls within this view. | ||
/// | ||
/// Use `controlSize(_:)` to override the system default size for controls | ||
/// in this view. In this example, a view displays several typical controls | ||
/// at `.mini`, `.small` and `.regular` sizes. | ||
/// | ||
/// struct ControlSize: View { | ||
/// var body: some View { | ||
/// VStack { | ||
/// MyControls(label: "Mini") | ||
/// .controlSize(.mini) | ||
/// MyControls(label: "Small") | ||
/// .controlSize(.small) | ||
/// MyControls(label: "Regular") | ||
/// .controlSize(.regular) | ||
/// } | ||
/// .padding() | ||
/// .frame(width: 450) | ||
/// .border(Color.gray) | ||
/// } | ||
/// } | ||
/// | ||
/// struct MyControls: View { | ||
/// var label: String | ||
/// @State private var value = 3.0 | ||
/// @State private var selected = 1 | ||
/// var body: some View { | ||
/// HStack { | ||
/// Text(label + ":") | ||
/// Picker("Selection", selection: $selected) { | ||
/// Text("option 1").tag(1) | ||
/// Text("option 2").tag(2) | ||
/// Text("option 3").tag(3) | ||
/// } | ||
/// Slider(value: $value, in: 1...10) | ||
/// Button("OK") { } | ||
/// } | ||
/// } | ||
/// } | ||
/// | ||
/// ![A screenshot showing several controls of various | ||
/// sizes.](SwiftUI-View-controlSize.png) | ||
/// | ||
/// - Parameter controlSize: One of the control sizes specified in the | ||
/// ``ControlSize`` enumeration. | ||
@inlinable | ||
public func controlSize(_ controlSize: ControlSize) -> some View { | ||
environment(\.controlSize, controlSize) | ||
} | ||
} |
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,51 @@ | ||
// | ||
// EnabledKey.swift | ||
// OpenSwiftUI | ||
// | ||
// Created by Kyle on 2023/10/9. | ||
// Lastest Version: iOS 15.5 | ||
// Status: Complete | ||
// ID: 6C7FC77DDFF6AC5E011A44B5658DAD66 | ||
|
||
private struct EnabledKey: EnvironmentKey { | ||
static var defaultValue: Bool { true } | ||
} | ||
|
||
extension EnvironmentValues { | ||
/// A Boolean value that indicates whether the view associated with this | ||
/// environment allows user interaction. | ||
/// | ||
/// The default value is `true`. | ||
public var isEnabled: Bool { | ||
get { self[EnabledKey.self] } | ||
set { self[EnabledKey.self] = newValue } | ||
} | ||
} | ||
|
||
extension View { | ||
/// Adds a condition that controls whether users can interact with this | ||
/// view. | ||
/// | ||
/// The higher views in a view hierarchy can override the value you set on | ||
/// this view. In the following example, the button isn't interactive | ||
/// because the outer `disabled(_:)` modifier overrides the inner one: | ||
/// | ||
/// HStack { | ||
/// Button(Text("Press")) {} | ||
/// .disabled(false) | ||
/// } | ||
/// .disabled(true) | ||
/// | ||
/// - Parameter disabled: A Boolean value that determines whether users can | ||
/// interact with this view. | ||
/// | ||
/// - Returns: A view that controls whether users can interact with this | ||
/// view. | ||
@inlinable | ||
public func disabled(_ disabled: Bool) -> some View { | ||
modifier(_EnvironmentKeyTransformModifier( | ||
keyPath: \.isEnabled, | ||
transform: { $0 = $0 && !disabled } | ||
)) | ||
} | ||
} |
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
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.