Skip to content

Commit

Permalink
[Feat] sopt-makers#327 - RefreshControl 이벤트 바인딩
Browse files Browse the repository at this point in the history
  • Loading branch information
lsj8706 committed Dec 20, 2023
1 parent 5741337 commit 46fd30d
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,18 @@ extension PokeMainVC {
make.bottom.equalToSuperview().inset(20)
}
}

private func setFriendRandomUsers(with randomUsers: [PokeFriendRandomUserModel]) {
let profileCardGroupViews = [firstProfileCardGroupView, secondProfileCardGroupView]

for (i, profileCardGroupView) in profileCardGroupViews.enumerated() {
let randomUser = randomUsers[safe: i]
profileCardGroupView.isHidden = (randomUser == nil)
if let randomUser {
profileCardGroupView.setData(with: randomUser)
}
}
}
}

// MARK: - Methods
Expand Down Expand Up @@ -233,15 +245,13 @@ extension PokeMainVC {
output.friendRandomUsers
.withUnretained(self)
.sink { owner, randomUsers in
let profileCardGroupViews = [owner.firstProfileCardGroupView, owner.secondProfileCardGroupView]

for (i, profileCardGroupView) in profileCardGroupViews.enumerated() {
let randomUser = randomUsers[safe: i]
profileCardGroupView.isHidden = (randomUser == nil)
if let randomUser {
profileCardGroupView.setData(with: randomUser)
}
}
owner.setFriendRandomUsers(with: randomUsers)
}.store(in: cancelBag)

output.endRefreshLoading
.withUnretained(self)
.sink { owner, _ in
owner.refreshControl.endRefreshing()
}.store(in: cancelBag)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ public class PokeMainViewModel:
let myFriend = PassthroughSubject<PokeUserModel, Never>()
let friendsSectionWillBeHidden = PassthroughSubject<Bool, Never>()
let friendRandomUsers = PassthroughSubject<[PokeFriendRandomUserModel], Never>()
let endRefreshLoading = PassthroughSubject<Void, Never>()
}

// MARK: - initialization
Expand All @@ -62,7 +63,7 @@ extension PokeMainViewModel {
let output = Output()
self.bindOutput(output: output, cancelBag: cancelBag)

input.viewDidLoad
Publishers.Merge(input.viewDidLoad, input.refreshRequest)
.sink { [weak self] _ in
self?.useCase.getWhoPokedToMe()
self?.useCase.getFriend()
Expand Down Expand Up @@ -102,11 +103,6 @@ extension PokeMainViewModel {
print("찌르기 - \(userId)")
}.store(in: cancelBag)

input.refreshRequest
.sink { _ in
print("리프레시 요청")
}.store(in: cancelBag)

return output
}

Expand Down Expand Up @@ -139,6 +135,11 @@ extension PokeMainViewModel {
.prefix(2)
.subscribe(output.friendRandomUsers)
.store(in: cancelBag)

Publishers.Zip3(useCase.pokedToMeUser, useCase.myFriend, useCase.friendRandomUsers)
.map { _ in Void() }
.subscribe(output.endRefreshLoading)
.store(in: cancelBag)
}
}

Expand Down

0 comments on commit 46fd30d

Please sign in to comment.