Skip to content

Commit b616457

Browse files
committed
Merge branch 'improveLoginVCToFeedVCDevelop'
2 parents c08f133 + 80f65ca commit b616457

File tree

4 files changed

+51
-14
lines changed

4 files changed

+51
-14
lines changed

Clone App/Instagram/Instagram.xcworkspace/xcuserdata/yangseunghyeon.xcuserdatad/xcdebugger/Expressions.xcexplist

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,5 +38,13 @@
3838
</PersistentString>
3939
</PersistentStrings>
4040
</ContextState>
41+
<ContextState
42+
contextName = "closure #1 in MainHomeTabController.authenticationCompletion():MainHomeTabController.swift">
43+
<PersistentStrings>
44+
<PersistentString
45+
value = "userInfo">
46+
</PersistentString>
47+
</PersistentStrings>
48+
</ContextState>
4149
</ContextStates>
4250
</VariablesViewState>

Clone App/Instagram/Instagram/Controller/FeedController.swift

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,17 @@ import Firebase
1010

1111
class FeedController: UICollectionViewController {
1212

13-
private let reuseIdentifier = "FeedCell"
1413

1514
//MARK: - LifeCycle
1615
override func viewDidLoad() {
1716
super.viewDidLoad()
18-
collectionView.register(FeedCell.self, forCellWithReuseIdentifier: reuseIdentifier )
17+
collectionView.register(FeedCell.self, forCellWithReuseIdentifier: FEEDCELLRESUIDENTIFIER )
18+
}
19+
20+
override func viewWillAppear(_ animated: Bool) {
21+
super.viewWillAppear(animated)
22+
collectionView.register(FeedCell.self, forCellWithReuseIdentifier: FEEDCELLRESUIDENTIFIER)
1923
setupNavigationUI()
20-
2124
}
2225
}
2326

@@ -50,7 +53,7 @@ extension FeedController {
5053
}
5154

5255
override func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
53-
guard let cell = collectionView.dequeueReusableCell(withReuseIdentifier: reuseIdentifier, for: indexPath) as? FeedCell else {
56+
guard let cell = collectionView.dequeueReusableCell(withReuseIdentifier: FEEDCELLRESUIDENTIFIER, for: indexPath) as? FeedCell else {
5457
fatalError()
5558
}
5659

Clone App/Instagram/Instagram/Controller/MainHomeTabController.swift

Lines changed: 31 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,26 @@ class MainHomeTabController: UITabBarController {
1717
}
1818
}
1919

20+
private var isLogin: Bool? {
21+
didSet {
22+
guard let isLogin = isLogin else { return }
23+
if !isLogin {
24+
DispatchQueue.main.async {
25+
self.presentLoginScene()
26+
}
27+
}
28+
}
29+
}
30+
31+
2032
//MARK: - Lifecycle
2133
override func viewDidLoad() {
2234
super.viewDidLoad()
2335
view.backgroundColor = .white
36+
}
37+
38+
override func viewWillAppear(_ animated: Bool) {
39+
super.viewWillAppear(animated)
2440
configure()
2541

2642
}
@@ -29,15 +45,14 @@ class MainHomeTabController: UITabBarController {
2945
configure()
3046
}
3147

32-
}
48+
}
3349

3450
//MARK: - Helpers
3551
extension MainHomeTabController {
3652

3753
func configure() {
3854
customTabBarUI()
39-
fetchUserInfo()
40-
checkIfUserIsLoggedIn()
55+
isLogin = isUserLogined()
4156
}
4257

4358
func configureViewControllers() {
@@ -53,7 +68,7 @@ extension MainHomeTabController {
5368

5469
let notifications = templateNavigationController(unselectedImage: .imageLiteral(name: "like_unselected"), selectedImage: .imageLiteral(name: "like_selected"), rootVC: NotificationController())
5570

56-
var profileVC = ProfileController(user: userVM.getUserInfoModel())
71+
let profileVC = ProfileController(user: userVM.getUserInfoModel())
5772
UserService.fetchUserProfile(userProfile: userVM.getUserProfileURL()) { image in
5873
profileVC.profileImage = image
5974
}
@@ -122,13 +137,16 @@ extension MainHomeTabController {
122137

123138

124139
//MARK: - API. check user's membership
125-
func checkIfUserIsLoggedIn() {
126-
if CURRENT_USER == nil {
127-
self.view.isHidden = true
128-
self.presentLoginScene()
140+
func isUserLogined() -> Bool {
141+
if Auth.auth().currentUser == nil {
142+
return false
129143
}
144+
fetchUserInfo()
145+
return true
130146
}
131147

148+
149+
132150
func presentLoginScene() {
133151
let controller = LoginController()
134152
controller.authDelegate = self
@@ -143,9 +161,12 @@ extension MainHomeTabController {
143161
//MARK: - Implement AuthentificationDelegate
144162
extension MainHomeTabController: AuthentificationDelegate {
145163
func authenticationCompletion() {
146-
fetchUserInfo()
164+
UserService.fetchCurrentUserInfo() { userInfo in
165+
guard let userInfo = userInfo else { return }
166+
self.viewDidLoad()
167+
self.userVM = UserInfoViewModel(user: userInfo, profileImage: nil)
168+
}
147169
self.dismiss(animated: false)
148170
}
149171

150-
151172
}

Clone App/Instagram/Instagram/Utils/Constants.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,8 @@ let AUTH = Auth.auth()
2020
//MARK: - profile subview's ID
2121
let COLLECTIONHEADERREUSEABLEID = "UserProfileCollectionHeaderView"
2222
let CELLREUSEABLEID = "CollectionViewCell"
23+
24+
25+
//MARK: - FeedVieController subview's ID
26+
27+
let FEEDCELLRESUIDENTIFIER = "FeedCell"

0 commit comments

Comments
 (0)