Skip to content
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
192 changes: 179 additions & 13 deletions Sources/OpenSwiftUICore/Data/Environment/EnvironmentAdditions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,52 @@
// EnvironmentAdditions.swift
// OpenSwiftUICore
//
// Audited for iOS 18.0
// Audited for 6.5.4
// Status: WIP
// ID: 1B17C64D9E901A0054B49B69A4A2439D (SwiftUICore)

public import Foundation
package import OpenGraphShims

// MARK: - EnvironmentValues + Display [6.4.41]
// MARK: - EnvironmentValues + Root

extension EnvironmentValues {
package mutating func configureForRoot() {
locale = .current
calendar = .current
timeZone = .current
}

package func configuredForRoot() -> EnvironmentValues {
var environment = self
environment.configureForRoot()
return environment
}
}

// TODO: EnvironementValues + Font

// MARK: - EnvironmentValues + Display

private struct DisplayScaleKey: EnvironmentKey {
static var defaultValue: CGFloat { 1.0 }
static let defaultValue: CGFloat = 1.0
}

private struct DefaultPixelLengthKey: EnvironmentKey {
static var defaultValue: CGFloat? { nil }
}

extension CachedEnvironment.ID {
package static let pixelLength: CachedEnvironment.ID = .init()
}

extension _ViewInputs {
package var pixelLength: Attribute<CGFloat> {
mapEnvironment(id: .pixelLength) { $0.pixelLength }
}
}

