generated from StanfordBDHG/SwiftPackageTemplate
-
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
124 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
// | ||
// This source file is part of the Spezi open-source project | ||
// | ||
// SPDX-FileCopyrightText: 2024 Stanford University and the project authors (see CONTRIBUTORS.md) | ||
// | ||
// SPDX-License-Identifier: MIT | ||
// | ||
|
||
import SwiftUI | ||
|
||
|
||
/// Header view for Lists or Forms. | ||
/// | ||
/// A header view that can be used in List or Form views. | ||
public struct ListHeader<Image: View, Title: View, Instructions: View>: View { | ||
private let image: Image | ||
private let title: Title | ||
private let instructions: Instructions | ||
|
||
|
||
public var body: some View { | ||
VStack { | ||
VStack { | ||
image | ||
.foregroundColor(.accentColor) | ||
.symbolRenderingMode(.multicolor) | ||
.font(.custom("XXL", size: 50, relativeTo: .title)) | ||
.accessibilityHidden(true) | ||
title | ||
.accessibilityAddTraits(.isHeader) | ||
.font(.title) | ||
.bold() | ||
.padding(.bottom, 4) | ||
} | ||
.accessibilityElement(children: .combine) | ||
instructions | ||
.padding([.leading, .trailing], 25) | ||
} | ||
.multilineTextAlignment(.center) | ||
.frame(maxWidth: .infinity) | ||
} | ||
|
||
/// Create a new list header. | ||
/// - Parameters: | ||
/// - image: The image view. | ||
/// - title: The title view. | ||
public init(@ViewBuilder image: () -> Image, @ViewBuilder title: () -> Title) where Instructions == EmptyView { | ||
self.init(image: image, title: title) { | ||
EmptyView() | ||
} | ||
} | ||
|
||
/// Create a new list header. | ||
/// - Parameters: | ||
/// - image: The image view. | ||
/// - title: The title view. | ||
/// - instructions: The instructions subheadline. | ||
public init(@ViewBuilder image: () -> Image, @ViewBuilder title: () -> Title, @ViewBuilder instructions: () -> Instructions) { | ||
self.image = image() | ||
self.title = title() | ||
self.instructions = instructions() | ||
} | ||
|
||
/// Create a new list header. | ||
/// - Parameters: | ||
/// - systemImage: The name of the system symbol image. | ||
/// - title: The title view. | ||
public init(systemImage: String, @ViewBuilder title: () -> Title) where Image == SwiftUI.Image, Instructions == EmptyView { | ||
// swiftlint:disable:next accessibility_label_for_image | ||
self.init(image: { SwiftUI.Image(systemName: systemImage) }, title: title) { | ||
EmptyView() | ||
} | ||
} | ||
|
||
/// Create a new list header. | ||
/// - Parameters: | ||
/// - systemImage: The name of the system symbol image. | ||
/// - title: The title view. | ||
/// - instructions: The instructions subheadline. | ||
public init(systemImage: String, @ViewBuilder title: () -> Title, @ViewBuilder instructions: () -> Instructions) where Image == SwiftUI.Image { | ||
// swiftlint:disable:next accessibility_label_for_image | ||
self.init(image: { SwiftUI.Image(systemName: systemImage) }, title: title, instructions: instructions) | ||
} | ||
} | ||
|
||
|
||
#if DEBUG | ||
#Preview { | ||
List { | ||
ListHeader(systemImage: "person.fill.badge.plus") { | ||
Text("Create a new Account", bundle: .module) | ||
} instructions: { | ||
Text("Please fill out the details below to create your new account.", bundle: .module) | ||
} | ||
} | ||
} | ||
|
||
#Preview { | ||
List { | ||
ListHeader(systemImage: "person.fill.badge.plus") { | ||
Text("Create a new Account", bundle: .module) | ||
} | ||
} | ||
} | ||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file added
BIN
+89.3 KB
...wsTests/__Snapshots__/SnapshotTests/testListHeader.list-header-instructions.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+74.3 KB
Tests/SpeziViewsTests/__Snapshots__/SnapshotTests/testListHeader.list-header.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.