Skip to content
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

♻️ [Refactor] 화면전환 코드 리펙토링 #400

Merged
merged 4 commits into from
Jul 11, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions NadoSunbae-iOS/NadoSunbae-iOS.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@
33C1B8A327974A4F004BABEC /* ClassroomQuestionDetailData.swift in Sources */ = {isa = PBXBuildFile; fileRef = 33C1B8A227974A4F004BABEC /* ClassroomQuestionDetailData.swift */; };
33C1B8A527974B72004BABEC /* ClassroomService.swift in Sources */ = {isa = PBXBuildFile; fileRef = 33C1B8A427974B72004BABEC /* ClassroomService.swift */; };
33C1B8A72797505D004BABEC /* ClassroomAPI.swift in Sources */ = {isa = PBXBuildFile; fileRef = 33C1B8A62797505D004BABEC /* ClassroomAPI.swift */; };
33C50100281A4E24004AAEEE /* Navigator.swift in Sources */ = {isa = PBXBuildFile; fileRef = 33C500FF281A4E24004AAEEE /* Navigator.swift */; };
33CF634F27945C0400E92C04 /* NadoSegmentView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 33CF634D27945C0300E92C04 /* NadoSegmentView.swift */; };
33CF635027945C0400E92C04 /* NadoHorizonContainerViews.swift in Sources */ = {isa = PBXBuildFile; fileRef = 33CF634E27945C0400E92C04 /* NadoHorizonContainerViews.swift */; };
33CF635227945C0900E92C04 /* NadoHorizonContainerViews.xib in Resources */ = {isa = PBXBuildFile; fileRef = 33CF635127945C0900E92C04 /* NadoHorizonContainerViews.xib */; };
Expand All @@ -122,6 +123,7 @@
33DAB83A27914EAD00214CA8 /* WriteQuestionVC.swift in Sources */ = {isa = PBXBuildFile; fileRef = 33DAB83927914EAD00214CA8 /* WriteQuestionVC.swift */; };
33DAB83C279153A400214CA8 /* BaseCVC.swift in Sources */ = {isa = PBXBuildFile; fileRef = 33DAB83B279153A400214CA8 /* BaseCVC.swift */; };
33E1E19627C7F51A0057C066 /* QnAType.swift in Sources */ = {isa = PBXBuildFile; fileRef = 33E1E19527C7F51A0057C066 /* QnAType.swift */; };
33E2CFC5287B112D007CD19A /* SignUpNC.swift in Sources */ = {isa = PBXBuildFile; fileRef = 33E2CFC4287B112D007CD19A /* SignUpNC.swift */; };
33EAD1F127C68D09000AD673 /* EditPostCommentModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 33EAD1F027C68D09000AD673 /* EditPostCommentModel.swift */; };
33F3ED8827C54E9F00731E24 /* EditPostQuestionModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 33F3ED8727C54E9F00731E24 /* EditPostQuestionModel.swift */; };
33FA751427931AA800E43523 /* ClassroomSB.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 33FA751327931AA800E43523 /* ClassroomSB.storyboard */; };
Expand Down Expand Up @@ -378,6 +380,7 @@
33C1B8A227974A4F004BABEC /* ClassroomQuestionDetailData.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ClassroomQuestionDetailData.swift; sourceTree = "<group>"; };
33C1B8A427974B72004BABEC /* ClassroomService.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ClassroomService.swift; sourceTree = "<group>"; };
33C1B8A62797505D004BABEC /* ClassroomAPI.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ClassroomAPI.swift; sourceTree = "<group>"; };
33C500FF281A4E24004AAEEE /* Navigator.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Navigator.swift; sourceTree = "<group>"; };
33CF634D27945C0300E92C04 /* NadoSegmentView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = NadoSegmentView.swift; sourceTree = "<group>"; };
33CF634E27945C0400E92C04 /* NadoHorizonContainerViews.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = NadoHorizonContainerViews.swift; sourceTree = "<group>"; };
33CF635127945C0900E92C04 /* NadoHorizonContainerViews.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = NadoHorizonContainerViews.xib; sourceTree = "<group>"; };
Expand All @@ -396,6 +399,7 @@
33DAB83927914EAD00214CA8 /* WriteQuestionVC.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WriteQuestionVC.swift; sourceTree = "<group>"; };
33DAB83B279153A400214CA8 /* BaseCVC.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BaseCVC.swift; sourceTree = "<group>"; };
33E1E19527C7F51A0057C066 /* QnAType.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = QnAType.swift; sourceTree = "<group>"; };
33E2CFC4287B112D007CD19A /* SignUpNC.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SignUpNC.swift; sourceTree = "<group>"; };
33EAD1F027C68D09000AD673 /* EditPostCommentModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EditPostCommentModel.swift; sourceTree = "<group>"; };
33F02A8A278889650078F9B7 /* NadoSunbaeBtn.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NadoSunbaeBtn.swift; sourceTree = "<group>"; };
33F3ED8727C54E9F00731E24 /* EditPostQuestionModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EditPostQuestionModel.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -694,6 +698,7 @@
33E1E19527C7F51A0057C066 /* QnAType.swift */,
33834A1427D5F66E001C4947 /* MypageLikePostType.swift */,
336EEE3D27D9A72C0010A9E3 /* PermissionType.swift */,
33C500FF281A4E24004AAEEE /* Navigator.swift */,
);
path = Struct;
sourceTree = "<group>";
Expand Down Expand Up @@ -1379,6 +1384,7 @@
isa = PBXGroup;
children = (
5CAB3F29278AE3C200025DA5 /* AgreeTermsVC.swift */,
33E2CFC4287B112D007CD19A /* SignUpNC.swift */,
);
path = VC;
sourceTree = "<group>";
Expand Down Expand Up @@ -1916,6 +1922,7 @@
331364562785A90F00E0C118 /* TypeOfViewController.swift in Sources */,
77A7591E279762BF00A8E48B /* ReviewPostRegisterData.swift in Sources */,
775728AC27D65E8900148C9A /* OnboardingDataModel.swift in Sources */,
33E2CFC5287B112D007CD19A /* SignUpNC.swift in Sources */,
3381083527D53E19005AF1F9 /* MypageLikeListVC.swift in Sources */,
33834A1D27D67FAB001C4947 /* MypageLikeReviewDataModel.swift in Sources */,
33CF63602794A03300E92C04 /* QuestionHeaderTVC.swift in Sources */,
Expand Down Expand Up @@ -2041,6 +2048,7 @@
C7F3F6DD27D5192D00E12888 /* ResendSignUpMailResponseModel.swift in Sources */,
3391E497278B7AC50079EA31 /* ClassroomQuestionTVC.swift in Sources */,
331364702785B18100E0C118 /* UserDefaults+.swift in Sources */,
33C50100281A4E24004AAEEE /* Navigator.swift in Sources */,
33CF634F27945C0400E92C04 /* NadoSegmentView.swift in Sources */,
33BE2D6A2789D605000FB6C8 /* NadoSunbaeBtn.swift in Sources */,
C7ACE63627CBD3280011B23F /* SettingAppInfoVC.swift in Sources */,
Expand Down
66 changes: 4 additions & 62 deletions NadoSunbae-iOS/NadoSunbae-iOS/Global/Class/BaseVC.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,13 @@ class BaseVC: UIViewController {

let screenWidth = UIScreen.main.bounds.size.width
let screenHeight = UIScreen.main.bounds.size.height
var navigator: Navigator?

// MARK: Life Cycle
override func viewDidLoad() {
super.viewDidLoad()
view.addSubview(activityIndicator)
navigator = Navigator(vc: self)
}
}

