diff --git a/CLAUDE.md b/CLAUDE.md index e7f2e39..28b31af 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -39,7 +39,7 @@ Sources/DashUIKit/ Geometry/ Layout readers + scale-to-fit helpers Icons/ Code-drawn icons (XmarkIcon, CheckmarkIcon, ChevronIcon, InfoRoundIcon) Illustrations/ Loading / success / error illustrations - Table List/ List1View (label/value row) + Table List/ List1View (label/value row), List8View (label/value row, optional avatar) ViewModifiers/ MenuViewModifier (card chrome) Foundation/ Color / Font / DashTextStyle / Image / line-height / Bundle Resources/ Media.xcassets (colors, icons, illustrations) diff --git a/README.md b/README.md index b378873..12a55da 100644 --- a/README.md +++ b/README.md @@ -81,6 +81,7 @@ a component already exists before building your own. | `MenuItem` | Settings/menu row with flexible trailing accessory | [Lists & rows](docs/lists-and-rows.md) | | `RadioButtonRow` | Selectable row — radio or checkbox style | [Lists & rows](docs/lists-and-rows.md) | | `List1View` | Simple label ↔ value row | [Lists & rows](docs/lists-and-rows.md) | +| `List8View` | Label ↔ value row with an optional avatar | [Lists & rows](docs/lists-and-rows.md) | | `NavigationBar` | Custom three-slot nav bar + `NavigationBarElement` buttons | [Navigation & containers](docs/navigation-and-containers.md) | | `BottomSheet` | Sheet chrome (grabber + nav bar) with self-sizing support | [Navigation & containers](docs/navigation-and-containers.md) | | `MenuViewModifier` | Card chrome — rounded background + shadow | [Navigation & containers](docs/navigation-and-containers.md) | @@ -99,7 +100,7 @@ a component already exists before building your own. Sources/DashUIKit/ Button/ DashButton Components/ Components (EnterAmount/, Geometry/, Icons/, Illustrations/) - Table List/ List1View + Table List/ List1View, List8View ViewModifiers/ MenuViewModifier Foundation/ Color / Font / typography / Image / Bundle helpers Resources/ Media.xcassets (colors, icons, illustrations) diff --git a/Sources/DashUIKit/Table List/List8View.swift b/Sources/DashUIKit/Table List/List8View.swift new file mode 100644 index 0000000..49d779f --- /dev/null +++ b/Sources/DashUIKit/Table List/List8View.swift @@ -0,0 +1,120 @@ +// +// Created by Roman Chornyi +// Copyright © 2026 Dash Core Group. All rights reserved. +// +// Licensed under the MIT License (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// https://opensource.org/licenses/MIT +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// + +import SwiftUI + +/// A label ↔ value row with an optional round avatar before the value — the design system's +/// `list-8`, for "who" rows such as the recipient on a payment confirmation. +/// +/// The avatar is the caller's view, laid out in a fixed 24 × 24 frame and clipped round; pass +/// a view that fills its frame (a `resizable()` image, a shape). It is hidden from VoiceOver, +/// which reads the row as one element, "label, value". Without one — `List8View(label:value:)`, +/// or a builder that produces no view (`EmptyView()`, an `if` without an `else`) — +/// the value stands alone at the trailing edge and the row takes no avatar space. A view that +/// produces something invisible (`Color.clear`) still takes the slot. +/// +/// Both texts stay on one line. When they do not fit together they share the width, so the +/// value never disappears behind a long label. The value truncates in the middle by default, +/// keeping the end of a username that may be what tells two recipients apart; pass +/// `truncationMode: .tail` for a display name. The value sets its own mode, so a +/// `.truncationMode(_:)` modifier on the row reaches only the label. +@available(iOS 14, macOS 11, *) +public struct List8View: View { + + public var label: String + public var value: String + public var truncationMode: Text.TruncationMode + private let avatar: Avatar + + public init( + label: String, + value: String, + truncationMode: Text.TruncationMode = .middle, + @ViewBuilder avatar: () -> Avatar + ) { + self.label = label + self.value = value + self.truncationMode = truncationMode + self.avatar = avatar() + } + + public var body: some View { + HStack(spacing: 0) { + Text(label) + .dashFont(.subheadMedium) + .foregroundColor(Color.dash.tertiaryText) + .lineLimit(1) + + Spacer(minLength: 20) + + HStack(spacing: 8) { + avatar + .frame(width: 24, height: 24) + .clipShape(Circle()) + .accessibilityHidden(true) + + Text(value) + .dashFont(.subhead) + .foregroundColor(Color.dash.primaryText) + .lineLimit(1) + .truncationMode(truncationMode) + } + } + .padding(.horizontal, 14) + .padding(.vertical, 12) + .accessibilityElement(children: .combine) + } +} + +@available(iOS 14, macOS 11, *) +public extension List8View where Avatar == EmptyView { + + /// A row without an avatar. + init(label: String, value: String, truncationMode: Text.TruncationMode = .middle) { + self.init(label: label, value: value, truncationMode: truncationMode) { EmptyView() } + } +} + +#if DEBUG + +@available(iOS 17, macOS 14, *) +#Preview("Every state") { + VStack(spacing: 0) { + List8View(label: "To", value: "username") { + Circle().fill(Color.dash.gray300) + } + List8View(label: "To", value: "username") + // An avatar builder that produces no view lays out like the no-avatar row above. + List8View(label: "To", value: "a-very-long-username-that-does-not-fit-the-row") { + if false { Circle().fill(Color.dash.gray300) } + } + List8View(label: "To", value: "Alexandra Konstantinopoulou-Whitfield of the Treasury Reserve", truncationMode: .tail) { + Circle().fill(Color.dash.gray300) + } + List8View(label: "To", value: "a-very-long-username-that-does-not-fit-the-row") { + Circle().fill(Color.dash.gray300) + } + List8View(label: "A longer translated label", value: "bob") { + Circle().fill(Color.dash.gray300) + } + List8View(label: "A longer translated label", value: "a-very-long-username") { + Circle().fill(Color.dash.gray300) + } + } +} + +#endif diff --git a/docs/README.md b/docs/README.md index dd05369..d8042f1 100644 --- a/docs/README.md +++ b/docs/README.md @@ -18,7 +18,7 @@ and callbacks; they render and report intent. They require `import DashUIKit` an `ReceiveEstimateView`, `DashAmount`, `DashBalanceView`, `DashPickerView`, `CurrencyOption`. - **[Lists & rows](lists-and-rows.md)** — `CoinSelector`, `MenuItem`, - `ConverterCard`, `TransactionView`, `RadioButtonRow`, `List1View`. + `ConverterCard`, `TransactionView`, `RadioButtonRow`, `List1View`, `List8View`. - **[Navigation & containers](navigation-and-containers.md)** — `NavigationBar`, `NavigationBarElement`, `TopIntroView`, `BottomSheet`, `MenuViewModifier`. - **[Feedback](feedback.md)** — `Toast`, `SystemMessageView`, @@ -53,6 +53,7 @@ and callbacks; they render and report intent. They require `import DashUIKit` an | `EnterAmountView` (`EnterAmountStyle`) | [Amount & currency](amount-and-currency.md#enteramountview) | | `ErrorIllustration` | [Feedback](feedback.md#successillustration--errorillustration) | | `List1View` | [Lists & rows](lists-and-rows.md#list1view) | +| `List8View` | [Lists & rows](lists-and-rows.md#list8view) | | `LoadingIllustration` / `LoadingSpinner` | [Feedback](feedback.md#loadingillustration--loadingspinner) | | `MenuItem` (`MenuItemAccessory`, `MenuItemInfo`) | [Lists & rows](lists-and-rows.md#menuitem) | | `MenuViewModifier` | [Navigation & containers](navigation-and-containers.md#menuviewmodifier) | diff --git a/docs/lists-and-rows.md b/docs/lists-and-rows.md index 8db289b..c75da4c 100644 --- a/docs/lists-and-rows.md +++ b/docs/lists-and-rows.md @@ -181,3 +181,42 @@ on the right (value is right-aligned and can wrap). Useful for detail / summary ```swift List1View(label: "Network", value: "Dash") ``` + +--- + +## List8View + +File `Table List/List8View.swift` · `@available(iOS 14, macOS 11, *)` + +A label ↔ value row with an optional round avatar before the value — for "who" rows, such as +the recipient on a payment confirmation. Generic over the avatar view, which the row lays out +in a fixed 24 × 24 frame and clips round; pass a view that fills its frame (a `resizable()` +image, a shape). The library does not load images itself. + +```swift +List8View(label: "To", value: "username") { + Image("avatar").resizable().scaledToFill() // @ViewBuilder avatar +} + +List8View(label: "To", value: "username") // no avatar + +List8View(label: "To", value: name) { // only some recipients have one + if let avatar { avatar.resizable().scaledToFill() } // avatar: Image? +} +``` + +A builder that produces no view (an `if` without an `else`, `EmptyView()`) takes no space: the +row lays out as if it had no avatar. A view that is merely invisible (`Color.clear`) still takes +the 24 pt slot. For an avatar that is still loading, draw a placeholder instead of nothing, or +the value moves 32 pt left when the image arrives. + +Both texts stay on one line. When they do not fit together they share the width, so the value +never disappears behind a long label. The value truncates in the middle by default +("alice-of…ments"), keeping the end of a username visible; pass `truncationMode: .tail` for a +display name ("Alexandra Kon…"). With an avatar, label and value are centred on it and +the row is 48 pt tall; without one it is the text's height plus 12 pt above and below. +VoiceOver reads the row as one element ("To, username") and skips the avatar. + +Without an avatar it differs from `List1View` on purpose: the value keeps one line (truncating, +in the middle by default) and the row is one VoiceOver element. Use `List8View` for a recipient or other +identifier, `List1View` for a value that should wrap.