From 06ea8351cdc869281a327905b0c739cff2c868d3 Mon Sep 17 00:00:00 2001 From: Cyndi Chin Date: Fri, 7 Jun 2024 13:50:17 -0400 Subject: [PATCH] Add FXIOS-9284 [Microsurvey] Add icon to mobile messaging configs (#20563) --- .../Experiments/Messaging/GleanPlumbMessage.swift | 6 ++++++ .../Frontend/Microsurvey/MicrosurveyModel.swift | 1 + .../Microsurvey/MicrosurveySurfaceManager.swift | 4 +++- .../Survey/View/MicrosurveyTableHeaderView.swift | 13 +++++++------ .../Survey/View/MicrosurveyViewController.swift | 2 +- .../Microsurvey/MicrosurveyMockModel.swift | 3 ++- .../messaging/messaging-evergreen-messages.fml.yaml | 1 + .../nimbus-features/messaging/messaging.fml.yaml | 4 ++++ 8 files changed, 25 insertions(+), 9 deletions(-) diff --git a/firefox-ios/Client/Experiments/Messaging/GleanPlumbMessage.swift b/firefox-ios/Client/Experiments/Messaging/GleanPlumbMessage.swift index 0dc11557f159..5a8aa805f7a2 100644 --- a/firefox-ios/Client/Experiments/Messaging/GleanPlumbMessage.swift +++ b/firefox-ios/Client/Experiments/Messaging/GleanPlumbMessage.swift @@ -89,6 +89,12 @@ struct GleanPlumbMessage { var options: [String] { return data.microsurveyConfig?.options ?? [] } + + /// The icon for this message if it has a microsurvey configuration. + /// Embedding apps should not read from this directly. + var icon: UIImage? { + return data.microsurveyConfig?.icon + } } /// Public properties for this message. diff --git a/firefox-ios/Client/Frontend/Microsurvey/MicrosurveyModel.swift b/firefox-ios/Client/Frontend/Microsurvey/MicrosurveyModel.swift index b872ac69b282..ca95f6bc635c 100644 --- a/firefox-ios/Client/Frontend/Microsurvey/MicrosurveyModel.swift +++ b/firefox-ios/Client/Frontend/Microsurvey/MicrosurveyModel.swift @@ -9,4 +9,5 @@ struct MicrosurveyModel: Equatable { let promptButtonLabel: String let surveyQuestion: String let surveyOptions: [String] + let icon: UIImage? } diff --git a/firefox-ios/Client/Frontend/Microsurvey/MicrosurveySurfaceManager.swift b/firefox-ios/Client/Frontend/Microsurvey/MicrosurveySurfaceManager.swift index 4484372ece5d..86f7cf66fcd7 100644 --- a/firefox-ios/Client/Frontend/Microsurvey/MicrosurveySurfaceManager.swift +++ b/firefox-ios/Client/Frontend/Microsurvey/MicrosurveySurfaceManager.swift @@ -36,12 +36,14 @@ class MicrosurveySurfaceManager: MobileMessageSurfaceProtocol { ) let promptButtonLabel = message?.buttonLabel ?? .Microsurvey.Prompt.TakeSurveyButton let options: [String] = message?.options ?? defaultSurveyOptions + let icon = message?.icon return MicrosurveyModel( promptTitle: promptTitle, promptButtonLabel: promptButtonLabel, surveyQuestion: surveyQuestion, - surveyOptions: options + surveyOptions: options, + icon: icon ) } diff --git a/firefox-ios/Client/Frontend/Microsurvey/Survey/View/MicrosurveyTableHeaderView.swift b/firefox-ios/Client/Frontend/Microsurvey/Survey/View/MicrosurveyTableHeaderView.swift index 7755df738e2b..8ef0665b54f9 100644 --- a/firefox-ios/Client/Frontend/Microsurvey/Survey/View/MicrosurveyTableHeaderView.swift +++ b/firefox-ios/Client/Frontend/Microsurvey/Survey/View/MicrosurveyTableHeaderView.swift @@ -24,9 +24,7 @@ class MicrosurveyTableHeaderView: UITableViewHeaderFooterView, ReusableCell, The } private lazy var iconView: UIImageView = .build { imageView in - // TODO: FXIOS-9108: This image should come from the data source, based on the target feature imageView.contentMode = .scaleAspectFit - imageView.image = UIImage(named: StandardImageIdentifiers.Large.lightbulb)?.withRenderingMode(.alwaysTemplate) } private lazy var questionLabel: UILabel = .build { label in @@ -38,9 +36,7 @@ class MicrosurveyTableHeaderView: UITableViewHeaderFooterView, ReusableCell, The override init(reuseIdentifier: String?) { super.init(reuseIdentifier: reuseIdentifier) - if iconView.image != nil { - horizontalStackView.addArrangedSubview(iconView) - } + horizontalStackView.addArrangedSubview(iconView) horizontalStackView.addArrangedSubview(questionLabel) contentView.addSubview(horizontalStackView) @@ -73,8 +69,13 @@ class MicrosurveyTableHeaderView: UITableViewHeaderFooterView, ReusableCell, The fatalError("init(coder:) has not been implemented") } - func configure(_ text: String) { + func configure(_ text: String, icon: UIImage?) { questionLabel.text = text + guard let icon else { + horizontalStackView.removeArrangedView(iconView) + return + } + iconView.image = icon.withRenderingMode(.alwaysTemplate) } // MARK: - ThemeApplicable diff --git a/firefox-ios/Client/Frontend/Microsurvey/Survey/View/MicrosurveyViewController.swift b/firefox-ios/Client/Frontend/Microsurvey/Survey/View/MicrosurveyViewController.swift index 64c2681c1e25..2a237e66fb04 100644 --- a/firefox-ios/Client/Frontend/Microsurvey/Survey/View/MicrosurveyViewController.swift +++ b/firefox-ios/Client/Frontend/Microsurvey/Survey/View/MicrosurveyViewController.swift @@ -355,7 +355,7 @@ final class MicrosurveyViewController: UIViewController, ) as? MicrosurveyTableHeaderView else { return nil } - headerView.configure(model.surveyQuestion) + headerView.configure(model.surveyQuestion, icon: model.icon) headerView.applyTheme(theme: themeManager.currentTheme(for: windowUUID)) return headerView } diff --git a/firefox-ios/firefox-ios-tests/Tests/ClientTests/Microsurvey/MicrosurveyMockModel.swift b/firefox-ios/firefox-ios-tests/Tests/ClientTests/Microsurvey/MicrosurveyMockModel.swift index dc4914b438d6..6aae82ee2fcf 100644 --- a/firefox-ios/firefox-ios-tests/Tests/ClientTests/Microsurvey/MicrosurveyMockModel.swift +++ b/firefox-ios/firefox-ios-tests/Tests/ClientTests/Microsurvey/MicrosurveyMockModel.swift @@ -14,7 +14,8 @@ class MicrosurveyMock { surveyOptions: [ "yes", "no" - ] + ], + icon: nil ) } } diff --git a/firefox-ios/nimbus-features/messaging/messaging-evergreen-messages.fml.yaml b/firefox-ios/nimbus-features/messaging/messaging-evergreen-messages.fml.yaml index 9ab3fc94ac78..7f4446974835 100644 --- a/firefox-ios/nimbus-features/messaging/messaging-evergreen-messages.fml.yaml +++ b/firefox-ios/nimbus-features/messaging/messaging-evergreen-messages.fml.yaml @@ -64,6 +64,7 @@ import: text: "How satisfied are you with your Firefox homepage?" # Should not show this message if this is nil button-label: Microsurvey/Microsurvey.Prompt.Button.v127 microsurveyConfig: + icon: homeLarge options: - Microsurvey/Microsurvey.Survey.Options.LikertScaleOption1.v127 - Microsurvey/Microsurvey.Survey.Options.LikertScaleOption2.v127 diff --git a/firefox-ios/nimbus-features/messaging/messaging.fml.yaml b/firefox-ios/nimbus-features/messaging/messaging.fml.yaml index aa78bca05eca..614089b3e1c1 100644 --- a/firefox-ios/nimbus-features/messaging/messaging.fml.yaml +++ b/firefox-ios/nimbus-features/messaging/messaging.fml.yaml @@ -191,6 +191,10 @@ objects: description: > Attributes relating to microsurvey messaging. fields: + icon: + description: The asset name in our bundle used as the icon shown in the survey. + type: Image + default: lightbulbLarge options: description: The list of survey options to present to the user. type: List