Skip to content

Commit

Permalink
added top aligned image to content card style
Browse files Browse the repository at this point in the history
  • Loading branch information
teddyfahi committed Jun 24, 2024
1 parent 4f3bc8b commit 3e47a58
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:
self.imagePosition = .right
case .leftAlignedGraphic:
self.imagePosition = .left
case .topAlignedGraphic:
self.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 3e47a58

Please sign in to comment.