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

Braze Content card with top aligned image #1355

Merged
merged 4 commits into from
Jun 28, 2024
Merged
Changes from 1 commit
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 @@ -12,6 +12,7 @@ public class BrazePromotionView: UIView {
public enum ImagePosition {
case left
case right
case top
}

private lazy var backgroundView: UIView = {
Expand Down Expand Up @@ -155,6 +156,7 @@ public class BrazePromotionView: UIView {
public enum CardStyle: String, Sendable {
case defaultStyle = "default"
case leftAlignedGraphic = "leftAlignedGraphic"
case topAlignedGraphic = "topAlignedGraphic"
}

public weak var delegate: BrazePromotionViewDelegate?
Expand All @@ -164,8 +166,9 @@ public class BrazePromotionView: UIView {
public init(viewModel: BrazePromotionViewModel, imageDatasource: RemoteImageViewDataSource) {
self.viewModel = viewModel
self.imageDatasource = imageDatasource
self.imagePosition = (viewModel.style == .defaultStyle) ? .right : .left
self.imagePosition = .right // default value
super.init(frame: .zero)
determineImagePosition()
setup()
configure()
}
Expand All @@ -174,6 +177,17 @@ public class BrazePromotionView: UIView {
fatalError("init(coder:) has not been implemented")
}

private func determineImagePosition() {
switch viewModel.style {
case .defaultStyle:
self.imagePosition = .right
case .leftAlignedGraphic:
self.imagePosition = .left
case .topAlignedGraphic:
self.imagePosition = .top
teddyfahi marked this conversation as resolved.
Show resolved Hide resolved
}
}

private func configure() {
titleLabel.text = viewModel.title
primaryButton.configure(withTitle: viewModel.primaryButtonTitle)
Expand Down Expand Up @@ -234,6 +248,22 @@ public class BrazePromotionView: UIView {
remoteImageView.trailingAnchor.constraint(equalTo: backgroundView.trailingAnchor),
remoteImageView.bottomAnchor.constraint(equalTo: backgroundView.bottomAnchor)
]

case .top:
stackViewConstraintsImage = [
verticalStackView.topAnchor.constraint(equalTo: remoteImageView.bottomAnchor, constant: .spacingM),
verticalStackView.leadingAnchor.constraint(equalTo: backgroundView.leadingAnchor, constant: .spacingM),
verticalStackView.trailingAnchor.constraint(equalTo: backgroundView.trailingAnchor, constant: -.spacingM),
verticalStackView.bottomAnchor.constraint(equalTo: backgroundView.bottomAnchor, constant: -.spacingM)
]

imageConstraints = [
remoteImageView.widthAnchor.constraint(equalTo: backgroundView.widthAnchor),
remoteImageView.topAnchor.constraint(equalTo: backgroundView.topAnchor),
remoteImageView.leadingAnchor.constraint(equalTo: backgroundView.leadingAnchor),
remoteImageView.trailingAnchor.constraint(equalTo: backgroundView.trailingAnchor),
remoteImageView.heightAnchor.constraint(equalTo: remoteImageView.widthAnchor, multiplier: 0.5)
]
}

NSLayoutConstraint.activate(stackViewConstraintsImage + imageConstraints)
Expand Down Expand Up @@ -329,3 +359,4 @@ private class CloseButton: UIButton {
bounds.insetBy(dx: -touchPointInset, dy: -touchPointInset).contains(point)
}
}