Skip to content

Feat/#482 댓글 자동스크롤 기능 구현 - #483

Merged
y-eonee merged 5 commits into
developfrom
feat/#482-댓글-자동스크롤
Aug 3, 2026

Hidden character warning

The head ref may contain hidden characters: "feat/#482-\ub313\uae00-\uc790\ub3d9\uc2a4\ud06c\ub864"
Merged

Feat/#482 댓글 자동스크롤 기능 구현 #483
y-eonee merged 5 commits into
developfrom
feat/#482-댓글-자동스크롤

Conversation

@y-eonee

@y-eonee y-eonee commented Aug 3, 2026

Copy link
Copy Markdown
Member

🔗 연결된 이슈

📄 작업 내용

  • 댓글 및 답글 자동 스크롤 기능을 구현했습니다.
구현 내용 댓글 답글
GIF

💻 주요 코드 설명

답글 자동 스크롤

답글 작성이 완료되는 시점에서 스크롤 함수를 호출합니다.

private func scrollToComment() {
        let snapshot = dataSource.snapshot()
        let replyCount = snapshot.numberOfItems(inSection: .replies)
        guard replyCount > 0 else { return }
        rootView.layoutIfNeeded()
        let lastIndex = IndexPath(row: replyCount - 1, section: 1)
        rootView.commentListView.scrollToRow(at: lastIndex, at: .bottom, animated: true)
}

마지막 인덱스를 구해서 UITableView의 함수 scrollToRow의 파라미터로 사용합니다.

댓글 자동 스크롤

ReplyVC에서는 일반 UITableView를 사용하는데, HistoryVC에서는 UITableView를 커스텀한 Self-sizing TableView를 사용합니다.
이때 tableview 자체의 scroll이 꺼져있기 때문에 scrollToRow를 사용할 수 없었습니다.

private func scrollToComment() {
        let snapshot = dataSource.snapshot()
        guard snapshot.numberOfItems > 0 else { return }
        rootView.layoutIfNeeded()

        let lastIndex = IndexPath(row: snapshot.numberOfItems - 1, section: 0)
        let rowRect = rootView.commentListView.rectForRow(at: lastIndex) // 마지막 인덱스에 해당하는 행의 Rect 크기와 좌표를 구합니다. 
        var rectInScrollView = rootView.commentListView.convert(rowRect, to: rootView.scrollView) // 스크롤뷰의 좌표계로 변환
        rectInScrollView.size.height = rootView.scrollView.contentSize.height - rectInScrollView.origin.y 

        rootView.scrollView.scrollRectToVisible(rectInScrollView, animated: true)
}
rectInScrollView.size.height = rootView.scrollView.contentSize.height - rectInScrollView.origin.y 

이 변환 없이 scrollRect를 하게 되면 rect의 top으로 스크롤 되어 댓글 내용이 다 보이지 않게 되는 문제가 있었습니다.
그래서 scrollView의 height에서 rect의 y가 어디서 시작하는지를 빼서 마지막 댓글의 top부터 스크롤뷰 하단까지의 높이가 rect height가 되도록 보정을 거쳤습니다.

Summary by CodeRabbit

  • 개선 사항

    • 댓글 등록 후 댓글 목록이 새로 추가된 마지막 댓글로 자동 스크롤됩니다.
    • 답글 등록 후 답글 목록이 마지막 답글 위치로 자동 스크롤됩니다.
    • 등록된 댓글이나 답글이 없을 때 불필요한 스크롤 동작이 발생하지 않습니다.
  • 기타

    • 앱 및 테스트 버전 정보가 업데이트되었습니다.

@y-eonee y-eonee self-assigned this Aug 3, 2026
@y-eonee y-eonee added 나연🐹 feat 새로운 기능 구현 및 API 연결 labels Aug 3, 2026
@y-eonee y-eonee linked an issue Aug 3, 2026 that may be closed by this pull request
1 task
@coderabbitai

coderabbitai Bot commented Aug 3, 2026

Copy link
Copy Markdown

Review Change Stack

Walkthrough

댓글과 답글 등록 성공 후 목록의 마지막 항목으로 자동 스크롤합니다. 등록 publisher의 self 캡처를 안전하게 처리합니다. 앱과 테스트 타깃의 빌드 버전을 갱신합니다.

Changes

댓글 및 답글 자동 스크롤

