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
52 changes: 49 additions & 3 deletions Sources/OpenSwiftUI/Event/Focus/FocusEventProxy.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,58 @@
// OpenSwiftUI
//
// Audited for 6.5.4
// Status: WIP
// Status: Complete
// ID: 220887A402CE7023D01D5BCC1E080716 (SwiftUI)

import OpenAttributeGraphShims
@_spi(ForOpenSwiftUIOnly)
import OpenSwiftUICore

// MARK: - FocusEventProxyResponder [TBA]
// MARK: - FocusEventProxyResponder

class FocusEventProxyResponder: DefaultLayoutViewResponder {}
private class FocusEventProxyResponder: DefaultLayoutViewResponder {}

@inline(__always)
func asFocusEventProxyResponder(_ responder: ResponderNode) -> ViewResponder? {
responder as? FocusEventProxyResponder
}

#if os(iOS) || os(visionOS)
// MARK: - FocusEventProxyModifier

struct FocusEventProxyModifier: MultiViewModifier, PrimitiveViewModifier {
Comment thread
Kyle-Ye marked this conversation as resolved.
static func _makeView(
modifier: _GraphValue<Self>,
inputs: _ViewInputs,
body: @escaping (_Graph, _ViewInputs) -> _ViewOutputs
) -> _ViewOutputs {
var outputs = body(_Graph(), inputs)
guard IOSFocusEnabledFlag.evaluate(inputs: inputs.base),
inputs.preferences.requiresViewResponders else {
return outputs
}
outputs.preferences.viewResponders = Attribute(FocusEventProxyResponderFilter(
children: outputs.viewResponders(),
responder: FocusEventProxyResponder(inputs: inputs)
))
return outputs
}
}

// MARK: - FocusEventProxyResponderFilter

private struct FocusEventProxyResponderFilter: StatefulRule {
@Attribute var children: [ViewResponder]

let responder: FocusEventProxyResponder

typealias Value = [ViewResponder]

mutating func updateValue() {
responder.updateChildren($children.changedValue())
if !hasValue {
value = [responder]
}
}
}
#endif
2 changes: 1 addition & 1 deletion Sources/OpenSwiftUI/Event/Focus/Focusable.swift
Original file line number Diff line number Diff line change
Expand Up @@ -403,7 +403,7 @@ private class FocusableViewResponder: DefaultLayoutViewResponder, FocusResponder
var focusProxyResponder: ViewResponder? {
var result: ViewResponder?
visit { responder in
guard let responder = responder as? FocusEventProxyResponder else { return .next }
guard let responder = asFocusEventProxyResponder(responder) else { return .next }
result = responder
return .cancel
}
Expand Down
Loading