diff --git a/Koin/Core/View/UIKit/ZoomableImageView.swift b/Koin/Core/View/UIKit/ZoomableImageView.swift new file mode 100644 index 000000000..fe70b2702 --- /dev/null +++ b/Koin/Core/View/UIKit/ZoomableImageView.swift @@ -0,0 +1,144 @@ +// +// ZoomableImageView.swift +// koin +// +// Created by 홍기정 on 11/24/26. +// + +import Combine +import Kingfisher +import UIKit + +final class ZoomableImageView: UIScrollView { + + // MARK: - Properties + + @Published private(set) var isZoomed = false + @Published private(set) var fittedImageFrame: CGRect = .zero + private var lastBoundsSize: CGSize = .zero + private let maximumZoomFactor: CGFloat = 3 + + // MARK: - UI Components + + private let imageView = UIImageView() + + // MARK: - Initializer + + init() { + super.init(frame: .zero) + delegate = self + contentInsetAdjustmentBehavior = .never + showsVerticalScrollIndicator = false + showsHorizontalScrollIndicator = false + decelerationRate = .fast + addSubview(imageView) + + let doubleTapGesture = UITapGestureRecognizer(target: self, action: #selector(doubleTapped)) + doubleTapGesture.numberOfTapsRequired = 2 + addGestureRecognizer(doubleTapGesture) + } + + @available(*, unavailable) + required init?(coder: NSCoder) { + fatalError("init(coder:) has not been implemented") + } + + // MARK: - Layout + + override func layoutSubviews() { + super.layoutSubviews() + guard bounds.size != lastBoundsSize else { return } + lastBoundsSize = bounds.size + updateZoomScales() + } + + // MARK: - Configure + + func setImage(_ image: UIImage?) { + imageView.image = image + resetImageLayout() + } + + func setImage(url: String) { + imageView.kf.setImage(with: URL(string: url), completionHandler: { [weak self] result in + if case .failure(let error) = result, error.isNotCurrentTask { return } + self?.resetImageLayout() + }) + } + + func resetZoom() { + setZoomScale(minimumZoomScale, animated: false) + } +} + +extension ZoomableImageView { + + private func resetImageLayout() { + minimumZoomScale = 1 + maximumZoomScale = 1 + zoomScale = 1 + let imageSize = imageView.image?.size ?? .zero + imageView.frame = CGRect(origin: .zero, size: imageSize) + contentSize = imageSize + updateZoomScales() + } + + private func updateZoomScales() { + guard let imageSize = imageView.image?.size, + imageSize.width > 0, imageSize.height > 0, + bounds.width > 0, bounds.height > 0 else { + fittedImageFrame = CGRect(origin: .zero, size: bounds.size) + return + } + let fitScale = min(bounds.width / imageSize.width, bounds.height / imageSize.height) + minimumZoomScale = fitScale + maximumZoomScale = fitScale * maximumZoomFactor + zoomScale = fitScale + centerImage() + contentOffset = CGPoint(x: -contentInset.left, y: -contentInset.top) + isZoomed = false + + let fittedSize = CGSize(width: imageSize.width * fitScale, height: imageSize.height * fitScale) + fittedImageFrame = CGRect( + x: (bounds.width - fittedSize.width) / 2, + y: (bounds.height - fittedSize.height) / 2, + width: fittedSize.width, + height: fittedSize.height + ) + } + + private func centerImage() { + let horizontalInset = max((bounds.width - contentSize.width) / 2, 0) + let verticalInset = max((bounds.height - contentSize.height) / 2, 0) + contentInset = UIEdgeInsets(top: verticalInset, left: horizontalInset, bottom: verticalInset, right: horizontalInset) + } + + @objc private func doubleTapped(_ gesture: UITapGestureRecognizer) { + guard imageView.image != nil else { return } + if isZoomed { + setZoomScale(minimumZoomScale, animated: true) + return + } + let point = gesture.location(in: imageView) + let zoomSize = CGSize(width: bounds.width / maximumZoomScale, height: bounds.height / maximumZoomScale) + let zoomRect = CGRect( + x: point.x - zoomSize.width / 2, + y: point.y - zoomSize.height / 2, + width: zoomSize.width, + height: zoomSize.height + ) + zoom(to: zoomRect, animated: true) + } +} + +extension ZoomableImageView: UIScrollViewDelegate { + + func viewForZooming(in scrollView: UIScrollView) -> UIView? { + imageView + } + + func scrollViewDidZoom(_ scrollView: UIScrollView) { + centerImage() + isZoomed = zoomScale != minimumZoomScale + } +} diff --git a/Koin/Core/View/UIKit/ZoomedImageViewController/Subviews/ZoomingCollectionView.swift b/Koin/Core/View/UIKit/ZoomedImageViewController/Subviews/ZoomingCollectionView.swift deleted file mode 100644 index 009d00b89..000000000 --- a/Koin/Core/View/UIKit/ZoomedImageViewController/Subviews/ZoomingCollectionView.swift +++ /dev/null @@ -1,101 +0,0 @@ -// -// ZoomingCollectionView.swift -// koin -// -// Created by 홍기정 on 4/22/26. -// - -import UIKit -import Combine - -final class ZoomingCollectionView: UICollectionView { - - private var images: [UIImage?] = [] - let closeButtonPublisher = PassthroughSubject() - - var imageCount: Int { - images.count - } - - init() { - let layout = UICollectionViewFlowLayout() - layout.scrollDirection = .horizontal - layout.minimumLineSpacing = 0 - layout.minimumInteritemSpacing = 0 - - super.init(frame: .zero, collectionViewLayout: layout) - setUpCollectionView() - } - - @available(*, unavailable) - required init?(coder: NSCoder) { - fatalError("init(coder:) has not been implemented") - } - - func setImages(_ newImages: [UIImage?]) { - images = newImages - reloadData() - setContentOffset(.zero, animated: false) - } - - func setImage(_ newImage: UIImage?) { - setImages([newImage]) - } - - func showImage(at index: Int, animated: Bool) { - guard 0.. Int { - images.count - } - - func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell { - guard let cell = collectionView.dequeueReusableCell( - withReuseIdentifier: ZoomingCollectionViewCell.identifier, - for: indexPath - ) as? ZoomingCollectionViewCell else { - return UICollectionViewCell() - } - - cell.setImage(images[indexPath.row]) - cell.onCloseButtonTap = { [weak self] in - self?.closeButtonPublisher.send() - } - return cell - } -} - -extension ZoomingCollectionView: UICollectionViewDelegateFlowLayout { - - func collectionView( - _ collectionView: UICollectionView, - layout collectionViewLayout: UICollectionViewLayout, - sizeForItemAt indexPath: IndexPath - ) -> CGSize { - collectionView.bounds.size - } -} - -extension ZoomingCollectionView { - - private func setUpCollectionView() { - register( - ZoomingCollectionViewCell.self, - forCellWithReuseIdentifier: ZoomingCollectionViewCell.identifier - ) - delegate = self - dataSource = self - isPagingEnabled = true - isScrollEnabled = false - showsHorizontalScrollIndicator = false - showsVerticalScrollIndicator = false - backgroundColor = .clear - } -} diff --git a/Koin/Core/View/UIKit/ZoomedImageViewController/Subviews/ZoomingCollectionViewCell.swift b/Koin/Core/View/UIKit/ZoomedImageViewController/Subviews/ZoomingCollectionViewCell.swift deleted file mode 100644 index 14398994b..000000000 --- a/Koin/Core/View/UIKit/ZoomedImageViewController/Subviews/ZoomingCollectionViewCell.swift +++ /dev/null @@ -1,85 +0,0 @@ -// -// ZoomingCollectionViewCell.swift -// koin -// -// Created by 홍기정 on 4/22/26. -// - -import UIKit - -final class ZoomingCollectionViewCell: UICollectionViewCell { - - var onCloseButtonTap: (() -> Void)? - - private let imageView: UIImageView = { - let imageView = UIImageView() - imageView.contentMode = .scaleAspectFit - imageView.clipsToBounds = true - return imageView - }() - - private var imageAspectRatioConstraint: NSLayoutConstraint? - - private let closeButton: UIButton = { - let button = UIButton() - button.setImage(UIImage.appImage(asset: .cancel), for: .normal) - return button - }() - - override init(frame: CGRect) { - super.init(frame: frame) - configureView() - closeButton.addTarget(self, action: #selector(closeButtonTapped), for: .touchUpInside) - } - - @available(*, unavailable) - required init?(coder: NSCoder) { - fatalError("init(coder:) has not been implemented") - } - - override func prepareForReuse() { - super.prepareForReuse() - imageView.image = nil - onCloseButtonTap = nil - imageAspectRatioConstraint?.isActive = false - imageAspectRatioConstraint = nil - } - - func setImage(_ image: UIImage?) { - imageView.image = image - - imageAspectRatioConstraint?.isActive = false - if let image, image.size.width > 0 { - let ratio = image.size.height / image.size.width - let constraint = imageView.heightAnchor.constraint(equalTo: imageView.widthAnchor, multiplier: ratio) - constraint.priority = .defaultHigh - constraint.isActive = true - imageAspectRatioConstraint = constraint - } - } - - @objc private func closeButtonTapped() { - onCloseButtonTap?() - } -} - -extension ZoomingCollectionViewCell { - - private func configureView() { - contentView.addSubview(imageView) - contentView.addSubview(closeButton) - - imageView.snp.makeConstraints { make in - make.leading.trailing.equalToSuperview() - make.centerY.equalToSuperview() - make.top.greaterThanOrEqualTo(contentView.safeAreaLayoutGuide.snp.top).offset(24) - make.bottom.lessThanOrEqualTo(contentView.safeAreaLayoutGuide.snp.bottom) - } - - closeButton.snp.makeConstraints { make in - make.width.height.equalTo(24) - make.bottom.equalTo(imageView.snp.top).offset(-8) - make.trailing.equalTo(imageView.snp.trailing) - } - } -} diff --git a/Koin/Core/View/UIKit/ZoomedImageViewController/ZoomedImageViewController.swift b/Koin/Core/View/UIKit/ZoomedImageViewController/ZoomedImageViewController.swift index 3efdecb46..e4a00a05e 100644 --- a/Koin/Core/View/UIKit/ZoomedImageViewController/ZoomedImageViewController.swift +++ b/Koin/Core/View/UIKit/ZoomedImageViewController/ZoomedImageViewController.swift @@ -6,181 +6,125 @@ // import Combine +import SnapKit import UIKit final class ZoomedImageViewController: UIViewController { - + // MARK: - Properties - - private var cancellables: Set = [] - private var currentIndex = 0 - + + private var subscriptions: Set = [] + private var initialTouchPoint = CGPoint.zero + private let closeButtonSize: CGFloat = 24 + private let closeButtonSpacing: CGFloat = 8 + // MARK: - UI Components - - private let scrollView = UIScrollView().then { - $0.minimumZoomScale = 1.0 - $0.maximumZoomScale = 6.0 - $0.backgroundColor = .clear - $0.showsVerticalScrollIndicator = false - $0.showsHorizontalScrollIndicator = false + + private let zoomableImageView = ZoomableImageView().then { + $0.clipsToBounds = false } - - private let collectionView = ZoomingCollectionView() - - private let nextButton: UIButton = { - let button = UIButton() - let image = UIImage(systemName: "arrow.right")? - .withTintColor(UIColor.appColor(.neutral0), renderingMode: .alwaysOriginal) - button.setImage(image, for: .normal) - button.layer.cornerRadius = 22 - button.backgroundColor = UIColor.appColor(.neutral800).withAlphaComponent(0.5) - return button - }() - - private let prevButton: UIButton = { - let button = UIButton() - let image = UIImage(systemName: "arrow.left")? - .withTintColor(UIColor.appColor(.neutral0), renderingMode: .alwaysOriginal) - button.setImage(image, for: .normal) - button.layer.cornerRadius = 22 - button.backgroundColor = UIColor.appColor(.neutral800).withAlphaComponent(0.5) - return button - }() - + + private let closeButton = UIButton().then { + $0.setImage(UIImage.appImage(asset: .cancel), for: .normal) + } + // MARK: - Initialize - + init() { super.init(nibName: nil, bundle: nil) modalPresentationStyle = .fullScreen - modalTransitionStyle = .coverVertical } - + @available(*, unavailable) required init?(coder: NSCoder) { fatalError("init(coder:) has not been implemented") } - + + override var preferredStatusBarStyle: UIStatusBarStyle { + .lightContent + } + // MARK: - Life Cycle - + override func viewDidLoad() { super.viewDidLoad() + additionalSafeAreaInsets.top = closeButtonSize + closeButtonSpacing configureView() - setupScrollView() bind() + closeButton.addTarget(self, action: #selector(closeButtonTapped), for: .touchUpInside) + view.addGestureRecognizer(UIPanGestureRecognizer(target: self, action: #selector(panGestureDismiss))) } - - override func viewDidLayoutSubviews() { - super.viewDidLayoutSubviews() - - if scrollView.zoomScale == scrollView.minimumZoomScale { - centerScrollViewContents() - } - } - + func setImage(_ image: UIImage?) { - currentIndex = 0 - collectionView.setImage(image) - scrollView.setZoomScale(scrollView.minimumZoomScale, animated: false) - updateButtonVisibility() - centerScrollViewContents() + zoomableImageView.setImage(image) } - - func setImages(_ images: [UIImage?]) { - currentIndex = 0 - collectionView.setImages(images) - scrollView.setZoomScale(scrollView.minimumZoomScale, animated: false) - updateButtonVisibility() - centerScrollViewContents() + + func setImage(url: String) { + zoomableImageView.setImage(url: url) } } extension ZoomedImageViewController { - + private func configureView() { - view.backgroundColor = .black - view.addSubview(scrollView) - scrollView.addSubview(collectionView) - view.addSubview(nextButton) - view.addSubview(prevButton) - - scrollView.snp.makeConstraints { make in - make.edges.equalToSuperview() - } - - collectionView.snp.makeConstraints { make in - make.edges.equalTo(scrollView.contentLayoutGuide) - make.width.equalTo(scrollView.frameLayoutGuide) - make.height.equalTo(scrollView.frameLayoutGuide) - } - - nextButton.snp.makeConstraints { make in - make.centerY.equalTo(view.safeAreaLayoutGuide) - make.trailing.equalToSuperview() - make.width.height.equalTo(44) + view.backgroundColor = .appColor(.neutral800) + view.addSubview(zoomableImageView) + view.addSubview(closeButton) + + zoomableImageView.snp.makeConstraints { make in + make.edges.equalTo(view.safeAreaLayoutGuide) } - - prevButton.snp.makeConstraints { make in - make.centerY.equalTo(view.safeAreaLayoutGuide) - make.leading.equalToSuperview() - make.width.height.equalTo(44) + + closeButton.snp.makeConstraints { make in + make.width.height.equalTo(closeButtonSize) + make.trailing.equalTo(zoomableImageView.snp.leading) + make.bottom.equalTo(zoomableImageView.snp.top).offset(-closeButtonSpacing) } } - - private func setupScrollView() { - scrollView.delegate = self - nextButton.addTarget(self, action: #selector(nextButtonTapped), for: .touchUpInside) - prevButton.addTarget(self, action: #selector(prevButtonTapped), for: .touchUpInside) - } - + private func bind() { - collectionView.closeButtonPublisher - .sink { [weak self] in - self?.dismiss(animated: true) + zoomableImageView.$fittedImageFrame + .sink { [weak self] fittedImageFrame in + self?.updateCloseButtonPosition(fittedImageFrame) } - .store(in: &cancellables) - } - - private func centerScrollViewContents() { - let offsetX = max((scrollView.bounds.width - scrollView.contentSize.width) * 0.5, 0) - let offsetY = max((scrollView.bounds.height - scrollView.contentSize.height) * 0.5, 0) - scrollView.contentInset = UIEdgeInsets(top: offsetY, left: offsetX, bottom: offsetY, right: offsetX) - } - - private func updateButtonVisibility() { - nextButton.isHidden = currentIndex >= collectionView.imageCount - 1 - prevButton.isHidden = currentIndex <= 0 - } - - @objc private func nextButtonTapped() { - if currentIndex < collectionView.imageCount - 1 { - currentIndex += 1 - collectionView.showImage(at: currentIndex, animated: true) - } - updateButtonVisibility() + .store(in: &subscriptions) + + zoomableImageView.$isZoomed + .removeDuplicates() + .sink { [weak self] isZoomed in + UIView.animate( + withDuration: isZoomed ? 0.1 : 0.2, + delay: 0, + options: [.overrideInheritedDuration, .overrideInheritedCurve] + ) { + self?.closeButton.alpha = isZoomed ? 0 : 1 + } + } + .store(in: &subscriptions) } - - @objc private func prevButtonTapped() { - if currentIndex > 0 { - currentIndex -= 1 - collectionView.showImage(at: currentIndex, animated: true) + + private func updateCloseButtonPosition(_ fittedImageFrame: CGRect) { + closeButton.snp.updateConstraints { make in + make.trailing.equalTo(zoomableImageView.snp.leading).offset(fittedImageFrame.maxX) + make.bottom.equalTo(zoomableImageView.snp.top).offset(fittedImageFrame.minY - closeButtonSpacing) } - updateButtonVisibility() } -} -extension ZoomedImageViewController: UIScrollViewDelegate { - - func viewForZooming(in scrollView: UIScrollView) -> UIView? { - collectionView + @objc private func closeButtonTapped() { + dismiss(animated: true) } - - func scrollViewDidZoom(_ scrollView: UIScrollView) { - centerScrollViewContents() - } - - func scrollViewDidEndZooming(_ scrollView: UIScrollView, with view: UIView?, atScale scale: CGFloat) { - UIView.animate(withDuration: 0.3) { - scrollView.setZoomScale(scrollView.minimumZoomScale, animated: false) + + @objc private func panGestureDismiss(_ sender: UIPanGestureRecognizer) { + let touchPoint = sender.location(in: view.window) + switch sender.state { + case .began: + initialTouchPoint = touchPoint + case .changed, .ended, .cancelled: + guard !zoomableImageView.isZoomed, + 50 < touchPoint.y - initialTouchPoint.y else { return } + dismiss(animated: true) + default: + return } } } diff --git a/Koin/Core/View/UIKit/ZoomedImageViewControllerB/Subviews/ZoomedImageCollectionView.swift b/Koin/Core/View/UIKit/ZoomedImageViewControllerB/Subviews/ZoomedImageCollectionView.swift index 1df2e69bb..2157b7995 100644 --- a/Koin/Core/View/UIKit/ZoomedImageViewControllerB/Subviews/ZoomedImageCollectionView.swift +++ b/Koin/Core/View/UIKit/ZoomedImageViewControllerB/Subviews/ZoomedImageCollectionView.swift @@ -12,16 +12,14 @@ final class ZoomedImageCollectionView: UICollectionView { // MARK: - Properties private var urls: [String] = [] - private var initialIndexPath: IndexPath = IndexPath(row: 0, section: 0) + private var initialIndex = 0 let updateTitlePublisher = PassthroughSubject() - let hideNavigationBarPublisher = PassthroughSubject() private var isInitialized = false // MARK: - Initializer override init(frame: CGRect, collectionViewLayout layout: UICollectionViewLayout) { let layout = UICollectionViewFlowLayout().then { $0.scrollDirection = .horizontal - $0.itemSize = CGSize(width: UIScreen.main.bounds.width, height: UIScreen.main.bounds.height) $0.minimumLineSpacing = 0 $0.minimumInteritemSpacing = 0 } @@ -33,17 +31,21 @@ final class ZoomedImageCollectionView: UICollectionView { fatalError("init(coder:) has not been implemented") } + var isCurrentImageZoomed: Bool { + visibleCells.contains { ($0 as? ZoomedImageCollectionViewCell)?.isZoomed == true } + } + // MARK: - Configure - func configure(urls: [String], initialIndexPath: IndexPath) { + func configure(urls: [String], initialIndex: Int) { self.urls = urls - self.initialIndexPath = initialIndexPath + self.initialIndex = initialIndex reloadData() } override func layoutSubviews() { super.layoutSubviews() - if !isInitialized { - contentOffset = CGPoint(x: UIScreen.main.bounds.width * CGFloat(initialIndexPath.row), y: 0) + if !isInitialized, 0 < bounds.width { + contentOffset = CGPoint(x: bounds.width * CGFloat(initialIndex), y: 0) isInitialized = true } } @@ -65,6 +67,14 @@ extension ZoomedImageCollectionView: UICollectionViewDataSource { } extension ZoomedImageCollectionView: UICollectionViewDelegateFlowLayout { + + func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize { + return collectionView.bounds.size + } + + func collectionView(_ collectionView: UICollectionView, didEndDisplaying cell: UICollectionViewCell, forItemAt indexPath: IndexPath) { + (cell as? ZoomedImageCollectionViewCell)?.resetZoom() + } func scrollViewDidEndDecelerating(_ scrollView: UIScrollView) { let width = self.frame.width @@ -89,6 +99,6 @@ extension ZoomedImageCollectionView { isPagingEnabled = true showsHorizontalScrollIndicator = false contentInsetAdjustmentBehavior = .never - backgroundColor = .black + backgroundColor = .appColor(.neutral800) } } diff --git a/Koin/Core/View/UIKit/ZoomedImageViewControllerB/Subviews/ZoomedImageCollectionViewCell.swift b/Koin/Core/View/UIKit/ZoomedImageViewControllerB/Subviews/ZoomedImageCollectionViewCell.swift index a6043ad6d..62d335ffb 100644 --- a/Koin/Core/View/UIKit/ZoomedImageViewControllerB/Subviews/ZoomedImageCollectionViewCell.swift +++ b/Koin/Core/View/UIKit/ZoomedImageViewControllerB/Subviews/ZoomedImageCollectionViewCell.swift @@ -6,78 +6,47 @@ // import UIKit -import Combine final class ZoomedImageCollectionViewCell: UICollectionViewCell { - + // MARK: - UI Components - let scrollView = UIScrollView().then { - $0.minimumZoomScale = 1.0 - $0.maximumZoomScale = 3.0 - $0.showsVerticalScrollIndicator = false - $0.showsHorizontalScrollIndicator = false - } - let imageView = UIImageView().then { - $0.contentMode = .scaleAspectFit + private let zoomableImageView = ZoomableImageView() + + var isZoomed: Bool { + zoomableImageView.isZoomed } - + // MARK: - Initializer override init(frame: CGRect) { super.init(frame: .zero) configureView() - setDelegate() } required init?(coder: NSCoder) { fatalError("init(coder:) has not been implemented") } - + // MARK: - Configure func configure(url: String) { - imageView.kf.setImage( - with: URL(string: url) - ) + zoomableImageView.setImage(url: url) + } + + func resetZoom() { + zoomableImageView.resetZoom() } - + // MARK: - PrepareForReuse override func prepareForReuse() { super.prepareForReuse() - - scrollView.zoomScale = 1.0 - imageView.image = nil - } -} - -extension ZoomedImageCollectionViewCell: UIScrollViewDelegate { - - func viewForZooming(in scrollView: UIScrollView) -> UIView? { - return imageView - } - - func scrollViewDidEndZooming(_ scrollView: UIScrollView, with view: UIView?, atScale scale: CGFloat) { - UIView.animate(withDuration: 0.3) { [weak self] in - self?.scrollView.zoomScale = 1.0 - } + zoomableImageView.setImage(nil) } } extension ZoomedImageCollectionViewCell { - - private func setDelegate() { - scrollView.delegate = self - } - + private func configureView() { - contentView.addSubview(scrollView) - scrollView.addSubview(imageView) - - scrollView.snp.makeConstraints { + contentView.addSubview(zoomableImageView) + zoomableImageView.snp.makeConstraints { $0.edges.equalToSuperview() - $0.width.equalToSuperview() - } - imageView.snp.makeConstraints { - $0.height.equalToSuperview() - $0.width.equalToSuperview() - $0.centerY.equalToSuperview() } } } diff --git a/Koin/Core/View/UIKit/ZoomedImageViewControllerB/Subviews/ZoomedImageRootViewController.swift b/Koin/Core/View/UIKit/ZoomedImageViewControllerB/Subviews/ZoomedImageRootViewController.swift index 5b2d44863..7fe81ce91 100644 --- a/Koin/Core/View/UIKit/ZoomedImageViewControllerB/Subviews/ZoomedImageRootViewController.swift +++ b/Koin/Core/View/UIKit/ZoomedImageViewControllerB/Subviews/ZoomedImageRootViewController.swift @@ -57,10 +57,10 @@ final class ZoomedImageRootViewController: UIViewController { } // MARK: - Configure - func configure(urls: [String], initialIndexPath: IndexPath) { - zoomedImageCollectionView.configure(urls: urls, initialIndexPath: initialIndexPath) + func configure(urls: [String], initialIndex: Int) { + zoomedImageCollectionView.configure(urls: urls, initialIndex: initialIndex) if shouldShowTitle { - title = "\(initialIndexPath.row+1)/\(urls.count)" + title = "\(initialIndex + 1)/\(urls.count)" } } @@ -72,10 +72,6 @@ final class ZoomedImageRootViewController: UIViewController { self.title = title } }.store(in: &subscriptions) - - zoomedImageCollectionView.hideNavigationBarPublisher.sink { [weak self] isHidden in - self?.navigationController?.setNavigationBarHidden(isHidden, animated: true) - }.store(in: &subscriptions) } } @@ -88,15 +84,13 @@ extension ZoomedImageRootViewController { @objc private func panGestureDismiss(_ sender: UIGestureRecognizer) { let touchPoint = sender.location(in: view.window) - - if sender.state == .began { - initialTouchPoint = touchPoint - } + switch sender.state { case .began: initialTouchPoint = touchPoint case .changed, .ended, .cancelled: - if 50 < touchPoint.y - initialTouchPoint.y { + if !zoomedImageCollectionView.isCurrentImageZoomed, + 50 < touchPoint.y - initialTouchPoint.y { dismiss(animated: true) } default: diff --git a/Koin/Core/View/UIKit/ZoomedImageViewControllerB/ZoomedImageViewControllerB.swift b/Koin/Core/View/UIKit/ZoomedImageViewControllerB/ZoomedImageViewControllerB.swift index 6089aa565..640f98224 100644 --- a/Koin/Core/View/UIKit/ZoomedImageViewControllerB/ZoomedImageViewControllerB.swift +++ b/Koin/Core/View/UIKit/ZoomedImageViewControllerB/ZoomedImageViewControllerB.swift @@ -10,15 +10,14 @@ import UIKit final class ZoomedImageViewControllerB: UINavigationController { // MARK: - Properties - let rootViewController: ZoomedImageRootViewController + private let rootViewController: ZoomedImageRootViewController // MARK: - Initializer init(shouldShowTitle: Bool = true) { rootViewController = ZoomedImageRootViewController(shouldShowTitle: shouldShowTitle) super.init(rootViewController: rootViewController) - modalPresentationStyle = .overCurrentContext - modalTransitionStyle = .coverVertical + modalPresentationStyle = .fullScreen } required init?(coder aDecoder: NSCoder) { fatalError("init(coder:) has not been implemented") @@ -33,7 +32,8 @@ final class ZoomedImageViewControllerB: UINavigationController { configure(urls: [url]) } - func configure(urls: [String], initialIndexPath: IndexPath = IndexPath(row: 0, section: 0)) { - rootViewController.configure(urls: urls, initialIndexPath: initialIndexPath) + func configure(urls: [String], selectedIndex: Int = 0) { + let index = urls.indices.contains(selectedIndex) ? selectedIndex : 0 + rootViewController.configure(urls: urls, initialIndex: index) } } diff --git a/Koin/Presentation/CallVan/CallVanChat/CallVanChatViewController.swift b/Koin/Presentation/CallVan/CallVanChat/CallVanChatViewController.swift index 698c1ae42..8cf222e20 100644 --- a/Koin/Presentation/CallVan/CallVanChat/CallVanChatViewController.swift +++ b/Koin/Presentation/CallVan/CallVanChat/CallVanChatViewController.swift @@ -93,7 +93,6 @@ final class CallVanChatViewController: UIViewController { .sink { [weak self] imageUrl in let zoomedImageViewController = ZoomedImageViewControllerB(shouldShowTitle: false) zoomedImageViewController.configure(url: imageUrl) - zoomedImageViewController.modalPresentationStyle = .overFullScreen self?.present(zoomedImageViewController, animated: true) } .store(in: &subscriptions) diff --git a/Koin/Presentation/Dining/Dining/DiningHostingController.swift b/Koin/Presentation/Dining/Dining/DiningHostingController.swift index 3d0056620..2874c7115 100644 --- a/Koin/Presentation/Dining/Dining/DiningHostingController.swift +++ b/Koin/Presentation/Dining/Dining/DiningHostingController.swift @@ -263,9 +263,8 @@ extension DiningHostingController { extension DiningHostingController { private func showZoomedImage(imageUrl: String) { - let zoomedImageViewController = ZoomedImageViewControllerB(shouldShowTitle: false) - zoomedImageViewController.configure(url: imageUrl) - zoomedImageViewController.modalPresentationStyle = .overFullScreen + let zoomedImageViewController = ZoomedImageViewController() + zoomedImageViewController.setImage(url: imageUrl) present(zoomedImageViewController, animated: true) } } diff --git a/Koin/Presentation/Land/LandDetail/LandDetailViewController.swift b/Koin/Presentation/Land/LandDetail/LandDetailViewController.swift index 96e27a5ea..8de670bfa 100644 --- a/Koin/Presentation/Land/LandDetail/LandDetailViewController.swift +++ b/Koin/Presentation/Land/LandDetail/LandDetailViewController.swift @@ -118,7 +118,7 @@ extension LandDetailViewController { private func presentZoomedImage(imageUrls: [String], indexPath: IndexPath) { let zoomedImageViewController = ZoomedImageViewControllerB() - zoomedImageViewController.configure(urls: imageUrls, initialIndexPath: indexPath) + zoomedImageViewController.configure(urls: imageUrls, selectedIndex: indexPath.row) present(zoomedImageViewController, animated: true) } diff --git a/Koin/Presentation/LostItem/LostItemChat/LostItemChatViewController.swift b/Koin/Presentation/LostItem/LostItemChat/LostItemChatViewController.swift index b5b9bebb1..53cc82c33 100644 --- a/Koin/Presentation/LostItem/LostItemChat/LostItemChatViewController.swift +++ b/Koin/Presentation/LostItem/LostItemChat/LostItemChatViewController.swift @@ -84,7 +84,7 @@ final class LostItemChatViewController: UIViewController, PHPickerViewController self?.dismissKeyboard() let zoomedImageViewController = ZoomedImageViewControllerB(shouldShowTitle: false) - zoomedImageViewController.configure(urls: [imageUrl], initialIndexPath: IndexPath(row: 0, section: 0)) + zoomedImageViewController.configure(url: imageUrl) self?.present(zoomedImageViewController, animated: true, completion: nil) }.store(in: &subscriptions) } diff --git a/Koin/Presentation/LostItem/LostItemData/LostItemDataViewController.swift b/Koin/Presentation/LostItem/LostItemData/LostItemDataViewController.swift index 4942d449e..17fcf007e 100644 --- a/Koin/Presentation/LostItem/LostItemData/LostItemDataViewController.swift +++ b/Koin/Presentation/LostItem/LostItemData/LostItemDataViewController.swift @@ -128,7 +128,7 @@ final class LostItemDataViewController: UIViewController { let viewController = ZoomedImageViewControllerB() viewController.configure( urls: imageUrls, - initialIndexPath: indexPath) + selectedIndex: indexPath.row) navigationController?.present(viewController, animated: true) }.store(in: &subscription) diff --git a/Koin/Presentation/Recruit/RecruitChat/RecruitChatViewController.swift b/Koin/Presentation/Recruit/RecruitChat/RecruitChatViewController.swift index c31bbd34a..1a52dc6ce 100644 --- a/Koin/Presentation/Recruit/RecruitChat/RecruitChatViewController.swift +++ b/Koin/Presentation/Recruit/RecruitChat/RecruitChatViewController.swift @@ -174,7 +174,6 @@ extension RecruitChatViewController { private func presentZoomedImageViewControllerB(_ imageUrl: String) { let viewController = ZoomedImageViewControllerB(shouldShowTitle: false) viewController.configure(url: imageUrl) - viewController.modalPresentationStyle = .overFullScreen present(viewController, animated: true) } } diff --git a/Koin/Presentation/Shop/ShopBenefit/ShopBenefitViewController.swift b/Koin/Presentation/Shop/ShopBenefit/ShopBenefitViewController.swift index 20b83c8f6..756d9acf8 100644 --- a/Koin/Presentation/Shop/ShopBenefit/ShopBenefitViewController.swift +++ b/Koin/Presentation/Shop/ShopBenefit/ShopBenefitViewController.swift @@ -54,8 +54,7 @@ final class ShopBenefitViewController: UIViewController { benefitsTableView.imageTapPublisher.sink { [weak self] (imageUrls, indexPath) in guard let self else { return } let zoomedImageViewController = ZoomedImageViewControllerB() - zoomedImageViewController.configure(urls: imageUrls, initialIndexPath: indexPath) - zoomedImageViewController.modalPresentationStyle = .fullScreen + zoomedImageViewController.configure(urls: imageUrls, selectedIndex: indexPath.row) present(zoomedImageViewController, animated: true) }.store(in: &subscriptions) diff --git a/Koin/Presentation/Shop/ShopReviewList/ReviewListViewController.swift b/Koin/Presentation/Shop/ShopReviewList/ReviewListViewController.swift index f3a6fa225..2e30fe8f9 100644 --- a/Koin/Presentation/Shop/ShopReviewList/ReviewListViewController.swift +++ b/Koin/Presentation/Shop/ShopReviewList/ReviewListViewController.swift @@ -375,7 +375,7 @@ extension ReviewListViewController { private func showZoomedImage(_ imageUrls: [String], _ initialIndexpath: IndexPath) { let zoomedImageViewController = ZoomedImageViewControllerB() - zoomedImageViewController.configure(urls: imageUrls, initialIndexPath: initialIndexpath) + zoomedImageViewController.configure(urls: imageUrls, selectedIndex: initialIndexpath.row) present(zoomedImageViewController, animated: true) } } diff --git a/Koin/Presentation/Shop/ShopSummary/ShopSummaryViewController.swift b/Koin/Presentation/Shop/ShopSummary/ShopSummaryViewController.swift index f81351cad..4473ad6c1 100644 --- a/Koin/Presentation/Shop/ShopSummary/ShopSummaryViewController.swift +++ b/Koin/Presentation/Shop/ShopSummary/ShopSummaryViewController.swift @@ -294,7 +294,7 @@ extension ShopSummaryViewController { self.inputSubject.send(.logEvent(EventParameter.EventLabel.Shop.shopDetailPhotoViewOpenClick, self.viewModel.shopName)) let zoomedViewController = ZoomedImageViewControllerB() zoomedViewController.configure(urls: viewModel.cachedImages.map { return $0.imageUrl }, - initialIndexPath: indexPath) + selectedIndex: indexPath.row) self.present(zoomedViewController, animated: true) }.store(in: &subscriptions) } diff --git a/koin.xcodeproj/project.pbxproj b/koin.xcodeproj/project.pbxproj index 45684e5a4..c22335dd1 100644 --- a/koin.xcodeproj/project.pbxproj +++ b/koin.xcodeproj/project.pbxproj @@ -1098,6 +1098,7 @@ D22C54812C6A5957000826DA /* FileUploadResponse.swift in Sources */ = {isa = PBXBuildFile; fileRef = D22C54802C6A5957000826DA /* FileUploadResponse.swift */; }; D22C54832C6A59C4000826DA /* UploadFileUseCase.swift in Sources */ = {isa = PBXBuildFile; fileRef = D22C54822C6A59C4000826DA /* UploadFileUseCase.swift */; }; D235829F2BC2F5D600D615DD /* ZoomedImageViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = D235829E2BC2F5D600D615DD /* ZoomedImageViewController.swift */; }; + D8C9A09DFDA097189C1CC6DC /* ZoomableImageView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8E6FC478657F8D64C0A7B0ED /* ZoomableImageView.swift */; }; D23944822C3C24A200048F45 /* ReviewsDto.swift in Sources */ = {isa = PBXBuildFile; fileRef = D23944812C3C24A200048F45 /* ReviewsDto.swift */; }; D23944842C3C3ABC00048F45 /* ShopReview.swift in Sources */ = {isa = PBXBuildFile; fileRef = D23944832C3C3ABC00048F45 /* ShopReview.swift */; }; D23944862C3C3ADB00048F45 /* FetchShopReviewListUseCase.swift in Sources */ = {isa = PBXBuildFile; fileRef = D23944852C3C3ADB00048F45 /* FetchShopReviewListUseCase.swift */; }; @@ -1261,8 +1262,6 @@ E5DD3F6BE6C501B7B3BD659C /* RecruitPostRoleView.swift in Sources */ = {isa = PBXBuildFile; fileRef = F670021A95E0AA103E8F7BED /* RecruitPostRoleView.swift */; }; E7EB12C06B3F32702DE1BDDB /* RecruitNotificationListDto.swift in Sources */ = {isa = PBXBuildFile; fileRef = 70B18A7091B73080A7AEDDDE /* RecruitNotificationListDto.swift */; }; F0F216EDAA69B52CBEC0E606 /* RecruitPostViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 288BC1E04044DC3FB48524FC /* RecruitPostViewModel.swift */; }; - F1A000010000000000000001 /* ZoomingCollectionView.swift in Sources */ = {isa = PBXBuildFile; fileRef = F1A000010000000000000002 /* ZoomingCollectionView.swift */; }; - F1A000010000000000000003 /* ZoomingCollectionViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = F1A000010000000000000004 /* ZoomingCollectionViewCell.swift */; }; F7F814BB370C922B6D8AA6EF /* RecruitStepView.swift in Sources */ = {isa = PBXBuildFile; fileRef = EFEC522ED41CF624AD3CB3A6 /* RecruitStepView.swift */; }; FBCFB1EF499995884A6F2E83 /* RecruitPostSchedule.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1D65EF9E2B65CAE83F8017DD /* RecruitPostSchedule.swift */; }; FC40DDB1CAB3573658F94721 /* StudentAcademicInfoDto.swift in Sources */ = {isa = PBXBuildFile; fileRef = FA5AA513615BE12CD677F848 /* StudentAcademicInfoDto.swift */; }; @@ -2382,6 +2381,7 @@ D22C54802C6A5957000826DA /* FileUploadResponse.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FileUploadResponse.swift; sourceTree = ""; }; D22C54822C6A59C4000826DA /* UploadFileUseCase.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UploadFileUseCase.swift; sourceTree = ""; }; D235829E2BC2F5D600D615DD /* ZoomedImageViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ZoomedImageViewController.swift; sourceTree = ""; }; + 8E6FC478657F8D64C0A7B0ED /* ZoomableImageView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ZoomableImageView.swift; sourceTree = ""; }; D23944812C3C24A200048F45 /* ReviewsDto.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ReviewsDto.swift; sourceTree = ""; }; D23944832C3C3ABC00048F45 /* ShopReview.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ShopReview.swift; sourceTree = ""; }; D23944852C3C3ADB00048F45 /* FetchShopReviewListUseCase.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FetchShopReviewListUseCase.swift; sourceTree = ""; }; @@ -2553,8 +2553,6 @@ ED038AB5420C8C565688CF6B /* DefaultRecruitRepository.swift */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.swift; path = DefaultRecruitRepository.swift; sourceTree = ""; }; EFEC522ED41CF624AD3CB3A6 /* RecruitStepView.swift */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.swift; path = RecruitStepView.swift; sourceTree = ""; }; F04DE3DD779FBB7BEB86A567 /* PickerAppearanceDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PickerAppearanceDelegate.swift; sourceTree = ""; }; - F1A000010000000000000002 /* ZoomingCollectionView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ZoomingCollectionView.swift; sourceTree = ""; }; - F1A000010000000000000004 /* ZoomingCollectionViewCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ZoomingCollectionViewCell.swift; sourceTree = ""; }; F483F8DD8FCE3104599410C0 /* KoinPickerView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = KoinPickerView.swift; sourceTree = ""; }; F670021A95E0AA103E8F7BED /* RecruitPostRoleView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RecruitPostRoleView.swift; sourceTree = ""; }; FA5AA513615BE12CD677F848 /* StudentAcademicInfoDto.swift */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.swift; path = StudentAcademicInfoDto.swift; sourceTree = ""; }; @@ -3317,6 +3315,7 @@ 7CED8ED32EF2D1F900457128 /* CancelableImageView.swift */, 7CC42B062F56A7E900940CE1 /* ZoomedImageViewController */, 7CA0D6172EC744E700E9A282 /* ZoomedImageViewControllerB */, + 8E6FC478657F8D64C0A7B0ED /* ZoomableImageView.swift */, 7C333E7A302E280C009D2B89 /* KoinModalViewController */, D2FB23442BFB6D090098BA2B /* CustomNavigationController.swift */, D27A5D992C6B97D200C4275F /* InsetLabel.swift */, @@ -4103,21 +4102,11 @@ 7CC42B062F56A7E900940CE1 /* ZoomedImageViewController */ = { isa = PBXGroup; children = ( - 7CC42B072F56A7F600940CE1 /* Subviews */, D235829E2BC2F5D600D615DD /* ZoomedImageViewController.swift */, ); path = ZoomedImageViewController; sourceTree = ""; }; - 7CC42B072F56A7F600940CE1 /* Subviews */ = { - isa = PBXGroup; - children = ( - F1A000010000000000000002 /* ZoomingCollectionView.swift */, - F1A000010000000000000004 /* ZoomingCollectionViewCell.swift */, - ); - path = Subviews; - sourceTree = ""; - }; 7CC42B082F56AAAD00940CE1 /* CallVan */ = { isa = PBXGroup; children = ( @@ -7885,8 +7874,6 @@ D2A8F8C02C4BCD470090C7A4 /* ShareMenuListUseCase.swift in Sources */, 7C61D3452F220E98005FAC3A /* EditLostItemImagesView.swift in Sources */, D2908D502BBE64B90008F908 /* Removetimetable.swift in Sources */, - F1A000010000000000000001 /* ZoomingCollectionView.swift in Sources */, - F1A000010000000000000003 /* ZoomingCollectionViewCell.swift in Sources */, D2F13E5D2BD0BA2B00172A9D /* NotiAgreementDto.swift in Sources */, 8354BE472C79FCA0009D4D7A /* Model.xcdatamodeld in Sources */, 7C372F292F1D6A7F00149729 /* LostItemDataViewModel.swift in Sources */, @@ -7993,6 +7980,7 @@ 7C16AA392F3E9FBC0071ABE6 /* ErrorViewController.swift in Sources */, 7CF77B6B30056ED4003642C1 /* NoticeKeywordAddButton.swift in Sources */, D235829F2BC2F5D600D615DD /* ZoomedImageViewController.swift in Sources */, + D8C9A09DFDA097189C1CC6DC /* ZoomableImageView.swift in Sources */, D249CD262C12DC2C000813F9 /* FetchDiningListUseCase.swift in Sources */, B46B8CC42E76CC6300A8E797 /* FetchShopSummaryUseCase.swift in Sources */, D20AD70B2E036BC60067760A /* ResetPasswordEmailUseCase.swift in Sources */,