Skip to content

Commit

Permalink
Merge pull request #149 from JORDYMA-Link/BUG/#148
Browse files Browse the repository at this point in the history
[BUG] 홈 ScrollViewProxy 이슈 수정
  • Loading branch information
kimkyuchul authored Nov 27, 2024
2 parents 7d5e4e9 + 70e5b5e commit 7103b36
Show file tree
Hide file tree
Showing 11 changed files with 38 additions and 16 deletions.
2 changes: 1 addition & 1 deletion Projects/Feature/Scene/Common/BKCard/BKCardView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ struct BKCardView: View {
@ViewBuilder
private func loadingView() -> some View {
BKLoadingIndicator()
.frame(minHeight: emptyHeight)
.frame(maxWidth: .infinity, minHeight: emptyHeight)
.background(Color.bkColor(.gray300))
}

Expand Down
8 changes: 3 additions & 5 deletions Projects/Feature/Scene/Home/Home/HomeFeature.swift
Original file line number Diff line number Diff line change
Expand Up @@ -168,8 +168,8 @@ public struct HomeFeature: Reducer {
} else {
state.category = categoryType
return .concatenate(
.send(.feeds(.setCategory(categoryType))),
.send(.feeds(.setLoading(true)), animation: .default),
.send(.feeds(.setCategory(categoryType))),
.send(.setMorePagingStatus(true)),
.send(.feeds(.resetPage))
.throttle(id: ThrottleId.categoryButton, for: .seconds(0.3), scheduler: DispatchQueue.main, latest: true)
Expand All @@ -180,9 +180,7 @@ public struct HomeFeature: Reducer {
return .concatenate(
.send(.feeds(.setLoading(true)), animation: .default),
.send(.setMorePagingStatus(true)),
.run { send in
await send(.feeds(.resetPage))
}
.run { send in await send(.feeds(.resetPage)) }
.debounce(id: DebounceId.pullToRefresh, for: .seconds(0.3), scheduler: DispatchQueue.main)
)

Expand Down Expand Up @@ -261,7 +259,7 @@ public struct HomeFeature: Reducer {
print(error)
}
)

case let .setFeeds(feedList):
state.feeds = .init(feedList: feedList)
return .none
Expand Down
17 changes: 7 additions & 10 deletions Projects/Feature/Scene/Home/Home/HomeView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,9 @@ public struct HomeView: View {
VStack(spacing: 0) {
CategoryHeaderView(
store: store,
scrollAction: {
withAnimation {
scrollProxy.scrollTo(topID, anchor: .top)
scrollAction: { type in
scrollProxy.scrollTo(topID, anchor: .top) {
store.send(.categoryButtonTapped(type), animation: .default)
}
}
)
Expand Down Expand Up @@ -173,11 +173,11 @@ private struct HomeBanner: View {

private struct CategoryHeaderView: View {
@Perception.Bindable private var store: StoreOf<HomeFeature>
private let scrollAction: () -> Void
private let scrollAction: (CategoryType) -> Void

init(
store: StoreOf<HomeFeature>,
scrollAction: @escaping () -> Void
scrollAction: @escaping (CategoryType) -> Void
) {
self.store = store
self.scrollAction = scrollAction
Expand All @@ -191,10 +191,7 @@ private struct CategoryHeaderView: View {
BKCategoryButton(
title: type.title,
isSelected: store.category == type,
action: {
scrollAction()
store.send(.categoryButtonTapped(type), animation: .default)
}
action: { scrollAction(type) }
)
}
}
Expand Down Expand Up @@ -224,7 +221,7 @@ final class ScrollViewDelegate: NSObject, UIScrollViewDelegate, ObservableObject

func scrollViewDidScroll(_ scrollView: UIScrollView) {
DispatchQueue.main.async {
self.isScrollDetected = scrollView.contentOffset.y > self.headerMaxY
self.isScrollDetected = scrollView.contentOffset.y > self.headerMaxY
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
//
// ScrollViewProxy+.swift
// Common
//
// Created by kyuchul on 11/27/24.
// Copyright © 2024 com.kyuchul.blink. All rights reserved.
//

import SwiftUI

public extension SwiftUI.ScrollViewProxy {
func scrollTo<ID>(
_ id: ID,
anchor: UnitPoint? = nil,
action: @escaping () -> Void
) where ID: Hashable {
DispatchQueue.main.async {
withAnimation(.none) {
self.scrollTo(id, anchor: anchor)
}

DispatchQueue.main.asyncAfter(deadline: .now() + 0.1) {
action()
}
}
}
}

0 comments on commit 7103b36

Please sign in to comment.