diff --git a/iOS/Projects/Features/WriteBoard/Sources/Dombain/Entities/Record.swift b/iOS/Projects/Features/WriteBoard/Sources/Dombain/Entities/Record.swift index 992bd901..5b17c10d 100644 --- a/iOS/Projects/Features/WriteBoard/Sources/Dombain/Entities/Record.swift +++ b/iOS/Projects/Features/WriteBoard/Sources/Dombain/Entities/Record.swift @@ -57,9 +57,9 @@ public extension Record { let hours = Int(timeInterval / 3600) let minutes = Int((timeInterval.truncatingRemainder(dividingBy: 3600)) / 60) if minutes == 0 { - return hours == 0 ? "" : "(\(hours)시간)" + return hours == 0 ? "" : "\(hours)시간" } - return hours == 0 ? "(\(minutes)분)" : "(\(hours)시간\(minutes)분)" + return hours == 0 ? "\(minutes)분" : "\(hours)시간\(minutes)분" } } diff --git a/iOS/Projects/Features/WriteBoard/Sources/Presentation/WirteBoardScene/View/WorkoutHistoryDescriptionView.swift b/iOS/Projects/Features/WriteBoard/Sources/Presentation/WirteBoardScene/View/WorkoutHistoryDescriptionView.swift index 3ac6d3da..8b51e4ef 100644 --- a/iOS/Projects/Features/WriteBoard/Sources/Presentation/WirteBoardScene/View/WorkoutHistoryDescriptionView.swift +++ b/iOS/Projects/Features/WriteBoard/Sources/Presentation/WirteBoardScene/View/WorkoutHistoryDescriptionView.swift @@ -46,7 +46,7 @@ final class WorkoutHistoryDescriptionView: UIStackView { WorkoutHistoryDescriptionRowView(titleString: Constants.workoutName, description: record.name), WorkoutHistoryDescriptionRowView(titleString: Constants.date, description: record.dateString), WorkoutHistoryDescriptionRowView(titleString: Constants.time, description: record.durationTime + " (" + record.startTime + "~" + record.endTime + ")"), - WorkoutHistoryDescriptionRowView(titleString: Constants.distance, description: String(format: "%01f", Double(record.distance) / 1000) + "km"), + WorkoutHistoryDescriptionRowView(titleString: Constants.distance, description: String(format: "%.1f", Double(record.distance) / 1000) + "km"), ]) stackView.axis = .vertical stackView.spacing = Constants.cellSpacing diff --git a/iOS/Projects/Features/WriteBoard/Sources/Presentation/WirteBoardScene/ViewController/AttachPictureViewController.swift b/iOS/Projects/Features/WriteBoard/Sources/Presentation/WirteBoardScene/ViewController/AttachPictureViewController.swift new file mode 100644 index 00000000..fb5c53f1 --- /dev/null +++ b/iOS/Projects/Features/WriteBoard/Sources/Presentation/WirteBoardScene/ViewController/AttachPictureViewController.swift @@ -0,0 +1,122 @@ +// +// AttachPictureViewController.swift +// WriteBoardFeature +// +// Created by MaraMincho on 1/13/24. +// Copyright © 2024 kr.codesquad.boostcamp8. All rights reserved. +// + +import Combine +import UIKit + +// MARK: - AttachPictureViewController + +final class AttachPictureViewController: UICollectionViewController { + // MARK: - Property + + private var subscriptions: Set = [] + + private var attachPictureCollectionViewDataSource: UICollectionViewDiffableDataSource? = nil + + // MARK: - View Life Cycle + + override func viewDidLoad() { + super.viewDidLoad() + } + + // MARK: - Init Function + + init() { + super.init(nibName: nil, bundle: nil) + setup() + } + + @available(*, unavailable) + required init?(coder _: NSCoder) { + fatalError("init(coder:) has not been implemented") + } +} + +private extension AttachPictureViewController { + func setup() { + collectionView = UICollectionView(frame: .zero, collectionViewLayout: .makeAttachPictureCollectionViewLayout()) + collectionView.register(AttachPictureCollectionViewCell.self, forCellWithReuseIdentifier: AttachPictureCollectionViewCell.identifier) + setupStyle() + setAttachPictureCollectionViewDataSource() + } + + func setupStyle() { + collectionView.backgroundColor = .clear + } + + func setAttachPictureCollectionViewDataSource() { + attachPictureCollectionViewDataSource = .init(collectionView: collectionView) { collectionView, indexPath, itemIdentifier in + guard + let cell = collectionView.dequeueReusableCell( + withReuseIdentifier: AttachPictureCollectionViewCell.identifier, + for: indexPath + ) as? AttachPictureCollectionViewCell + else { + return UICollectionViewCell() + } + + cell.configure(image: itemIdentifier) + return cell + } + guard + var snapshot = attachPictureCollectionViewDataSource?.snapshot(), + let addPicImage = Constants.addPictureImage, + let testImage = UIImage(systemName: "figure.run") + else { + return + } + snapshot.appendSections([0]) + snapshot.appendItems([addPicImage, testImage]) + attachPictureCollectionViewDataSource?.apply(snapshot) + } + + private enum Constants { + static let addPictureImage: UIImage? = .init(systemName: "plus") + } +} + +private extension UICollectionViewLayout { + static func makeAttachPictureCollectionViewLayout() -> UICollectionViewLayout { + let itemSize = NSCollectionLayoutSize( + widthDimension: .absolute(attachPictureCollectionViewCellConstants.width), + heightDimension: .fractionalHeight(1) + ) + let item = NSCollectionLayoutItem(layoutSize: itemSize) + item.contentInsets = .init( + top: 0, + leading: attachPictureCollectionViewCellConstants.itemLeadingAndTrailingInset, + bottom: 0, + trailing: attachPictureCollectionViewCellConstants.itemLeadingAndTrailingInset + ) + + let groupSize = NSCollectionLayoutSize( + widthDimension: .fractionalWidth(1), + heightDimension: .absolute(attachPictureCollectionViewCellConstants.height) + ) + let group = NSCollectionLayoutGroup.horizontal(layoutSize: groupSize, subitems: [item]) + group.contentInsets = .init( + top: 0, + leading: attachPictureCollectionViewCellConstants.groupLeadingAndTrailingInset, + bottom: 0, + trailing: attachPictureCollectionViewCellConstants.groupLeadingAndTrailingInset + ) + + let section = NSCollectionLayoutSection(group: group) + + return UICollectionViewCompositionalLayout(section: section) + } + + private enum attachPictureCollectionViewCellConstants { + static let height: CGFloat = 94 + static let width: CGFloat = 94 + + static let itemLeadingAndTrailingInset: CGFloat = 6 + + static let groupLeadingAndTrailingInset: CGFloat = 29 + } +} diff --git a/iOS/Projects/Features/WriteBoard/Sources/Presentation/WirteBoardScene/ViewController/WriteBoardViewController.swift b/iOS/Projects/Features/WriteBoard/Sources/Presentation/WirteBoardScene/ViewController/WriteBoardViewController.swift index 45b8007f..1329ceb7 100644 --- a/iOS/Projects/Features/WriteBoard/Sources/Presentation/WirteBoardScene/ViewController/WriteBoardViewController.swift +++ b/iOS/Projects/Features/WriteBoard/Sources/Presentation/WirteBoardScene/ViewController/WriteBoardViewController.swift @@ -18,8 +18,6 @@ final class WriteBoardViewController: UIViewController { private let viewModel: WriteBoardViewModelRepresentable - private var attachPictureCollectionViewDataSource: UICollectionViewDiffableDataSource? = nil - private let completeButtonDidTapPublisher: PassthroughSubject = .init() private var subscriptions: Set = [] @@ -46,15 +44,7 @@ final class WriteBoardViewController: UIViewController { return label }() - private lazy var attachPictureCollectionView: UICollectionView = { - let collectionView = UICollectionView(frame: .zero, collectionViewLayout: .makeAttachPictureCollectionViewLayout()) - collectionView.register(AttachPictureCollectionViewCell.self, forCellWithReuseIdentifier: AttachPictureCollectionViewCell.identifier) - collectionView.delegate = self - collectionView.backgroundColor = .clear - - collectionView.translatesAutoresizingMaskIntoConstraints = false - return collectionView - }() + private let attachPictureViewController = AttachPictureViewController() private let boardDetailTitleLabel: UILabel = { let label = UILabel() @@ -111,39 +101,12 @@ final class WriteBoardViewController: UIViewController { private extension WriteBoardViewController { func setup() { workoutHistoryDescriptionView = .init(record: viewModel.record()) - setAttachPictureCollectionViewDataSource() setupStyles() setupHierarchyAndConstraints() bind() setupNavigationItem() } - func setAttachPictureCollectionViewDataSource() { - attachPictureCollectionViewDataSource = .init(collectionView: attachPictureCollectionView) { collectionView, indexPath, itemIdentifier in - guard - let cell = collectionView.dequeueReusableCell( - withReuseIdentifier: AttachPictureCollectionViewCell.identifier, - for: indexPath - ) as? AttachPictureCollectionViewCell - else { - return UICollectionViewCell() - } - - cell.configure(image: itemIdentifier) - return cell - } - guard - var snapshot = attachPictureCollectionViewDataSource?.snapshot(), - let addPicImage = Constants.addPictureImage, - let testImage = UIImage(systemName: "figure.run") - else { - return - } - snapshot.appendSections([0]) - snapshot.appendItems([addPicImage, testImage]) - attachPictureCollectionViewDataSource?.apply(snapshot) - } - func setupNavigationItem() { navigationItem.backButtonTitle = "뒤로" navigationItem.title = "글쓰기" @@ -177,7 +140,10 @@ private extension WriteBoardViewController { attachPictureTitleLabel.leadingAnchor .constraint(equalTo: workoutHistoryDescriptionView.leadingAnchor).isActive = true + // TODO: View에 관한 layout이 어떻게 이루어지는지 그리고 View에 lifeCycle에 대해서 자세하게 공부하기 + guard let attachPictureCollectionView = attachPictureViewController.collectionView else { return } contentScrollView.addSubview(attachPictureCollectionView) + attachPictureCollectionView.translatesAutoresizingMaskIntoConstraints = false attachPictureCollectionView.topAnchor .constraint(equalTo: attachPictureTitleLabel.bottomAnchor, constant: Metrics.attachPictureBottomSpacing).isActive = true attachPictureCollectionView.leadingAnchor @@ -236,57 +202,10 @@ private extension WriteBoardViewController { enum Constants { static let pictureTitleLabelText = "사진" - - static let addPictureImage: UIImage? = .init(systemName: "plus") - } -} - -// MARK: UICollectionViewDelegate - -extension WriteBoardViewController: UICollectionViewDelegate {} - -extension UICollectionViewLayout { - static func makeAttachPictureCollectionViewLayout() -> UICollectionViewLayout { - let itemSize = NSCollectionLayoutSize( - widthDimension: .absolute(attachPictureCollectionViewCellConstants.width), - heightDimension: .fractionalHeight(1) - ) - let item = NSCollectionLayoutItem(layoutSize: itemSize) - item.contentInsets = .init( - top: 0, - leading: attachPictureCollectionViewCellConstants.itemLeadingAndTrailingInset, - bottom: 0, - trailing: attachPictureCollectionViewCellConstants.itemLeadingAndTrailingInset - ) - - let groupSize = NSCollectionLayoutSize( - widthDimension: .fractionalWidth(1), - heightDimension: .absolute(attachPictureCollectionViewCellConstants.height) - ) - let group = NSCollectionLayoutGroup.horizontal(layoutSize: groupSize, subitems: [item]) - group.contentInsets = .init( - top: 0, - leading: attachPictureCollectionViewCellConstants.groupLeadingAndTrailingInset, - bottom: 0, - trailing: attachPictureCollectionViewCellConstants.groupLeadingAndTrailingInset - ) - - let section = NSCollectionLayoutSection(group: group) - - return UICollectionViewCompositionalLayout(section: section) - } - - private enum attachPictureCollectionViewCellConstants { - static let height: CGFloat = 94 - static let width: CGFloat = 94 - - static let itemLeadingAndTrailingInset: CGFloat = 6 - - static let groupLeadingAndTrailingInset: CGFloat = 29 } } -// MARK: - WriteBoardViewController + UIScrollViewDelegate +// MARK: UIScrollViewDelegate extension WriteBoardViewController: UIScrollViewDelegate { func scrollViewDidScroll(_ scrollView: UIScrollView) {