|
| 1 | +// |
| 2 | +// Divider.swift |
| 3 | +// OpenSwiftUI |
| 4 | +// |
| 5 | +// Audited for 6.5.4 |
| 6 | +// Status: Complete |
| 7 | +// ID: A41482AADD0929733C3343B5E142E952 (SwiftUI) |
| 8 | + |
| 9 | +import OpenAttributeGraphShims |
| 10 | +@_spi(ForOpenSwiftUIOnly) |
| 11 | +public import OpenSwiftUICore |
| 12 | + |
| 13 | +// MARK: - Divider |
| 14 | + |
| 15 | +/// A visual element that can be used to separate other content. |
| 16 | +/// |
| 17 | +/// When contained in a stack, the divider extends across the minor axis of the |
| 18 | +/// stack, or horizontally when not in a stack. |
| 19 | +@available(OpenSwiftUI_v1_0, *) |
| 20 | +public struct Divider: View, UnaryView, PrimitiveView { |
| 21 | + |
| 22 | + public init() { |
| 23 | + _openSwiftUIEmptyStub() |
| 24 | + } |
| 25 | + |
| 26 | + nonisolated public static func _makeView( |
| 27 | + view: _GraphValue<Self>, |
| 28 | + inputs: _ViewInputs |
| 29 | + ) -> _ViewOutputs { |
| 30 | + var newInputs = inputs |
| 31 | + if inputs.preferences.requiresPlatformItemList { |
| 32 | + newInputs.preferences.requiresPlatformItemList = false |
| 33 | + newInputs.requestedTextRepresentation = nil |
| 34 | + } |
| 35 | + let orientation = inputs.stackOrientation |
| 36 | + let child = Attribute( |
| 37 | + Child( |
| 38 | + orientation: orientation, |
| 39 | + dynamicOrientation: orientation == nil ? inputs.dynamicStackOrientation : .init() |
| 40 | + ) |
| 41 | + ) |
| 42 | + var outputs = ResolvedDivider.makeDebuggableView( |
| 43 | + view: .init(child), |
| 44 | + inputs: newInputs |
| 45 | + ) |
| 46 | + if let representation = inputs.requestedDividerRepresentation, |
| 47 | + representation.shouldMakeRepresentation(inputs: inputs) { |
| 48 | + representation.makeRepresentation(inputs: inputs, outputs: &outputs) |
| 49 | + } |
| 50 | + return outputs |
| 51 | + } |
| 52 | + |
| 53 | + private struct Child: Rule { |
| 54 | + var orientation: Axis? |
| 55 | + @OptionalAttribute var dynamicOrientation: Axis?? |
| 56 | + |
| 57 | + var value: ResolvedDivider { |
| 58 | + let axis: Axis |
| 59 | + if let orientation { |
| 60 | + axis = orientation |
| 61 | + } else if let dynamicOrientation { |
| 62 | + axis = dynamicOrientation ?? .vertical |
| 63 | + } else { |
| 64 | + axis = .vertical |
| 65 | + } |
| 66 | + return ResolvedDivider(configuration: .init(orientation: axis.otherAxis)) |
| 67 | + } |
| 68 | + } |
| 69 | +} |
| 70 | + |
| 71 | +@available(*, unavailable) |
| 72 | +extension Divider: Sendable {} |
| 73 | + |
| 74 | +// MARK: - PlatformDividerRepresentable |
| 75 | + |
| 76 | +package protocol PlatformDividerRepresentable { |
| 77 | + static func shouldMakeRepresentation( |
| 78 | + inputs: _ViewInputs |
| 79 | + ) -> Bool |
| 80 | + |
| 81 | + static func makeRepresentation( |
| 82 | + inputs: _ViewInputs, |
| 83 | + outputs: inout _ViewOutputs |
| 84 | + ) |
| 85 | +} |
| 86 | + |
| 87 | +extension _ViewInputs { |
| 88 | + package var requestedDividerRepresentation: (any PlatformDividerRepresentable.Type)? { |
| 89 | + get { base.requestedDividerRepresentation } |
| 90 | + set { base.requestedDividerRepresentation = newValue } |
| 91 | + } |
| 92 | +} |
| 93 | + |
| 94 | +extension _GraphInputs { |
| 95 | + private struct DividerRepresentationKey: GraphInput { |
| 96 | + static var defaultValue: (any PlatformDividerRepresentable.Type)? { nil } |
| 97 | + } |
| 98 | + |
| 99 | + package var requestedDividerRepresentation: (any PlatformDividerRepresentable.Type)? { |
| 100 | + get { self[DividerRepresentationKey.self] } |
| 101 | + set { self[DividerRepresentationKey.self] = newValue } |
| 102 | + } |
| 103 | +} |
0 commit comments