diff --git a/Clone App/Instagram/Instagram.xcworkspace/xcuserdata/yangseunghyeon.xcuserdatad/xcdebugger/Expressions.xcexplist b/Clone App/Instagram/Instagram.xcworkspace/xcuserdata/yangseunghyeon.xcuserdatad/xcdebugger/Expressions.xcexplist index b40c5435..ba841b5d 100644 --- a/Clone App/Instagram/Instagram.xcworkspace/xcuserdata/yangseunghyeon.xcuserdatad/xcdebugger/Expressions.xcexplist +++ b/Clone App/Instagram/Instagram.xcworkspace/xcuserdata/yangseunghyeon.xcuserdatad/xcdebugger/Expressions.xcexplist @@ -38,5 +38,13 @@ + + + + + + diff --git a/Clone App/Instagram/Instagram/Controller/FeedController.swift b/Clone App/Instagram/Instagram/Controller/FeedController.swift index 16382e48..39f41711 100644 --- a/Clone App/Instagram/Instagram/Controller/FeedController.swift +++ b/Clone App/Instagram/Instagram/Controller/FeedController.swift @@ -10,14 +10,17 @@ import Firebase class FeedController: UICollectionViewController { - private let reuseIdentifier = "FeedCell" //MARK: - LifeCycle override func viewDidLoad() { super.viewDidLoad() - collectionView.register(FeedCell.self, forCellWithReuseIdentifier: reuseIdentifier ) + collectionView.register(FeedCell.self, forCellWithReuseIdentifier: FEEDCELLRESUIDENTIFIER ) + } + + override func viewWillAppear(_ animated: Bool) { + super.viewWillAppear(animated) + collectionView.register(FeedCell.self, forCellWithReuseIdentifier: FEEDCELLRESUIDENTIFIER) setupNavigationUI() - } } @@ -50,7 +53,7 @@ extension FeedController { } override func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell { - guard let cell = collectionView.dequeueReusableCell(withReuseIdentifier: reuseIdentifier, for: indexPath) as? FeedCell else { + guard let cell = collectionView.dequeueReusableCell(withReuseIdentifier: FEEDCELLRESUIDENTIFIER, for: indexPath) as? FeedCell else { fatalError() } diff --git a/Clone App/Instagram/Instagram/Controller/MainHomeTabController.swift b/Clone App/Instagram/Instagram/Controller/MainHomeTabController.swift index 02559a3f..0898844c 100644 --- a/Clone App/Instagram/Instagram/Controller/MainHomeTabController.swift +++ b/Clone App/Instagram/Instagram/Controller/MainHomeTabController.swift @@ -17,10 +17,26 @@ class MainHomeTabController: UITabBarController { } } + private var isLogin: Bool? { + didSet { + guard let isLogin = isLogin else { return } + if !isLogin { + DispatchQueue.main.async { + self.presentLoginScene() + } + } + } + } + + //MARK: - Lifecycle override func viewDidLoad() { super.viewDidLoad() view.backgroundColor = .white + } + + override func viewWillAppear(_ animated: Bool) { + super.viewWillAppear(animated) configure() } @@ -29,15 +45,14 @@ class MainHomeTabController: UITabBarController { configure() } -} +} //MARK: - Helpers extension MainHomeTabController { func configure() { customTabBarUI() - fetchUserInfo() - checkIfUserIsLoggedIn() + isLogin = isUserLogined() } func configureViewControllers() { @@ -53,7 +68,7 @@ extension MainHomeTabController { let notifications = templateNavigationController(unselectedImage: .imageLiteral(name: "like_unselected"), selectedImage: .imageLiteral(name: "like_selected"), rootVC: NotificationController()) - var profileVC = ProfileController(user: userVM.getUserInfoModel()) + let profileVC = ProfileController(user: userVM.getUserInfoModel()) UserService.fetchUserProfile(userProfile: userVM.getUserProfileURL()) { image in profileVC.profileImage = image } @@ -122,13 +137,16 @@ extension MainHomeTabController { //MARK: - API. check user's membership - func checkIfUserIsLoggedIn() { - if CURRENT_USER == nil { - self.view.isHidden = true - self.presentLoginScene() + func isUserLogined() -> Bool { + if Auth.auth().currentUser == nil { + return false } + fetchUserInfo() + return true } + + func presentLoginScene() { let controller = LoginController() controller.authDelegate = self @@ -143,9 +161,12 @@ extension MainHomeTabController { //MARK: - Implement AuthentificationDelegate extension MainHomeTabController: AuthentificationDelegate { func authenticationCompletion() { - fetchUserInfo() + UserService.fetchCurrentUserInfo() { userInfo in + guard let userInfo = userInfo else { return } + self.viewDidLoad() + self.userVM = UserInfoViewModel(user: userInfo, profileImage: nil) + } self.dismiss(animated: false) } - } diff --git a/Clone App/Instagram/Instagram/Utils/Constants.swift b/Clone App/Instagram/Instagram/Utils/Constants.swift index 390862e5..76076683 100644 --- a/Clone App/Instagram/Instagram/Utils/Constants.swift +++ b/Clone App/Instagram/Instagram/Utils/Constants.swift @@ -20,3 +20,8 @@ let AUTH = Auth.auth() //MARK: - profile subview's ID let COLLECTIONHEADERREUSEABLEID = "UserProfileCollectionHeaderView" let CELLREUSEABLEID = "CollectionViewCell" + + +//MARK: - FeedVieController subview's ID + +let FEEDCELLRESUIDENTIFIER = "FeedCell"