Layer / File(s) Summary
등록 후 마지막 항목 스크롤
ByeBoo-iOS/ByeBoo-iOS/Presentation/Feature/Quest/ViewController/CommonQuestHistoryViewController.swift, ByeBoo-iOS/ByeBoo-iOS/Presentation/Feature/Quest/ViewController/CommonQuestReplyViewController.swift
댓글과 답글 등록 성공 후 scrollToComment()을 호출합니다. 항목이 없으면 종료하고, 레이아웃을 갱신한 뒤 마지막 항목으로 애니메이션 스크롤합니다.
컨트롤러 생명주기 처리
ByeBoo-iOS/ByeBoo-iOS/Presentation/Feature/Quest/ViewController/CommonQuestHistoryViewController.swift
댓글 등록 publisher가 self를 약하게 캡처합니다. 인스턴스가 없으면 처리를 종료합니다.

빌드 버전 갱신

Layer / File(s) Summary
타깃 빌드 버전 갱신
ByeBoo-iOS/ByeBoo-iOS.xcodeproj/project.pbxproj
앱 타깃의 Debug 및 Release CURRENT_PROJECT_VERSION18로 변경했습니다. ByeBooTests 타깃의 값을 15로 변경했습니다.

Estimated code review effort: 2 (Simple) | ~10 minutes

Sequence Diagram(s)

sequenceDiagram
  participant CommentPublisher as 댓글 등록 publisher
  participant HistoryVC as CommonQuestHistoryViewController
  participant ScrollView as 스크롤 뷰
  CommentPublisher->>HistoryVC: 등록 성공 전달
  HistoryVC->>HistoryVC: 마지막 댓글 확인 및 레이아웃 갱신
  HistoryVC->>ScrollView: 마지막 댓글로 애니메이션 스크롤
Loading
sequenceDiagram
  participant ReplyPublisher as 답글 등록 publisher
  participant ReplyVC as CommonQuestReplyViewController
  participant ScrollView as 스크롤 뷰
  ReplyPublisher->>ReplyVC: 등록 성공 전달
  ReplyVC->>ReplyVC: 마지막 답글 확인 및 레이아웃 갱신
  ReplyVC->>ScrollView: 마지막 답글로 애니메이션 스크롤
Loading

Possibly related PRs

Suggested reviewers: dev-domo, juri123123

Poem

토끼가 댓글을 남기면
목록 끝까지 깡충 이동해요.
답글도 마지막 줄에 닿고
새 버전 숫자도 반짝 올라요.
당근처럼 깔끔한 변경이에요.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed 제목은 댓글 자동 스크롤 기능 구현이라는 풀 리퀘스트의 주요 변경 사항을 명확하게 설명합니다.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/#482-댓글-자동스크롤

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@juri123123 juri123123 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

LGTM

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In
`@ByeBoo-iOS/ByeBoo-iOS/Presentation/Feature/Quest/ViewController/CommonQuestHistoryViewController.swift`:
- Around line 316-321: 게시 성공 이벤트와 목록 snapshot 적용 순서를 보장하도록
CommonQuestHistoryViewController의 postComment/postReply 흐름을 수정하고,
CommonQuestHistoryViewController.swift 316-321 및
CommonQuestReplyViewController.swift 103-108의 성공 처리도 동일하게 반영하세요. fetchPublisher
완료와 dataSource.apply 호출 이후에 성공 이벤트가 발생하도록 연결하거나, 해당 이벤트 핸들러의 scrollToComment 호출을
snapshot 적용 완료 후로 이동해 새 댓글이 표시된 뒤 스크롤되게 하세요.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 9439ea8f-942c-4eb5-9f09-2dd54c87e30d

📥 Commits

Reviewing files that changed from the base of the PR and between 29ba1b0 and 6cf0a21.

📒 Files selected for processing (3)
  • ByeBoo-iOS/ByeBoo-iOS.xcodeproj/project.pbxproj
  • ByeBoo-iOS/ByeBoo-iOS/Presentation/Feature/Quest/ViewController/CommonQuestHistoryViewController.swift
  • ByeBoo-iOS/ByeBoo-iOS/Presentation/Feature/Quest/ViewController/CommonQuestReplyViewController.swift

