Skip to content

Commit

Permalink
feat: Thumbnail 이미지 네트워크 요청 및 업데이트
Browse files Browse the repository at this point in the history
didSelectRow 메소드에서 detail 정보를 받으면, 받은 thumbnail Image URL들을 가지고 네트워크 요청을 하여 요청을 받으면 각각 Thumbnail VC의 이미지를 업데이트

Issue: #38
  • Loading branch information
corykim0829 committed Apr 28, 2020
1 parent b5c9a2e commit 15caa76
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,10 @@ class DetailViewController: UIViewController {
deliveryInfoLabel.text = detail.deliveryInfo
}

func updateThumbnailImage(at index: Int, image: UIImage?) {
thumbnailPageViewController.updateThumbnailImage(at: index, image: image)
}

private func configureGradientBackgroundView() {
let gradientLayer = CAGradientLayer()
gradientLayerContainerView.backgroundColor = .clear
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,20 @@ extension SideDishProductsViewController: UITableViewDelegate {
DispatchQueue.main.async {
detailViewController.configureDetailViewController(title: product.title, with: detail)
}

detail.thumbnailImageURLs.enumerated().forEach { (index, url) in
self.networkManager.fetchImage(from: url) { (result) in
switch result {
case .success(let data):
let image = UIImage(data: data)
DispatchQueue.main.async {
detailViewController.updateThumbnailImage(at: index, image: image)
}
case .failure(_):
break
}
}
}
}
navigationController?.pushViewController(detailViewController, animated: true)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ class ThumbnailViewController: UIViewController {
configureImageView()
}

func updateImage(_ image: UIImage?) {
self.imageView.image = image
}

private func configureImageView() {
view.addSubview(imageView)
imageView.topAnchor.constraint(equalTo: view.topAnchor).isActive = true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,11 @@ class ThumbnailsPageViewController: UIPageViewController {
configureUI()
}

func updateThumbnailImage(at index: Int, image: UIImage?) {
let thumbnailViewController = thumbnailViewControllers[index]
thumbnailViewController.updateImage(image)
}

private func configureUI() {
view.backgroundColor = .clear
}
Expand Down

0 comments on commit 15caa76

Please sign in to comment.