Skip to content
This repository has been archived by the owner on Sep 24, 2024. It is now read-only.

Commit

Permalink
fix: 🐛 showing the first 11 Quick replies only
Browse files Browse the repository at this point in the history
previously all the Quick reply buttons were visible. However, UX
guidelines for Web Client limits the number of visible Quick Replies.
Hence, restricting number of visible Quick replies to 11 to be
consistent

JIRA: SAPMLCONV-22301
  • Loading branch information
MarcoEidinger committed Aug 6, 2021
1 parent 4995e46 commit 9a1027b
Showing 1 changed file with 19 additions and 5 deletions.
24 changes: 19 additions & 5 deletions Sources/SAPCAI/UI/MessageView/QuickRepliesMessageView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,20 +18,26 @@ struct QuickRepliesMessageView: View {
assertionFailure("only use `QuickRepliesMessageView` with message type `quickReplies`")
return nil
}

var amountOfButtons: Int {
let limitForVisibleButtons = 11
guard let amountOfButtons = buttons?.buttonsData?.count else { return 0 }
return (amountOfButtons >= limitForVisibleButtons) ? limitForVisibleButtons : amountOfButtons
}

private var padding: CGFloat {
self.themeManager.value(for: .containerLTPadding, type: CGFloat.self, defaultValue: 0)
}

var body: some View {
VStack(alignment: .leading, spacing: vSizeClass == .compact ? 2 : 4) {
BotTextView(value: NSAttributedString(string: buttons!.buttonText!), isMarkdown: false, geometry: geometry)
BotTextView(value: NSAttributedString(string: buttons?.buttonText ?? ""), isMarkdown: false, geometry: geometry)

if buttons!.buttonsData != nil {
if let buttons = buttons, let buttonsData = buttons.buttonsData {
ScrollView(.horizontal, showsIndicators: false) {
HStack(alignment: .center, spacing: 8) {
ForEach(self.buttons!.buttonsData!, id: \.id) { button in
QuickReplyButtonView(button: button)
ForEach(0 ..< amountOfButtons) { i in
QuickReplyButtonView(button: buttonsData[i])
}
}
.padding([.top, .bottom], 1)
Expand All @@ -45,9 +51,17 @@ struct QuickRepliesMessageView: View {

#if DEBUG
struct QuickRepliesMessageView_Previews: PreviewProvider {
static func testData(amountOfButtons: Int) -> CAIResponseMessageData {
var buttons: [UIModelDataAction] = []
for i in 1 ... amountOfButtons {
buttons.append(UIModelDataAction("\(i)", "\(i)", .text))
}
return CAIResponseMessageData(text: "Show up to limitForVisibleButtons", buttons, buttonType: .quickReplies)
}

static var previews: some View {
GeometryReader { geometry in
QuickRepliesMessageView(model: testData.model[0], geometry: geometry)
QuickRepliesMessageView(model: QuickRepliesMessageView_Previews.testData(amountOfButtons: 15), geometry: geometry).environmentObject(ThemeManager.shared)
}
}
}
Expand Down

0 comments on commit 9a1027b

Please sign in to comment.