@available(OpenSwiftUI_v1_0, *)
extension EnvironmentValues {
/// The display scale of this environment.
public var displayScale: CGFloat {
Expand All @@ -40,31 +69,130 @@ extension EnvironmentValues {
}
}

extension CachedEnvironment.ID {
package static let pixelLength: CachedEnvironment.ID = .init()
// MARK: - EnvironmentValues + ? [6.4.41]

private struct LocaleKey: EnvironmentKey {
static let defaultValue: Locale = Locale(identifier: "")
}

extension _ViewInputs {
package var pixelLength: Attribute<CGFloat> {
mapEnvironment(id: .pixelLength) { $0.pixelLength }
}
private struct TimeZoneKey: EnvironmentKey {
static let defaultValue: TimeZone = .autoupdatingCurrent
}

private struct CalendarKey: EnvironmentKey {
static let defaultValue: Calendar = .autoupdatingCurrent
}

private struct DisplayGamutKey: EnvironmentKey {
static var defaultValue: DisplayGamut { .sRGB }
}

@available(OpenSwiftUI_v1_0, *)
extension EnvironmentValues {
@_spi(Private)
@available(OpenSwiftUI_v3_0, *)
public var dividerThickness: CGFloat {
get { _openSwiftUIUnimplementedFailure() }
set { _openSwiftUIUnimplementedFailure() }
}

// package var defaultRenderingMode: Image.TemplateRenderingMode {
// get { _openSwiftUIUnimplementedFailure() }
// set { _openSwiftUIUnimplementedFailure() }
// }

@_spi(ClarityBoard)
@available(OpenSwiftUI_v4_0, *)
@available(macOS, unavailable)
@available(tvOS, unavailable)
@available(watchOS, unavailable)
@available(macCatalyst, unavailable)
public var displayCornerRadius: CGFloat? {
get { _openSwiftUIUnimplementedFailure() }
set { _openSwiftUIUnimplementedFailure() }
}

/// The font weight to apply to text.
///
/// This value reflects the value of the Bold Text display setting found in
/// the Accessibility settings.
// public var legibilityWeight: LegibilityWeight? {
// get { _openSwiftUIUnimplementedFailure() }
// set { _openSwiftUIUnimplementedFailure() }
// }

/// The current locale that views should use.
public var locale: Locale {
get { self[LocaleKey.self] }
set { self[LocaleKey.self] = newValue }
}

/// The current calendar that views should use when handling dates.
public var calendar: Calendar {
get { self[CalendarKey.self] }
set { self[CalendarKey.self] = newValue }
}

/// The current time zone that views should use when handling dates.
public var timeZone: TimeZone {
get { self[TimeZoneKey.self] }
set { self[TimeZoneKey.self] = newValue }
}

@_spi(Private)
@available(OpenSwiftUI_v3_0, *)
public var displayGamut: DisplayGamut {
get { self[DisplayGamutKey.self] }
set { self[DisplayGamutKey.self] = newValue }
}

// @available(iOS, unavailable)
// @available(macOS, deprecated, message: "Use `EnvironmentValues.appearsActive` instead.")
// @available(tvOS, unavailable)
// @available(watchOS, unavailable)
// @available(visionOS, unavailable)
// public var controlActiveState: ControlActiveState {
// get { _openSwiftUIUnimplementedFailure() }
// set { _openSwiftUIUnimplementedFailure() }
// }
//
// @available(OpenSwiftUI_v1_0, *)
// public var horizontalSizeClass: UserInterfaceSizeClass? {
// get { _openSwiftUIUnimplementedFailure() }
// set { _openSwiftUIUnimplementedFailure() }
// }
//
// @available(OpenSwiftUI_v1_0, *)
// @usableFromInline
// var realHorizontalSizeClass: UserInterfaceSizeClass? {
// get { _openSwiftUIUnimplementedFailure() }
// set { _openSwiftUIUnimplementedFailure() }
// }
//
// @available(OpenSwiftUI_v1_0, *)
// public var verticalSizeClass: UserInterfaceSizeClass? {
// get { _openSwiftUIUnimplementedFailure() }
// set { _openSwiftUIUnimplementedFailure() }
// }
//
// @available(OpenSwiftUI_v1_0, *)
// @usableFromInline
// var realVerticalSizeClass: UserInterfaceSizeClass? {
// get { _openSwiftUIUnimplementedFailure() }
// set { _openSwiftUIUnimplementedFailure() }
// }
}

// MARK: - EnvironmentValues + Vibrant

struct AllowsVibrantBlendingKey: EnvironmentKey {
static var defaultValue: Bool? { nil }
}

private struct ReduceDesktopTintingKey: EnvironmentKey {
static var defaultValue: Bool { false }
}

extension EnvironmentValues {
package var allowsVibrantBlending: Bool {
get { self[AllowsVibrantBlendingKey.self] ?? true }
Expand All @@ -77,15 +205,53 @@ extension EnvironmentValues {
@available(watchOS, unavailable)
@available(visionOS, unavailable)
public var _useVibrantStyling: Bool {
get { _openSwiftUIUnimplementedFailure() }
set { _openSwiftUIUnimplementedFailure() }
get { backgroundMaterial != nil }
set {
if newValue {
backgroundMaterial = nil
} else {
backgroundMaterial = .regular
}
}
}

@available(OpenSwiftUI_v3_0, *)
@available(iOS, unavailable)
@available(tvOS, unavailable)
@available(watchOS, unavailable)
package var reduceDesktopTinting: Bool {
get { _openSwiftUIUnimplementedFailure() }
set { _openSwiftUIUnimplementedFailure() }
get { self[ReduceDesktopTintingKey.self] }
set { self[ReduceDesktopTintingKey.self] = newValue }
}
}

// MARK: - EnvironmentValues + Typography

private struct DefaultKerningKey: EnvironmentKey {
static let defaultValue: CGFloat = .zero
}

private struct DefaultTrackingKey: EnvironmentKey {
static let defaultValue: CGFloat = .zero
}

private struct DefaultBaselineOffsetKey: EnvironmentKey {
static let defaultValue: CGFloat = .zero
}

extension EnvironmentValues {
package var defaultKerning: CGFloat {
get { self[DefaultKerningKey.self] }
set { self[DefaultKerningKey.self] = newValue }
}

package var defaultTracking: CGFloat {
get { self[DefaultTrackingKey.self] }
set { self[DefaultTrackingKey.self] = newValue }
}

package var defaultBaselineOffset: CGFloat {
get { self[DefaultBaselineOffsetKey.self] }
set { self[DefaultBaselineOffsetKey.self] = newValue }
}
}
2 changes: 2 additions & 0 deletions Sources/OpenSwiftUICore/Shape/ShapeStyle/Material.swift
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,8 @@ public struct Material: Sendable {

extension Material: ShapeStyle {
// FIXME

static let regular = Material(id: .regular)
}

package struct ForegroundMaterialStyle: ShapeStyle, PrimitiveShapeStyle {
Expand Down