Skip to content

Commit

Permalink
MBX-2793 Fix first image
Browse files Browse the repository at this point in the history
  • Loading branch information
Akylbek Utekeshev committed Sep 8, 2023
1 parent 3169073 commit 12e6221
Show file tree
Hide file tree
Showing 7 changed files with 13 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,8 @@ final class InAppConfigutationMapper: InAppConfigurationMapperProtocol {

imageDictQueue.sync {
if !imageDict.isEmpty && !gotError {
formData = InAppFormData(inAppId: inapp.inAppId, imagesDict: imageDict, content: inapp.content)
let firstImageValue = imageValues.first ?? ""
formData = InAppFormData(inAppId: inapp.inAppId, imagesDict: imageDict, firstImageValue: firstImageValue, content: inapp.content)
}
}
}
Expand Down
1 change: 1 addition & 0 deletions Mindbox/InAppMessages/Models/InAppFormData.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import UIKit
struct InAppFormData {
let inAppId: String
let imagesDict: [String: UIImage]
let firstImageValue: String
let content: MindboxFormVariant
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ final class PresentationDisplayUseCase {
guard let viewController = factory.create(model: model.content,
id: model.inAppId,
imagesDict: model.imagesDict,
firstImageValue: model.firstImageValue,
onPresented: onPresented,
onTapAction: onTapAction,
onClose: onClose) else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ class SnackbarViewController: UIViewController, InappViewControllerProtocol {
return model.content.position?.margin?.element?.right ?? 0
}

private let id: String
private let imagesDict: [String: UIImage]
private let firstImageValue: String
private let onPresented: () -> Void
private let onClose: () -> Void
private let onTapAction: (ContentBackgroundLayerAction?) -> Void
Expand All @@ -51,15 +51,15 @@ class SnackbarViewController: UIViewController, InappViewControllerProtocol {

init(
model: SnackbarFormVariant,
id: String,
imagesDict: [String: UIImage],
firstImageValue: String,
onPresented: @escaping () -> Void,
onTapAction: @escaping (ContentBackgroundLayerAction?) -> Void,
onClose: @escaping () -> Void
) {
self.model = model
self.id = id
self.imagesDict = imagesDict
self.firstImageValue = firstImageValue
self.onPresented = onPresented
self.onClose = onClose
self.onTapAction = onTapAction
Expand Down Expand Up @@ -161,7 +161,7 @@ class SnackbarViewController: UIViewController, InappViewControllerProtocol {
}

func setupConstraints() {
guard let firstImageKey = imagesDict.keys.first, let image = imagesDict[firstImageKey] else {
guard let image = imagesDict[firstImageValue] else {
return
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ class ModalViewFactory: ViewFactoryProtocol {
func create(model: MindboxFormVariant,
id: String,
imagesDict: [String: UIImage],
firstImageValue: String,
onPresented: @escaping () -> Void,
onTapAction: @escaping (ContentBackgroundLayerAction?) -> Void,
onClose: @escaping () -> Void) -> UIViewController? {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,15 @@ class SnackbarViewFactory: ViewFactoryProtocol {

weak var viewController: UIViewController?

func create(model: MindboxFormVariant, id: String, imagesDict: [String: UIImage], onPresented: @escaping () -> Void, onTapAction: @escaping (ContentBackgroundLayerAction?) -> Void, onClose: @escaping () -> Void) -> UIViewController? {
func create(model: MindboxFormVariant, id: String, imagesDict: [String: UIImage], firstImageValue: String, onPresented: @escaping () -> Void, onTapAction: @escaping (ContentBackgroundLayerAction?) -> Void, onClose: @escaping () -> Void) -> UIViewController? {
if case .snackbar(let snackbarFormVariant) = model {
if let gravity = snackbarFormVariant.content.position?.gravity?.element?.vertical {
var snackbarViewController: UIViewController?
switch gravity {
case .top:
snackbarViewController = TopSnackbarViewController(model: snackbarFormVariant, id: id, imagesDict: imagesDict, onPresented: onPresented, onTapAction: onTapAction, onClose: onClose)
snackbarViewController = TopSnackbarViewController(model: snackbarFormVariant, imagesDict: imagesDict, firstImageValue: firstImageValue, onPresented: onPresented, onTapAction: onTapAction, onClose: onClose)
case .bottom:
snackbarViewController = BottomSnackbarViewController(model: snackbarFormVariant, id: id, imagesDict: imagesDict, onPresented: onPresented, onTapAction: onTapAction, onClose: onClose)
snackbarViewController = BottomSnackbarViewController(model: snackbarFormVariant, imagesDict: imagesDict, firstImageValue: firstImageValue, onPresented: onPresented, onTapAction: onTapAction, onClose: onClose)
default:
return nil
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ protocol ViewFactoryProtocol {
func create(model: MindboxFormVariant,
id: String,
imagesDict: [String: UIImage],
firstImageValue: String,
onPresented: @escaping () -> Void,
onTapAction: @escaping (ContentBackgroundLayerAction?) -> Void,
onClose: @escaping () -> Void) -> UIViewController?
Expand Down

0 comments on commit 12e6221

Please sign in to comment.