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
2 changes: 1 addition & 1 deletion Package.resolved

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

26 changes: 23 additions & 3 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@ let linkCoreUI = envBoolValue("LINK_COREUI", default: buildForDarwinPlatform &&
let linkCoreSVG = envBoolValue("LINK_CORESVG", default: buildForDarwinPlatform && !isSPIBuild)
let linkSFSymbols = envBoolValue("LINK_SFSYMBOLS", default: buildForDarwinPlatform && !isSPIBuild)
let linkBacklightServices = envBoolValue("LINK_BACKLIGHTSERVICES", default: buildForDarwinPlatform && !isSPIBuild)
let linkGestures = envBoolValue("LINK_GESTURES", default: buildForDarwinPlatform && !isSPIBuild && releaseVersion >= 2025)
// This should be disabled for UI test target due to link issue of Testing.
// Only enable for non-UI test targets.
let linkTesting = envBoolValue("LINK_TESTING")
Expand Down Expand Up @@ -289,6 +290,9 @@ if linkBacklightServices {
)
)
}
if linkGestures {
sharedSwiftSettings.append(.define("OPENSWIFTUI_LINK_GESTURES"))
}

if swiftUIRenderCondition {
sharedCSettings.append(.define("OPENSWIFTUI_SWIFTUI_RENDERER", .when(platforms: .darwinPlatforms)))
Expand Down Expand Up @@ -419,6 +423,10 @@ extension Target {
)
}

func addGesturesSettings() {
dependencies.append(.product(name: "Gestures", package: "DarwinPrivateFrameworks"))
}

