Skip to content

Commit 2e2bb5a

Browse files
committed
[#72] 피드 카테고리 선택 시 팔로잉 버튼까지 스크롤 이동
1 parent 4dd8f1d commit 2e2bb5a

1 file changed

Lines changed: 31 additions & 18 deletions

File tree

Codive/Shared/DesignSystem/Buttons/FeedFilterBar.swift

Lines changed: 31 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -18,29 +18,42 @@ struct FeedFilterBar: View {
1818
// MARK: - Body
1919
var body: some View {
2020
HStack(spacing: 0) {
21-
ScrollView(.horizontal, showsIndicators: false) {
22-
HStack(spacing: 8) {
23-
// 팔로우 버튼
24-
FollowingButton(isSelected: $isFollowingSelected)
25-
26-
// 스타일 카테고리 버튼
27-
ForEach(categories, id: \.self) { category in
28-
let isSelected = selectedCategory.contains(category)
21+
ScrollViewReader { proxy in
22+
ScrollView(.horizontal, showsIndicators: false) {
23+
HStack(spacing: 8) {
24+
Color.clear
25+
.frame(width: 0, height: 0)
26+
.id("scrollAnchor")
2927

30-
FilterSelectionButton(
31-
title: category,
32-
isSelected: isSelected
33-
) {
34-
if selectedCategory.contains(category) {
35-
selectedCategory.remove(category)
36-
} else {
37-
selectedCategory.insert(category)
28+
// 팔로우 버튼
29+
FollowingButton(isSelected: $isFollowingSelected)
30+
31+
// 스타일 카테고리 버튼
32+
ForEach(categories, id: \.self) { category in
33+
let isSelected = selectedCategory.contains(category)
34+
35+
FilterSelectionButton(
36+
title: category,
37+
isSelected: isSelected
38+
) {
39+
if selectedCategory.contains(category) {
40+
selectedCategory.remove(category)
41+
} else {
42+
selectedCategory.insert(category)
43+
}
44+
// 팔로잉 버튼부터 보이도록 맨 앞으로 스크롤
45+
DispatchQueue.main.asyncAfter(deadline: .now() + 0.05) {
46+
withAnimation(.easeInOut(duration: 0.3)) {
47+
proxy.scrollTo("scrollAnchor", anchor: .leading)
48+
}
49+
}
3850
}
51+
.id(category)
3952
}
4053
}
54+
.padding(.leading, 20)
55+
.padding(.trailing, 12)
4156
}
42-
.padding(.leading, 20)
43-
.padding(.trailing, 12)
4457
}
4558

4659
HStack(spacing: 12) {

0 commit comments

Comments
 (0)