Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add to Dock - Add extra custom view to Contextual Dialog Content #1043

Merged
merged 1 commit into from
Oct 31, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public struct ContextualDaxDialogContent: View {
public let message: NSAttributedString
let list: [ContextualOnboardingListItem]
let listAction: ((_ item: ContextualOnboardingListItem) -> Void)?
let imageName: String?
let customView: AnyView?
let customActionView: AnyView?
let orientation: Orientation

Expand All @@ -54,7 +54,7 @@ public struct ContextualDaxDialogContent: View {
messageFont: Font? = nil,
list: [ContextualOnboardingListItem] = [],
listAction: ((_: ContextualOnboardingListItem) -> Void)? = nil,
imageName: String? = nil,
customView: AnyView? = nil,
customActionView: AnyView? = nil
) {
self.title = title
Expand All @@ -63,7 +63,7 @@ public struct ContextualDaxDialogContent: View {
self.messageFont = messageFont
self.list = list
self.listAction = listAction
self.imageName = imageName
self.customView = customView
self.customActionView = customActionView
self.orientation = orientation

Expand All @@ -75,8 +75,8 @@ public struct ContextualDaxDialogContent: View {
if !list.isEmpty {
itemsToAnimate.append(.list)
}
if imageName != nil {
itemsToAnimate.append(.image)
if customView != nil {
itemsToAnimate.append(.customView)
}
if customActionView != nil {
itemsToAnimate.append(.button)
Expand Down Expand Up @@ -124,8 +124,8 @@ public struct ContextualDaxDialogContent: View {
VStack(alignment: .leading, spacing: 16) {
listView
.visibility(nonTypingAnimatableItems.contains(.list) ? .visible : .invisible)
imageView
.visibility(nonTypingAnimatableItems.contains(.image) ? .visible : .invisible)
extraView
.visibility(nonTypingAnimatableItems.contains(.customView) ? .visible : .invisible)
actionView
.visibility(nonTypingAnimatableItems.contains(.button) ? .visible : .invisible)
}
Expand Down Expand Up @@ -166,13 +166,9 @@ public struct ContextualDaxDialogContent: View {
}

@ViewBuilder
private var imageView: some View {
if let imageName {
HStack {
Spacer()
Image(imageName)
Spacer()
}
private var extraView: some View {
if let customView {
customView
}
}

Expand All @@ -187,7 +183,7 @@ public struct ContextualDaxDialogContent: View {
case title
case message
case list
case image
case customView
case button
}
}
Expand All @@ -196,7 +192,7 @@ struct NonTypingAnimatableItems: OptionSet {
let rawValue: Int

static let list = NonTypingAnimatableItems(rawValue: 1 << 0)
static let image = NonTypingAnimatableItems(rawValue: 1 << 1)
static let customView = NonTypingAnimatableItems(rawValue: 1 << 1)
static let button = NonTypingAnimatableItems(rawValue: 1 << 2)
}

Expand Down Expand Up @@ -225,8 +221,8 @@ extension ContextualDaxDialogContent {
break
case .list:
nonTypingAnimatableItems.insert(.list)
case .image:
nonTypingAnimatableItems.insert(.image)
case .customView:
nonTypingAnimatableItems.insert(.customView)
case .button:
nonTypingAnimatableItems.insert(.button)
}
Expand Down Expand Up @@ -274,10 +270,18 @@ enum Metrics {

#Preview("Intro Dialog - title, text, image and button") {
let contextualText = NSMutableAttributedString(string: "Sabrina is the best\n\nBelieve me! ☝️")
let extraView = {
HStack {
Spacer()
Image("Sync-Desktop-New-128")
Spacer()
}
}()

return ContextualDaxDialogContent(
title: "Who is the best?",
message: contextualText,
imageName: "Sync-Desktop-New-128",
customView: AnyView(extraView),
customActionView: AnyView(Button("Got it!", action: {})))
.padding()
.preferredColorScheme(.light)
Expand Down
Loading