Skip to content

Commit

Permalink
Braze Content card with top aligned image (#1355)
Browse files Browse the repository at this point in the history
* added top aligned image to content card style

* removed self not needed
  • Loading branch information
teddyfahi authored Jun 28, 2024
1 parent 98f859f commit 4c053b3
Showing 1 changed file with 32 additions and 1 deletion.
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:
imagePosition = .right
case .leftAlignedGraphic:
imagePosition = .left
case .topAlignedGraphic:
imagePosition = .top
}
}

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)
}
}

0 comments on commit 4c053b3

Please sign in to comment.