Expand Down Expand Up @@ -121,12 +123,12 @@ extension BaseVC {
switch permissionStatus {
case .review:
restrictionAlert.confirmBtn.press {
self.presentToReviewWriteVC { _ in }
self.navigator?.instantiateVC(destinationViewControllerType: ReviewWriteVC.self, useStoryboard: true, storyboardName: "ReviewWriteSB", naviType: .present, modalPresentationStyle: .fullScreen) { reviewWriteVC in }
}
case .inappropriate:
permissionMsg = "부적절한 후기 작성이 확인되어\n열람 권한이 제한되었습니다.\n권한을 얻고 싶다면\n다시 학과후기를 작성해주세요."
restrictionAlert.confirmBtn.press {
self.presentToReviewWriteVC { _ in }
self.navigator?.instantiateVC(destinationViewControllerType: ReviewWriteVC.self, useStoryboard: true, storyboardName: "ReviewWriteSB", naviType: .present, modalPresentationStyle: .fullScreen) { reviewWriteVC in }
}
case .report:
permissionMsg = UserPermissionInfo.shared.permissionMsg
Expand Down Expand Up @@ -214,66 +216,6 @@ extension BaseVC {
}
}

/// 회원가입VC로 present 화면전환을 하는 메서드
func presentToSignUpVC() {
guard let signUpVC = UIStoryboard.init(name: AgreeTermsVC.className, bundle: nil).instantiateViewController(withIdentifier: "SignUpNVC") as? UINavigationController else { return }
signUpVC.modalPresentationStyle = .fullScreen
self.present(signUpVC, animated: true, completion: nil)
}

/// 로그인VC로 present 화면전환을 하는 메서드
func presentToSignInVC() {
guard let signInVC = UIStoryboard.init(name: "SignInSB", bundle: nil).instantiateViewController(withIdentifier: SignInVC.className) as? SignInVC else { return }
signInVC.modalPresentationStyle = .fullScreen
self.present(signInVC, animated: true, completion: nil)
}

/// 후기작성VC로 present 화면전환을 하는 메서드
func presentToReviewWriteVC(completion: @escaping (ReviewWriteVC) -> ()) {
guard let reviewWriteVC = UIStoryboard.init(name: "ReviewWriteSB", bundle: nil).instantiateViewController(withIdentifier: ReviewWriteVC.className) as? ReviewWriteVC else { return }
reviewWriteVC.modalPresentationStyle = .fullScreen
self.present(reviewWriteVC, animated: true, completion: nil)
completion(reviewWriteVC)
}

/// 후기상세VC로 navigation push 화면전환을 하는 메서드
func pushToReviewDetailVC(completion: @escaping (ReviewDetailVC) -> ()) {
guard let reviewDetailVC = UIStoryboard.init(name: "ReviewDetailSB", bundle: nil).instantiateViewController(withIdentifier: ReviewDetailVC.className) as? ReviewDetailVC else { return }
completion(reviewDetailVC)
self.navigationController?.pushViewController(reviewDetailVC, animated: true)
}

/// 질문작성VC로 present 화면전환을 하는 메서드
func presentToWriteQuestionVC(completion: @escaping (WriteQuestionVC) -> ()) {
guard let writeQuestionVC = UIStoryboard(name: Identifiers.WriteQusetionSB, bundle: nil).instantiateViewController(identifier: WriteQuestionVC.className) as? WriteQuestionVC else { return }
completion(writeQuestionVC)
writeQuestionVC.modalPresentationStyle = .fullScreen
self.present(writeQuestionVC, animated: true, completion: nil)
}

/// 선배마이페이지VC로 navigation push 화면전환을 하는 메서드
func pushToMypageUserVC(completion: @escaping (MypageUserVC) -> ()) {
guard let mypageUserVC = UIStoryboard.init(name: MypageUserVC.className, bundle: nil).instantiateViewController(withIdentifier: MypageUserVC.className) as? MypageUserVC else { return }
completion(mypageUserVC)
self.navigationController?.pushViewController(mypageUserVC, animated: true)
}

/// 정보상세VC로 navigation push 화면전환을 하는 메서드
func pushToInfoDetailVC(completion: @escaping (InfoDetailVC) -> ()) {
guard let infoDetailVC = UIStoryboard(name: Identifiers.InfoSB, bundle: nil).instantiateViewController(identifier: InfoDetailVC.className) as? InfoDetailVC else { return }
infoDetailVC.hidesBottomBarWhenPushed = true
completion(infoDetailVC)
self.navigationController?.pushViewController(infoDetailVC, animated: true)
}

/// 질문상세VC로 navigation push 화면전환을 하는 메서드
func pushToQuestionDetailVC(completion: @escaping (DefaultQuestionChatVC) -> ()) {
guard let questionDetailVC = UIStoryboard(name: Identifiers.QuestionChatSB, bundle: nil).instantiateViewController(identifier: DefaultQuestionChatVC.className) as? DefaultQuestionChatVC else { return }
questionDetailVC.hidesBottomBarWhenPushed = true
completion(questionDetailVC)
self.navigationController?.pushViewController(questionDetailVC, animated: true)
}

/// SafariViewController를 불러와 present 화면전환을 하는 메서드 (인앱)
func presentToSafariVC(url: URL) {
let safariView: SFSafariViewController = SFSafariViewController(url: url)
Expand Down
10 changes: 10 additions & 0 deletions NadoSunbae-iOS/NadoSunbae-iOS/Global/Extension/String+.swift
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,16 @@ extension String {
return dateFormatter.string(from: self.toDate())
}
}

/// String을 ViewController 인스턴스로 변환하는 메서드
public func getViewController() -> UIViewController? {
if let vcName = Bundle.main.infoDictionary?["CFBundleName"] as? String {
if let viewControllerType = Bundle.main.classNamed("\(vcName).\(self)") as? UIViewController.Type {
return viewControllerType.init()
}
}
return nil
}
}

