-
Notifications
You must be signed in to change notification settings - Fork 0
[FIX] 스크롤이 튕기는 문제 해결 #133
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[FIX] 스크롤이 튕기는 문제 해결 #133
Changes from all commits
4a00617
2d75d3b
b593626
1c72dd3
7d82d2a
5996f6e
b85b113
6d0b611
6497a30
d4c7a81
0b57cd5
00f5342
7ccb36d
a53ff06
3ae769e
7574d2b
904830f
57e7a84
12bbf10
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -23,14 +23,17 @@ final class SearchController: BaseViewController, View { | |
| private var mainView = SearchView() | ||
| private var sections: [any Sectionable] = [] | ||
| private let cellTapped: PublishSubject<IndexPath> = .init() | ||
| private let pageChange: PublishSubject<Void> = .init() | ||
| private let loadNextPage = PublishSubject<Void>() | ||
| } | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 변수명을 더 직관적으로 변경하셨군요 😂 |
||
|
|
||
| // MARK: - Life Cycle | ||
| extension SearchController { | ||
| override func viewDidLoad() { | ||
| super.viewDidLoad() | ||
| setUp() | ||
|
|
||
| self.addViews() | ||
| self.setupContstraints() | ||
| self.configureUI() | ||
| } | ||
|
|
||
| override func viewWillAppear(_ animated: Bool) { | ||
|
|
@@ -41,36 +44,50 @@ extension SearchController { | |
|
|
||
| // MARK: - SetUp | ||
| private extension SearchController { | ||
| func setUp() { | ||
| func addViews() { | ||
| [mainView].forEach { | ||
| self.view.addSubview($0) | ||
| } | ||
| } | ||
|
|
||
| func setupContstraints() { | ||
| mainView.snp.makeConstraints { make in | ||
| make.edges.equalTo(view.safeAreaLayoutGuide) | ||
| } | ||
| } | ||
|
|
||
| func configureUI() { | ||
| if let layout = reactor?.compositionalLayout { | ||
| mainView.contentCollectionView.collectionViewLayout = layout | ||
| } | ||
|
|
||
| mainView.contentCollectionView.delegate = self | ||
| mainView.contentCollectionView.dataSource = self | ||
|
|
||
| mainView.contentCollectionView.register( | ||
| SearchTitleSectionCell.self, | ||
| forCellWithReuseIdentifier: SearchTitleSectionCell.identifiers | ||
| ) | ||
|
|
||
| mainView.contentCollectionView.register( | ||
| SpacingSectionCell.self, | ||
| forCellWithReuseIdentifier: SpacingSectionCell.identifiers | ||
| ) | ||
|
|
||
| mainView.contentCollectionView.register( | ||
| CancelableTagSectionCell.self, | ||
| forCellWithReuseIdentifier: CancelableTagSectionCell.identifiers | ||
| ) | ||
|
|
||
| mainView.contentCollectionView.register( | ||
| SearchCountTitleSectionCell.self, | ||
| forCellWithReuseIdentifier: SearchCountTitleSectionCell.identifiers | ||
| ) | ||
|
|
||
| mainView.contentCollectionView.register( | ||
| HomeCardSectionCell.self, | ||
| forCellWithReuseIdentifier: HomeCardSectionCell.identifiers | ||
| ) | ||
| view.addSubview(mainView) | ||
| mainView.snp.makeConstraints { make in | ||
| make.edges.equalTo(view.safeAreaLayoutGuide) | ||
| } | ||
| } | ||
| } | ||
|
|
||
|
|
@@ -90,19 +107,45 @@ extension SearchController { | |
| .bind(to: reactor.action) | ||
| .disposed(by: disposeBag) | ||
|
|
||
| pageChange | ||
| .throttle(.milliseconds(1000), scheduler: MainScheduler.asyncInstance) | ||
| .map { Reactor.Action.changePage } | ||
| loadNextPage | ||
| .throttle(.seconds(1), latest: false, scheduler: MainScheduler.asyncInstance) | ||
| .map { Reactor.Action.loadNextPage } | ||
| .bind(to: reactor.action) | ||
| .disposed(by: disposeBag) | ||
|
|
||
| reactor.state | ||
| .filter { $0.newBottomSearchList.isEmpty && $0.bottomSearchListLastIndexPath == nil } | ||
| .withUnretained(self) | ||
| .subscribe { (owner, state) in | ||
| .subscribe { owner, state in | ||
| owner.sections = state.sections | ||
| owner.mainView.contentCollectionView.reloadData() | ||
| } | ||
| .disposed(by: disposeBag) | ||
|
|
||
| reactor.state | ||
| .map { (sections: $0.sections, | ||
| newItems: $0.newBottomSearchList, | ||
| indexPath: $0.bottomSearchListLastIndexPath) } | ||
| .filter { !$0.newItems.isEmpty && $0.indexPath != nil } | ||
| .withUnretained(self) | ||
| .subscribe { (owner, subscribeResponse) in | ||
| let (updatedSections, newPopUpItems, popUpGridindexPath) = subscribeResponse | ||
| guard let popUpGridindexPath = popUpGridindexPath else { return } | ||
|
|
||
| let start = popUpGridindexPath.item | ||
| let count = newPopUpItems.count | ||
| let section = popUpGridindexPath.section | ||
| let indexPaths = (start..<start+count).map { | ||
| IndexPath(item: $0, section: section) | ||
| } | ||
|
|
||
| owner.mainView.contentCollectionView.performBatchUpdates { | ||
| // 데이터 모델을 업데이트한 뒤 삽입 | ||
| owner.sections = updatedSections | ||
| owner.mainView.contentCollectionView.insertItems(at: indexPaths) | ||
| } | ||
| } | ||
| .disposed(by: disposeBag) | ||
| } | ||
| } | ||
|
|
||
|
|
@@ -122,8 +165,9 @@ extension SearchController: UICollectionViewDelegate, UICollectionViewDataSource | |
| ) -> UICollectionViewCell { | ||
| let cell = sections[indexPath.section].getCell(collectionView: collectionView, indexPath: indexPath) | ||
| guard let userDefaultService = reactor?.userDefaultService else { return cell } | ||
| var searchList = userDefaultService.fetchArray(key: "searchList") ?? [] | ||
| let searchList = userDefaultService.fetchArray(key: "searchList") ?? [] | ||
| guard let reactor = reactor else { return cell } | ||
|
|
||
| if let cell = cell as? SearchTitleSectionCell { | ||
| cell.titleButton.rx.tap | ||
| .map { Reactor.Action.recentSearchListAllDeleteButtonTapped } | ||
|
|
@@ -168,6 +212,7 @@ extension SearchController: UICollectionViewDelegate, UICollectionViewDataSource | |
| .bind(to: reactor.action) | ||
| .disposed(by: cell.disposeBag) | ||
| } | ||
|
|
||
| return cell | ||
| } | ||
|
|
||
|
|
@@ -177,7 +222,7 @@ extension SearchController: UICollectionViewDelegate, UICollectionViewDataSource | |
| let scrollViewHeight = scrollView.frame.size.height | ||
| let contentOffsetY = scrollView.contentOffset.y | ||
| if contentOffsetY + scrollViewHeight >= contentHeight { | ||
| pageChange.onNext(()) | ||
| loadNextPage.onNext(()) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 스크롤 이벤트 포인트가 변경되지는 않았군요!!
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 아마 몇개셀 이전에 돌아가도록 하면 좋긴 하겠는데, 추후 새로운 피쳐로 재구성을 염두하고 있어서 그런지 불필요한 작업이라 판단해서 추후 작업할때 반영해볼것 같아요! |
||
| } | ||
| } | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
configureIUI와 addViews에서 뷰추가가 중복되있는것 같습니다!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@zzangzzangguy
앗! 저는 재사용 셀 등록은 뷰를 추가하는 과정은 아니라고 생각해서 configureUI에 등록을 해뒀던 거였습니다 👍🏻
이 부분은 생각의 차이가 있을 수 있어서 다음 회의때 어떤 스타일로 사용할건지 의논하고 하나의 스타일로 병합하면 좋을것같아요!