Skip to content

Commit ff2615d

Browse files
authored
[Refactor] 내 프로필 메뉴 탭 자연스럽게 개선 (#48)
2 parents 7ab0b29 + cab649e commit ff2615d

File tree

2 files changed

+30
-6
lines changed

2 files changed

+30
-6
lines changed

Fitfty/Projects/Profile/Sources/Profile/ViewControllers/ProfileViewController.swift

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ final public class ProfileViewController: UIViewController {
1919
private var profileType: ProfileType
2020
private var presentType: ProfilePresentType
2121
private var nickname: String?
22+
private var isRefreshProfileImage = false
2223
private var dataSource: UICollectionViewDiffableDataSource<ProfileSectionKind, ProfileCellModel>?
2324

2425
private lazy var collectionView: UICollectionView = {
@@ -38,7 +39,7 @@ final public class ProfileViewController: UIViewController {
3839
}()
3940

4041
private lazy var loadingIndicatorView: LoadingView = {
41-
let loadingView: LoadingView = .init(backgroundColor: .white.withAlphaComponent(0.2), alpha: 1)
42+
let loadingView: LoadingView = .init(backgroundColor: .white.withAlphaComponent(0), alpha: 1)
4243
loadingView.stopAnimating()
4344
return loadingView
4445
}()
@@ -106,6 +107,7 @@ final public class ProfileViewController: UIViewController {
106107
}
107108
viewModel.input.viewWillAppearWithoutMenu(nickname: nickname)
108109
case .myProfile:
110+
isRefreshProfileImage = true
109111
viewModel.input.viewWillAppearWithMenu(menuType: menuType)
110112
}
111113
}
@@ -130,13 +132,21 @@ final public class ProfileViewController: UIViewController {
130132
}
131133

132134
@objc func didTapMyFitftyMenu(_ sender: Any?) {
135+
guard menuType == .bookmark else {
136+
return
137+
}
138+
isRefreshProfileImage = false
133139
collectionView.isScrollEnabled = true
134140
emptyView.isHidden = true
135141
menuType = .myFitfty
136142
viewModel.input.didTapMenu(.myFitfty)
137143
}
138144

139145
@objc func didTapBookmarkMenu(_ sender: Any?) {
146+
guard menuType == .myFitfty else {
147+
return
148+
}
149+
isRefreshProfileImage = false
140150
collectionView.isScrollEnabled = true
141151
emptyView.isHidden = true
142152
menuType = .bookmark
@@ -299,7 +309,8 @@ private extension ProfileViewController {
299309
supplementaryView.profileView.setUp(
300310
nickname: nickname,
301311
content: content,
302-
filepath: self?.profileFilePath
312+
filepath: self?.profileFilePath,
313+
refresh: self?.isRefreshProfileImage ?? true
303314
)
304315
}
305316
return supplementaryView
@@ -316,7 +327,8 @@ private extension ProfileViewController {
316327
supplementaryView.profileView.setUp(
317328
nickname: nickname,
318329
content: content,
319-
filepath: self?.profileFilePath
330+
filepath: self?.profileFilePath,
331+
refresh: self?.isRefreshProfileImage ?? true
320332
)
321333
}
322334
supplementaryView.menuView.setMyFitftyButtonTarget(self, action: #selector(self?.didTapMyFitftyMenu))
@@ -345,7 +357,6 @@ private extension ProfileViewController {
345357
snapshot.appendSections([$0.sectionKind])
346358
snapshot.appendItems($0.items)
347359
}
348-
snapshot.reloadSections([.feed])
349360
dataSource?.apply(snapshot, animatingDifferences: true) {
350361
guard sections.first?.items.count == 0 else {
351362
return
@@ -355,6 +366,11 @@ private extension ProfileViewController {
355366
self.emptyView.setUp(self.menuType)
356367
}
357368

369+
guard var currentSnapshot = dataSource?.snapshot() else {
370+
return
371+
}
372+
currentSnapshot.reloadSections([.feed])
373+
dataSource?.apply(currentSnapshot, animatingDifferences: false)
358374
}
359375

360376
func postLayout() -> UICollectionViewLayout {

Fitfty/Projects/Profile/Sources/Profile/Views/ProfileView.swift

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,10 +62,18 @@ final class ProfileView: UIView {
6262
}
6363

6464
extension ProfileView {
65-
func setUp(nickname: String, content: String, filepath: String?) {
65+
func setUp(nickname: String, content: String, filepath: String?, refresh: Bool) {
6666
if let filepath = filepath {
6767
let url = URL(string: filepath)
68-
imageView.kf.setImage(with: url)
68+
if refresh {
69+
imageView.kf.indicatorType = .activity
70+
imageView.kf.setImage(
71+
with: url,
72+
options: [.forceRefresh]
73+
)
74+
} else {
75+
imageView.kf.setImage(with: url)
76+
}
6977
} else {
7078
imageView.image = CommonAsset.Images.profileDummy.image
7179
}

0 commit comments

Comments
 (0)