Skip to content

Commit

Permalink
chore: refactor code (RMCCX-7619)
Browse files Browse the repository at this point in the history
  • Loading branch information
SoumenRautray committed Dec 17, 2024
1 parent 8008963 commit 792fc43
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 22 deletions.
35 changes: 17 additions & 18 deletions Sources/RInAppMessaging/CampaignDispatcher.swift
Original file line number Diff line number Diff line change
Expand Up @@ -106,29 +106,11 @@ internal class CampaignDispatcher: CampaignDispatcherType, TaskSchedulable {
fetchCampaignImagesAndDisplay(campaign: campaign)
}

func createCarouselDataList(from data: [String: ImageDetails], using images: [UIImage?]) -> [CarouselData] {
let sortedKeys = Array(data.keys).sorted()
var imageDataList: [CarouselData] = []

for (index, key) in sortedKeys.enumerated() {
guard index < images.count else { break }

let image = images[index]
let altText = data[key]?.altText
let link = data[key]?.link

imageDataList.append(CarouselData(image: image, altText: altText, link: link))
}

return imageDataList
}

func fetchCampaignImagesAndDisplay(campaign: Campaign) {
if let carouselData = campaign.data.customJson?.carousel,
!(carouselData.images?.isEmpty ?? true) {
fetchImagesArray(from: carouselData) { images in
guard let carouselData = carouselData.images else { return }
// let carouselHandler = CarouselModelHandler(data: carouselData, images: images)
let carouselHandler = self.createCarouselDataList(from: carouselData, using: images)
self.displayCampaign(campaign, carouselData: carouselHandler)
}
Expand Down Expand Up @@ -292,4 +274,21 @@ extension CampaignDispatcher {
}
}
}

func createCarouselDataList(from data: [String: ImageDetails], using images: [UIImage?]) -> [CarouselData] {
let sortedKeys = Array(data.keys).sorted()
var imageDataList: [CarouselData] = []

for (index, key) in sortedKeys.enumerated() {
guard index < images.count else { break }

let image = images[index]
let altText = data[key]?.altText
let link = data[key]?.link

imageDataList.append(CarouselData(image: image, altText: altText, link: link))
}

return imageDataList
}
}
6 changes: 2 additions & 4 deletions Sources/RInAppMessaging/Views/FullView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -374,10 +374,8 @@ internal class FullView: UIView, FullViewType, RichContentBrowsable {
}

func configureCarouselView(viewModel: FullViewModel) {
guard let carouselData = viewModel.carouselData else { return }
if layout == .carousel {
carouselView.configure(carouselData: carouselData)
}
guard layout == .carousel, let carouselData = viewModel.carouselData else { return }
carouselView.configure(carouselData: carouselData)
}

@objc private func onActionButtonClick(_ sender: ActionButton) {
Expand Down

0 comments on commit 792fc43

Please sign in to comment.