Skip to content

Commit

Permalink
Add extra custom view to Contextual Dialog Content
Browse files Browse the repository at this point in the history
  • Loading branch information
alessandroboron committed Oct 31, 2024
1 parent 5159f25 commit a93a0f7
Showing 1 changed file with 23 additions and 19 deletions.
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

0 comments on commit a93a0f7

Please sign in to comment.