Skip to content

Commit

Permalink
MOB-9982 Embedded messaging crash when image fails to load (#897)
Browse files Browse the repository at this point in the history
  • Loading branch information
joaodordio authored Feb 11, 2025
1 parent 584f3ae commit 7eab80a
Showing 1 changed file with 36 additions and 40 deletions.
76 changes: 36 additions & 40 deletions swift-sdk/ui-components/uikit/IterableEmbeddedView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import Foundation
import UIKit

@IBDesignable
public class IterableEmbeddedView:UIView {
public class IterableEmbeddedView: UIView {

/// Set background color of view in container view.
@IBOutlet weak public var contentView: UIView!
Expand All @@ -32,8 +32,8 @@ public class IterableEmbeddedView:UIView {
@IBOutlet weak var horizontalButtonStackViewSpacer: UIView!

/// IterableEmbeddedView Image View.
@IBOutlet weak public var imgView: UIImageView!
@IBOutlet weak public var cardImageView: UIImageView!
@IBOutlet weak public var imgView: UIImageView?
@IBOutlet weak public var cardImageView: UIImageView?
@IBOutlet var cardImageTopConstraint: NSLayoutConstraint!
@IBOutlet var titleToTopConstraint: NSLayoutConstraint!

Expand Down Expand Up @@ -274,46 +274,42 @@ public class IterableEmbeddedView:UIView {

private func loadViewType(viewType: IterableEmbeddedViewType) {
switch viewType {
case .card:
imgView.isHidden = true
let shouldShowCardImageView = EMimage != nil
if shouldShowCardImageView {
// Show cardImageView
cardImageView.image = EMimage
cardImageView.isHidden = false
cardImageTopConstraint.isActive = true
titleToTopConstraint.isActive = false
titleToTopConstraint?.isActive = false
} else {
// Hide cardImageView and deactivate its constraints
cardImageView.isHidden = true
cardImageTopConstraint.isActive = false
titleToTopConstraint.isActive = true
titleToTopConstraint?.isActive = true

// Remove cardImageView from its superview and release it
cardImageView.removeFromSuperview()
cardImageView = nil
}
case .banner:
imgView.isHidden = EMimage == nil
imgView.isHidden = self.EMimage == nil
imgView.image = EMimage
if !imgView.isHidden {
imgView.widthAnchor.constraint(equalToConstant: 100).isActive = true
}
cardImageView.isHidden = true
cardImageTopConstraint.isActive = false
titleToTopConstraint.isActive = true
cardImageTopConstraint?.isActive = false
titleToTopConstraint?.isActive = true
case .notification:
imgView.isHidden = true
cardImageView.isHidden = true
case .card:
imgView?.isHidden = true
let shouldShowCardImageView = EMimage != nil
if shouldShowCardImageView {
// Show cardImageView
cardImageView?.image = EMimage
cardImageView?.isHidden = false
cardImageTopConstraint.isActive = true
titleToTopConstraint.isActive = false
titleToTopConstraint?.isActive = false
} else {
// Hide cardImageView and deactivate its constraints
cardImageView?.isHidden = true
cardImageTopConstraint.isActive = false
titleToTopConstraint.isActive = true
cardImageTopConstraint?.isActive = false
titleToTopConstraint?.isActive = true
}
case .banner:
imgView?.isHidden = EMimage == nil
imgView?.isHidden = self.EMimage == nil
imgView?.image = EMimage
if let imageView = imgView, !imageView.isHidden {
imgView?.widthAnchor.constraint(equalToConstant: 100).isActive = true
}
cardImageView?.isHidden = true
cardImageTopConstraint.isActive = false
titleToTopConstraint.isActive = true
cardImageTopConstraint?.isActive = false
titleToTopConstraint?.isActive = true
case .notification:
imgView?.isHidden = true
cardImageView?.isHidden = true
cardImageTopConstraint.isActive = false
titleToTopConstraint.isActive = true
cardImageTopConstraint?.isActive = false
titleToTopConstraint?.isActive = true
}
}

Expand Down

0 comments on commit 7eab80a

Please sign in to comment.