Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,12 @@ extension HomeController {
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
tabBarController?.tabBar.isHidden = false
restartBannerAutoScroll()
}

override func viewWillDisappear(_ animated: Bool) {
super.viewWillDisappear(animated)
stopBannerAutoScroll() // 화면을 벗어나면 스크롤 중지
}
}

Expand Down Expand Up @@ -128,6 +134,20 @@ extension HomeController {
}
.disposed(by: disposeBag)
}

private func stopBannerAutoScroll() {
let indexPath = IndexPath(row: 0, section: 0) // 배너 섹션 인덱스
if let cell = mainView.contentCollectionView.cellForItem(at: indexPath) as? ImageBannerSectionCell {
cell.stopAutoScroll()
}
}

private func restartBannerAutoScroll() {
let indexPath = IndexPath(row: 0, section: 0)
if let cell = mainView.contentCollectionView.cellForItem(at: indexPath) as? ImageBannerSectionCell {
cell.startAutoScroll()
}
}
Comment on lines +138 to +150
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

cellForItem(at:) 사용의 한계를 고려해야 합니다.

두 헬퍼 메서드 모두 cellForItem(at:)을 사용하여 배너 셀에 접근하는데, 이 메서드는 셀이 현재 화면에 보이는 경우에만 셀을 반환합니다. 사용자가 스크롤하여 배너가 화면 밖에 있는 경우, 이 메서드들은 아무 동작도 하지 않습니다.

더 견고한 접근 방법을 고려하세요:

  • 셀 자체의 생명주기 메서드(willMove(toWindow:) 등)에서 타이머를 관리
  • 또는 뷰 컨트롤러에서 배너 섹션의 타이머 상태를 직접 추적

다음 개선 방안을 적용할 수 있습니다:

private func stopBannerAutoScroll() {
    let indexPath = IndexPath(row: 0, section: 0)
    if let cell = mainView.contentCollectionView.cellForItem(at: indexPath) as? ImageBannerSectionCell {
        cell.stopAutoScroll()
    }
    // 대안: 섹션 데이터 모델에 상태를 저장하여 셀이 나타날 때 적용
}

private func restartBannerAutoScroll() {
    let indexPath = IndexPath(row: 0, section: 0)
    if let cell = mainView.contentCollectionView.cellForItem(at: indexPath) as? ImageBannerSectionCell {
        cell.startAutoScroll()
    }
    // 대안: 섹션 데이터 모델에 상태를 저장하여 셀이 나타날 때 적용
}

또는 UICollectionViewDelegatewillDisplay 메서드를 활용하는 방법도 고려하세요.

🤖 Prompt for AI Agents
Poppool/PresentationLayer/Presentation/Presentation/Scene/Home/Main/HomeController.swift
lines 138-150: stopBannerAutoScroll() and restartBannerAutoScroll() rely on
cellForItem(at:) which returns a cell only if it's visible, so they silently do
nothing when the banner cell is offscreen; fix by tracking the banner timer
state in the controller or section model and ensuring the cell applies that
state when it appears, or move timer control into the cell lifecycle: (1) add a
Bool flag (e.g., isBannerAutoScrollEnabled) in the view controller or section
data and set it in stopBannerAutoScroll/restartBannerAutoScroll instead of only
calling cell methods, (2) implement collectionView(_:willDisplay:forItemAt:) to
start/stop the cell’s auto-scroll based on that flag when the cell is about to
appear, or (3) alternatively, move timer management into ImageBannerSectionCell
(override willMove(toWindow:) or didMoveToWindow) so the cell starts/stops its
timer when added/removed from window and expose public start/stop only for
explicit controller overrides.

}

// MARK: - UICollectionViewDelegate, UICollectionViewDataSource
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ final class ImageBannerSectionCell: UICollectionViewCell {

var disposeBag = DisposeBag()

private var autoScrollTimer: Timer?
private weak var autoScrollTimer: Timer?

private lazy var contentCollectionView: UICollectionView = {
let view = UICollectionView(frame: .zero, collectionViewLayout: compositionalLayout)
Expand Down Expand Up @@ -73,10 +73,15 @@ final class ImageBannerSectionCell: UICollectionViewCell {

override func prepareForReuse() {
super.prepareForReuse()
stopAutoScroll()
disposeBag = DisposeBag()
isFirstResponseAutoScroll = false
}

deinit {
stopAutoScroll()
}

// 자동 스크롤 중지 함수
func stopAutoScroll() {
stopButton.isHidden = true
Expand Down