/// 전공정보 String으로 반환하는 함수
Expand Down
44 changes: 44 additions & 0 deletions NadoSunbae-iOS/NadoSunbae-iOS/Global/Struct/Navigator.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
//
// Navigator.swift
// NadoSunbae-iOS
//
// Created by hwangJi on 2022/04/28.
//

import Foundation
import UIKit

struct Navigator {

// MARK: Properties
private var viewController: UIViewController

// MARK: Init
init(vc: UIViewController) {
self.viewController = vc
}

// MARK: Public Methods
public func instantiateVC<T>(destinationViewControllerType vcType: T.Type, useStoryboard: Bool, storyboardName sbName: String, naviType: NaviType = .present, modalPresentationStyle style: UIModalPresentationStyle = .fullScreen, completion: @escaping(T) -> ()) {
var destinationVC: UIViewController = UIViewController()

if useStoryboard {
let storyboard = UIStoryboard(name: sbName, bundle: nil)
destinationVC = storyboard.instantiateViewController(withIdentifier: String(describing: vcType.self))
} else {
if let vc = String(describing: vcType.self).getViewController() {
destinationVC = vc
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

와 여기 제네릭 이용해서 한거 대박이다....

}

switch naviType {
case .push:
completion(destinationVC as! T)
viewController.navigationController?.pushViewController(destinationVC, animated: true)
case .present:
completion(destinationVC as! T)
destinationVC.modalPresentationStyle = style
viewController.present(destinationVC, animated: true, completion: nil)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -201,12 +201,12 @@ extension InfoDetailVC {

/// 정보글 원글을 수정하기 위해 WriteQuestionVC로 화면전환하는 메서드
private func presentWriteQuestionVC() {
presentToWriteQuestionVC { writeQuestionVC in
self.navigator?.instantiateVC(destinationViewControllerType: WriteQuestionVC.self, useStoryboard: true, storyboardName: Identifiers.WriteQusetionSB, naviType: .present, modalPresentationStyle: .fullScreen) { [weak self] writeQuestionVC in
writeQuestionVC.questionType = .info
writeQuestionVC.isEditState = true
writeQuestionVC.postID = self.postID
writeQuestionVC.originTitle = self.infoDetailData?.post.title
writeQuestionVC.originContent = self.infoDetailData?.post.content
writeQuestionVC.postID = self?.postID
writeQuestionVC.originTitle = self?.infoDetailData?.post.title
writeQuestionVC.originContent = self?.infoDetailData?.post.content
}
}

Expand All @@ -233,10 +233,9 @@ extension InfoDetailVC {
if userID == UserDefaults.standard.integer(forKey: UserDefaults.Keys.UserID) {
goToRootOfTab(index: 3)
} else {
pushToMypageUserVC { mypageUserVC in
self.navigator?.instantiateVC(destinationViewControllerType: MypageUserVC.self, useStoryboard: true, storyboardName: MypageUserVC.className, naviType: .push) { mypageUserVC in
mypageUserVC.targetUserID = userID
mypageUserVC.judgeBlockStatusDelegate = self
mypageUserVC.hidesBottomBarWhenPushed = true
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,8 +139,8 @@ extension InfoMainVC {
infoFloatingBtn.press {

/// 유저의 권한 분기처리
self.divideUserPermission() {
self.presentToWriteQuestionVC { writeQuestionVC in
self.divideUserPermission() { [weak self] in
self?.navigator?.instantiateVC(destinationViewControllerType: WriteQuestionVC.self, useStoryboard: true, storyboardName: Identifiers.WriteQusetionSB, naviType: .present, modalPresentationStyle: .fullScreen) { writeQuestionVC in
writeQuestionVC.questionType = .info
}
}
Expand Down Expand Up @@ -244,7 +244,8 @@ extension InfoMainVC: UITableViewDelegate {
/// 유저의 권한 분기처리
self.divideUserPermission() {
if infoList.count != 0 {
pushToInfoDetailVC { infoDetailVC in
self.navigator?.instantiateVC(destinationViewControllerType: InfoDetailVC.self, useStoryboard: true, storyboardName: Identifiers.InfoSB, naviType: .push) { infoDetailVC in
infoDetailVC.hidesBottomBarWhenPushed = true
infoDetailVC.postID = self.infoList[indexPath.row].postID
}
}
Expand Down
Loading