From e4aba928ecae069d5767c4deb0468a747dba2ea3 Mon Sep 17 00:00:00 2001 From: Andreas Bauer Date: Tue, 30 Jan 2024 14:16:56 -0800 Subject: [PATCH] Rethink naming --- .../Views/Layout/DynamicHStack.swift | 28 +++++++++---------- Sources/SpeziViews/Views/List/ListRow.swift | 15 +++++----- 2 files changed, 21 insertions(+), 22 deletions(-) diff --git a/Sources/SpeziViews/Views/Layout/DynamicHStack.swift b/Sources/SpeziViews/Views/Layout/DynamicHStack.swift index e2dc13e..bc27862 100644 --- a/Sources/SpeziViews/Views/Layout/DynamicHStack.swift +++ b/Sources/SpeziViews/Views/Layout/DynamicHStack.swift @@ -9,10 +9,10 @@ import SwiftUI -/// Access the alignment of a dynamic layout component. +/// Access the dynamic layout of a child view. /// /// Refer to the documentation of ``DynamicHStack`` on how to retrieve the current layout. -public enum Alignment { +public enum DynamicLayout { /// The layout is horizontal. case horizontal /// The layout is vertical. @@ -31,12 +31,12 @@ public enum Alignment { /// of the view. This check won't apply if the [`horizontalSizeClass`](https://developer.apple.com/documentation/swiftui/environmentvalues/horizontalsizeclass) /// is `regular` (not `compact`) or if the device is in landscape orientation (refer to [`UIDeviceOrientation`](https://developer.apple.com/documentation/uikit/uideviceorientation)). /// -/// ### Checking the current alignment +/// ### Checking the current layout /// -/// You can retrieve the current `DynamicHStack` alignment using the ``Alignment`` preference key. +/// You can retrieve the current `DynamicHStack` layout using the ``DynamicLayout`` preference key. /// This is useful if you want to conditionally change the layout of your View depending on the current /// layout of your content (e.g., only render a `Spacer` if the view is horizontally aligned). -/// You can retrieve the current alignment using the [`onPreferenceChange(_:perform:)`](https://developer.apple.com/documentation/swiftui/view/onpreferencechange(_:perform:)) +/// You can retrieve the current layout using the [`onPreferenceChange(_:perform:)`](https://developer.apple.com/documentation/swiftui/view/onpreferencechange(_:perform:)) /// modifier. /// /// Below is a short code example that demonstrates this capability. @@ -51,21 +51,21 @@ public enum Alignment { /// private let city: LocalizedStringResource /// private let temperature: Int /// -/// @State var currentAlignment: Alignment? +/// @State var currentLayout: DynamicLayout? /// /// var body: some View { /// DynamicHStack { /// Text(city) /// -/// if alignment == .horizontal { +/// if currentLayout == .horizontal { /// Spacer() /// } /// /// Text(verbatim: "\(temperature) °C") /// .foregroundColor(.secondary) /// } -/// .onPreferenceChange(Alignment.self) { alignment in -/// currentAlignment = alignment +/// .onPreferenceChange(DynamicLayout.self) { layout in +/// currentLayout = layout /// } /// } /// } @@ -73,8 +73,8 @@ public enum Alignment { /// /// ## Topics /// -/// ### Checking the current alignment -/// - ``Alignment`` +/// ### Checking the current layout +/// - ``DynamicLayout`` public struct DynamicHStack: View { private let realignAfter: DynamicTypeSize private let horizontalAlignment: VerticalAlignment @@ -96,12 +96,12 @@ public struct DynamicHStack: View { HStack(alignment: horizontalAlignment, spacing: spacing) { content } - .preference(key: Alignment.self, value: .horizontal) + .preference(key: DynamicLayout.self, value: .horizontal) } else { VStack(alignment: verticalAlignment, spacing: spacing) { content } - .preference(key: Alignment.self, value: .vertical) + . preference(key: DynamicLayout.self, value: .vertical) } } .observeOrientationChanges($orientation) @@ -131,7 +131,7 @@ public struct DynamicHStack: View { } -extension Alignment: PreferenceKey { +extension DynamicLayout: PreferenceKey { public typealias Value = Self? public static func reduce(value: inout Self?, nextValue: () -> Self?) { diff --git a/Sources/SpeziViews/Views/List/ListRow.swift b/Sources/SpeziViews/Views/List/ListRow.swift index 8bbff96..799b2f7 100644 --- a/Sources/SpeziViews/Views/List/ListRow.swift +++ b/Sources/SpeziViews/Views/List/ListRow.swift @@ -37,7 +37,7 @@ public struct ListRow: View { private let label: Label private let content: Content - @State private var alignment: Alignment? + @State private var layout: DynamicLayout? public var body: some View { @@ -45,25 +45,24 @@ public struct ListRow: View { DynamicHStack { label .foregroundColor(.primary) - .lineLimit(alignment == .horizontal ? 1 : nil) + .lineLimit(layout == .horizontal ? 1 : nil) - if alignment == .horizontal { + if layout == .horizontal { Spacer() } content - .lineLimit(alignment == .horizontal ? 1 : nil) + .lineLimit(layout == .horizontal ? 1 : nil) .layoutPriority(1) .foregroundColor(.secondary) } - if alignment == .vertical { + if layout == .vertical { Spacer() } } - // .accessibilityElement(children: .combine) - .onPreferenceChange(Alignment.self) { value in - alignment = value + .onPreferenceChange(DynamicLayout.self) { value in + layout = value } }