func addOpenCombineSettings() {
dependencies.append(.product(name: "OpenCombine", package: "OpenCombine"))
dependencies.append(.product(name: "OpenCombineFoundation", package: "OpenCombine"))
Expand Down Expand Up @@ -837,12 +845,24 @@ if renderBoxCondition {
openSwiftUIBridgeTestTarget.addRBSettings()
}

if attributeGraphCondition || renderBoxCondition {
if linkGestures {
openSwiftUICoreTarget.addGesturesSettings()
openSwiftUITarget.addGesturesSettings()

openSwiftUISPITestTarget.addGesturesSettings()
openSwiftUICoreTestTarget.addGesturesSettings()
openSwiftUITestTarget.addGesturesSettings()
openSwiftUICompatibilityTestTarget.addGesturesSettings()
openSwiftUIBridgeTestTarget.addGesturesSettings()
}

if attributeGraphCondition || renderBoxCondition || linkGestures {
let release = EnvManager.shared.withDomain("DarwinPrivateFrameworks") {
envIntValue("TARGET_RELEASE", default: 2024)
}
package.platforms = switch release {
case 2024: [.iOS(.v18), .macOS(.v15), .macCatalyst(.v18), .tvOS(.v18), .watchOS(.v10), .visionOS(.v2)]
case 2025: [.iOS("26.0"), .macOS("26.0"), .macCatalyst("26.0"), .tvOS("26.0"), .watchOS("26.0"), .visionOS("26.0")]
default: nil
}
} else {
Expand Down Expand Up @@ -876,7 +896,7 @@ if useLocalDeps {
.package(path: "../OpenRenderBox"),
.package(path: "../OpenObservation"),
]
if attributeGraphCondition || renderBoxCondition || linkCoreUI || linkCoreSVG || linkSFSymbols || linkBacklightServices {
if attributeGraphCondition || renderBoxCondition || linkCoreUI || linkCoreSVG || linkSFSymbols || linkBacklightServices || linkGestures {
dependencies.append(.package(path: "../DarwinPrivateFrameworks"))
}
package.dependencies += dependencies
Expand All @@ -888,7 +908,7 @@ if useLocalDeps {
.package(url: "https://github.com/OpenSwiftUIProject/OpenRenderBox", branch: "main"),
.package(url: "https://github.com/OpenSwiftUIProject/OpenObservation", branch: "main"),
]
if attributeGraphCondition || renderBoxCondition || linkCoreUI || linkCoreSVG || linkSFSymbols {
if attributeGraphCondition || renderBoxCondition || linkCoreUI || linkCoreSVG || linkSFSymbols || linkGestures {
dependencies.append(.package(url: "https://github.com/OpenSwiftUIProject/DarwinPrivateFrameworks.git", branch: "main"))
}
package.dependencies += dependencies
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,10 +112,6 @@ extension PreferencesOutputs {
}
}

// TODO: - View + truePreference

// TODO: - Gesture + truePreference

// MARK: - HostPreferencesWriter

private struct HostPreferencesWriter<K>: StatefulRule, AsyncAttribute, CustomStringConvertible where K: PreferenceKey {
Expand Down Expand Up @@ -167,3 +163,62 @@ private struct HostPreferencesWriter<K>: StatefulRule, AsyncAttribute, CustomStr
"Preference: \(K.readableName)"
}
}

// MARK: - View + truePreference

@available(OpenSwiftUI_v1_0, *)
extension View {
@MainActor
@preconcurrency
package func truePreference<K>(_ key: K.Type = K.self) -> some View where K: PreferenceKey, K.Value == Bool {
modifier(TruePreferenceWritingModifier<K>())
}
}

// MARK: - TruePreferenceWritingModifier

private struct TruePreferenceWritingModifier<K>: ViewModifier, MultiViewModifier, PrimitiveViewModifier where K: PreferenceKey, K.Value == Bool {
nonisolated static func _makeView(
modifier: _GraphValue<Self>,
inputs: _ViewInputs,
body: @escaping (_Graph, _ViewInputs) -> _ViewOutputs
) -> _ViewOutputs {
var outputs = body(_Graph(), inputs)
outputs.preferences.makePreferenceWriter(
inputs: inputs.preferences,
key: K.self,
value: inputs.intern(true, id: .trueValue)
)
return outputs
}
}

// MARK: - Gesture + truePreference

extension Gesture {
package func truePreference<K>(_ key: K.Type = K.self) -> some Gesture<Value> where K: PreferenceKey, K.Value == Bool {
modifier(TruePreferenceWritingGestureModifier<K, Value>())
}
}

// MARK: - TruePreferenceWritingGestureModifier

private struct TruePreferenceWritingGestureModifier<K, GestureValue>: GestureModifier where K: PreferenceKey, K.Value == Bool {
static func _makeGesture(
modifier: _GraphValue<TruePreferenceWritingGestureModifier<K, GestureValue>>,
inputs: _GestureInputs,
body: (_GestureInputs) -> _GestureOutputs<GestureValue>
) -> _GestureOutputs<GestureValue> {
var outputs = body(inputs)
outputs.preferences.makePreferenceWriter(
inputs: inputs.preferences,
key: K.self,
value: inputs.intern(true, id: .trueValue)
)
return outputs
}

typealias Value = GestureValue

typealias BodyValue = GestureValue
}
12 changes: 6 additions & 6 deletions Sources/OpenSwiftUICore/Data/Update.swift
Original file line number Diff line number Diff line change
Expand Up @@ -231,12 +231,12 @@ package enum Update {
// FIXME
package enum CustomEventTrace {
package enum ActionEventType {
package enum Reason {
case onAppear
case onChange
case onDisappear
case gesture
case didReleaseButton
package enum Reason: UInt32 {
case onAppear = 65
case onChange = 67
case onDisappear = 68
case gesture = 71
case didReleaseButton = 82
}
}
}
3 changes: 2 additions & 1 deletion Sources/OpenSwiftUICore/Event/Gesture/AnyGesture.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@
// AnyGesture.swift
// OpenSwiftUICore
//
// Audited for 6.5.4
// Status: Complete
// ID: 9726BF9F3BA5F571B5F201AD7C8C86F0 (SwiftUICore)

import OpenAttributeGraphShims

// MARK: - AnyGesture [6.5.4]
// MARK: - AnyGesture

/// A type-erased gesture.
@available(OpenSwiftUI_v1_0, *)
Expand Down
Loading
Loading