Comment on lines +316 to +321
.sink { [weak self] result in
guard let self else { return }
switch result {
case .success:
ByeBooLogger.debug("댓글 입력 성공")
self.scrollToComment()

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🗄️ Data Integrity & Integration | 🟡 Minor | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

#!/usr/bin/env bash
set -euo pipefail

# 게시 성공과 목록 적용 순서를 확인합니다.
rg -n -C 12 \
  'postCommentPublisher|postReplyPublisher|fetchCommonQuestDetailPublisher|fetchReplyListPublisher|applySnapshot|scrollToComment' \
  --glob '*.swift'

Repository: 36-APPJAM-HEARTZ/BYEBOO-iOS

Length of output: 165


🏁 Script executed:

#!/usr/bin/env bash
set -euo pipefail

printf 'Swift files matching controller names:\n'
fd -i 'CommonQuest(Reply|History)ViewController\.swift|CommonQuest.*Reply.*\.swift|CommonQuest.*History.*\.swift' ByeBoo-iOS/ByeBoo-iOS || true

printf '\nSearch identifiers with broader terms:\n'
rg -n -C 8 \
  'scrollToComment|scrollToItem|apply\(Snapshot|snapshot|Append|Update|Insert|deleteItems|reloadData|func post|publisher|Subject|Publishers\.Merge|defer' \
  ByeBoo-iOS/ByeBoo-iOS/Presentation/Feature/Quest 2>/dev/null || true

printf '\nInspect candidate file outlines:\n'
for f in $(fd -i 'CommonQuest(Reply|History)ViewController\.swift' ByeBoo-iOS/ByeBoo-iOS); do
  echo "--- $f ---"
  wc -l "$f"
  ast-grep outline "$f" --view compact || true
done

Repository: 36-APPJAM-HEARTZ/BYEBOO-iOS

Length of output: 50384


🏁 Script executed:

#!/usr/bin/env bash
set -euo pipefail

for f in \
  'ByeBoo-iOS/ByeBoo-iOS/Presentation/Feature/Quest/ViewController/CommonQuestHistoryViewController.swift' \
  'ByeBoo-iOS/ByeBoo-iOS/Presentation/Feature/Quest/ViewController/CommonQuestReplyViewController.swift' \
  'ByeBoo-iOS/ByeBoo-iOS/Presentation/Feature/Quest/ViewModel/CommonQuestHistoryViewModel.swift' \
  'ByeBoo-iOS/ByeBoo-iOS/Presentation/Feature/Quest/ViewModel/CommonQuestReplyViewModel.swift'
do
  echo "--- $f ---"
  wc -l "$f"
  sed -n '1,240p' "$f"
done

echo '--- action enum candidates ---'
rg -n -C 4 'case (postComment|postReply|fetchQuestDetail|fetchReplyList|detail|replyList|FetchQuest|FetchReply)' \
  ByeBoo-iOS/ByeBoo-iOS/Presentation/Feature/Quest/ViewController/CommonQuestHistoryViewController.swift \
  ByeBoo-iOS/ByeBoo-iOS/Presentation/Feature/Quest/ViewController/CommonQuestReplyViewController.swift \
  ByeBoo-iOS/ByeBoo-iOS/Presentation/Feature/Quest/ViewModel/CommonQuestHistoryViewModel.swift \
  ByeBoo-iOS/ByeBoo-iOS/Presentation/Feature/Quest/ViewModel/CommonQuestReplyViewModel.swift

Repository: 36-APPJAM-HEARTZ/BYEBOO-iOS

Length of output: 31515


게시 성공 이벤트와 목록 snapshot 적용 순서를 맞춰주세요.

postComment() / postReply()는 목록을 먼저 업데이트하고 성공 이벤트를 보냅니다. 성공 핸들러는 이를 기다리지 않고 바로 scrollToComment()를 호출하므로, 게시 직후 목록에 새 댓글이 없으면 스크롤 대상이 없습니다. 게시 성공 이벤트는 목록 fetchPublisher + dataSource.apply 호출 이후에 생성되도록 변경하거나, 성공 처리기에서 snapshot 적용 완료 뒤에 scrollToComment()를 호출하도록 연결하세요.

📍 Affects 2 files
  • ByeBoo-iOS/ByeBoo-iOS/Presentation/Feature/Quest/ViewController/CommonQuestHistoryViewController.swift#L316-L321 (this comment)
  • ByeBoo-iOS/ByeBoo-iOS/Presentation/Feature/Quest/ViewController/CommonQuestReplyViewController.swift#L103-L108
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In
`@ByeBoo-iOS/ByeBoo-iOS/Presentation/Feature/Quest/ViewController/CommonQuestHistoryViewController.swift`
around lines 316 - 321, 게시 성공 이벤트와 목록 snapshot 적용 순서를 보장하도록
CommonQuestHistoryViewController의 postComment/postReply 흐름을 수정하고,
CommonQuestHistoryViewController.swift 316-321 및
CommonQuestReplyViewController.swift 103-108의 성공 처리도 동일하게 반영하세요. fetchPublisher
완료와 dataSource.apply 호출 이후에 성공 이벤트가 발생하도록 연결하거나, 해당 이벤트 핸들러의 scrollToComment 호출을
snapshot 적용 완료 후로 이동해 새 댓글이 표시된 뒤 스크롤되게 하세요.

@dev-domo dev-domo left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

확인 완!!

@y-eonee
y-eonee merged commit 301ea78 into develop Aug 3, 2026
2 checks passed
@y-eonee
y-eonee deleted the feat/#482-댓글-자동스크롤 branch August 3, 2026 08:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

feat 새로운 기능 구현 및 API 연결 나연🐹

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feat] 댓글 자동스크롤 기능 구현

3 participants