Skip to content

Commit

Permalink
Add FXIOS-9284 [Microsurvey] Add icon to mobile messaging configs (#2…
Browse files Browse the repository at this point in the history
  • Loading branch information
cyndichin committed Jun 7, 2024
1 parent b41ea57 commit 06ea835
Show file tree
Hide file tree
Showing 8 changed files with 25 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@ struct MicrosurveyModel: Equatable {
let promptButtonLabel: String
let surveyQuestion: String
let surveyOptions: [String]
let icon: UIImage?
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)

Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ class MicrosurveyMock {
surveyOptions: [
"yes",
"no"
]
],
icon: nil
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions firefox-ios/nimbus-features/messaging/messaging.fml.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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<Text>
Expand Down

0 comments on commit 06ea835

Please sign in to comment.