Skip to content

Commit

Permalink
Support WithPerceptionTracking in non-view contexts (#7)
Browse files Browse the repository at this point in the history
  • Loading branch information
stephencelis authored Jan 12, 2024
1 parent 0e9cb44 commit 7b2994f
Showing 1 changed file with 85 additions and 4 deletions.
89 changes: 85 additions & 4 deletions Sources/Perception/WithPerceptionTracking.swift
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,10 @@ public enum _PerceptionLocals {
@available(tvOS, deprecated: 17, message: "Remove WithPerceptionTracking")
@available(watchOS, deprecated: 10, message: "Remove WithPerceptionTracking")
@MainActor
public struct WithPerceptionTracking<Content: View>: View {
public struct WithPerceptionTracking<Content> {
@State var id = 0
let content: () -> Content
public init(@ViewBuilder content: @escaping () -> Content) {
self.content = content
}

public var body: Content {
if #available(iOS 17, macOS 14, tvOS 17, watchOS 10, *) {
return self.content()
Expand All @@ -76,3 +74,86 @@ public struct WithPerceptionTracking<Content: View>: View {
}
}
}

@available(iOS 15, macOS 12, tvOS 15, watchOS 8, *)
extension WithPerceptionTracking: AccessibilityRotorContent
where Content: AccessibilityRotorContent {
public init(@AccessibilityRotorContentBuilder content: @escaping () -> Content) {
self.content = content
}
}

@available(iOS 14, macOS 11, *)
@available(tvOS, unavailable)
@available(watchOS, unavailable)
extension WithPerceptionTracking: Commands where Content: Commands {
public init(@CommandsBuilder content: @escaping () -> Content) {
self.content = content
}
}

@available(iOS 14, macOS 11, tvOS 14, watchOS 7, *)
extension WithPerceptionTracking: CustomizableToolbarContent
where Content: CustomizableToolbarContent {
}

@available(iOS 14, macOS 11, tvOS 14, watchOS 7, *)
extension WithPerceptionTracking: Scene where Content: Scene {
public init(@SceneBuilder content: @escaping () -> Content) {
self.content = content
}
}

@available(iOS 16, macOS 12, *)
@available(tvOS, unavailable)
@available(watchOS, unavailable)
extension WithPerceptionTracking: TableColumnContent where Content: TableColumnContent {
public typealias TableRowValue = Content.TableRowValue
public typealias TableColumnSortComparator = Content.TableColumnSortComparator
public typealias TableColumnBody = Never

public init<R, C>(@TableColumnBuilder<R, C> content: @escaping () -> Content)
where R == Content.TableRowValue, C == Content.TableColumnSortComparator {
self.content = content
}

public var tableColumnBody: Never {
fatalError()
}

public static func _makeContent(
content: _GraphValue<WithPerceptionTracking<Content>>, inputs: _TableColumnInputs
) -> _TableColumnOutputs {
Content._makeContent(content: content[\.body], inputs: inputs)
}
}

@available(iOS 16, macOS 12, *)
@available(tvOS, unavailable)
@available(watchOS, unavailable)
extension WithPerceptionTracking: TableRowContent where Content: TableRowContent {
public typealias TableRowValue = Content.TableRowValue
public typealias TableRowBody = Never

public init<R>(@TableRowBuilder<R> content: @escaping () -> Content)
where R == Content.TableRowValue {
self.content = content
}

public var tableRowBody: Never {
fatalError()
}
}

@available(iOS 14, macOS 11, tvOS 14, watchOS 7, *)
extension WithPerceptionTracking: ToolbarContent where Content: ToolbarContent {
public init(@ToolbarContentBuilder content: @escaping () -> Content) {
self.content = content
}
}

extension WithPerceptionTracking: View where Content: View {
public init(@ViewBuilder content: @escaping () -> Content) {
self.content = content
}
}

0 comments on commit 7b2994f

Please sign in to comment.