Skip to content

Commit

Permalink
fix: Home에서 발생한 이슈들을 수정해요. (#679)
Browse files Browse the repository at this point in the history
* fix: navigator input family link(#668)

* fix: home issues(#668)

* rename files(#668)

* rename propertieis(#668)
  • Loading branch information
akrudal authored Oct 17, 2024
1 parent 51b167f commit 9ad25a1
Show file tree
Hide file tree
Showing 20 changed files with 226 additions and 99 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,20 @@ final class AppDIContainer: BaseContainer {
)
}

private func makeFetchFamilyManagementUseCase() -> FetchIsFirstFamilyManagementUseCaseProtocol {
FetchFamilyManagementUseCase(repository: makeAppRepository())
private func makeCheckIsFirstWidgetAlertUseCase() -> IsFirstWidgetAlertUseCaseProtocol {
IsFirstWidgetAlertUseCase(repository: makeAppRepository())
}

private func makeSaveFamilyManagementUseCase() -> UpdateFamilyManagementUseCaseProtocol {
UpdateFamilyManagementUseCase(repository: makeAppRepository())
private func makeSaveWidgetAlertUseCase() -> SaveIsFirstWidgetAlertUseCaseProtocol {
SaveIsFirstWidgetAlertUseCase(repository: makeAppRepository())
}

private func makeFetchFamilyManagementUseCase() -> IsFirstFamilyManagementUseCaseProtocol {
IsFirstFamilyManagementUseCase(repository: makeAppRepository())
}

private func makeSaveFamilyManagementUseCase() -> SaveIsFirstFamilyManagementUseCaseProtocol {
SaveIsFirstFamilyManagementUseCase(repository: makeAppRepository())
}


Expand All @@ -38,11 +46,15 @@ final class AppDIContainer: BaseContainer {
// MARK: - Register

func registerDependencies() {
container.register(type: FetchIsFirstFamilyManagementUseCaseProtocol.self) { _ in
container.register(type: IsFirstWidgetAlertUseCaseProtocol.self) { _ in
self.makeCheckIsFirstWidgetAlertUseCase()
}

container.register(type: IsFirstFamilyManagementUseCaseProtocol.self) { _ in
self.makeFetchFamilyManagementUseCase()
}

container.register(type: UpdateFamilyManagementUseCaseProtocol.self) { _ in
container.register(type: SaveIsFirstFamilyManagementUseCaseProtocol.self) { _ in
self.makeSaveFamilyManagementUseCase()
}

Expand All @@ -58,6 +70,10 @@ final class AppDIContainer: BaseContainer {
container.register(type: AppUserDefaultsType.self) { _ in
return AppUserDefaults()
}

container.register(type: SaveIsFirstWidgetAlertUseCaseProtocol.self) { _ in
return self.makeSaveWidgetAlertUseCase()
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ final class NavigatorDIContainer: BaseContainer {
}

container.register(type: MainNavigatorProtocol.self) { _ in
MainNavigator(navigationController: makeUINavigationController())
MainNavigator(navigationController: makeUINavigationController())
}

container.register(type: SplashNavigatorProtocol.self) { _ in
Expand Down Expand Up @@ -90,7 +90,7 @@ final class NavigatorDIContainer: BaseContainer {
}

container.register(type: FamilyEntranceNavigatorProtocol.self) { _ in
FamilyEntranceNavigator(navigationController: makeUINavigationController())
FamilyEntranceNavigator(navigationController: makeUINavigationController())
}

container.register(type: JoinFamilyNavigatorProtocol.self) { _ in
Expand All @@ -116,6 +116,10 @@ final class NavigatorDIContainer: BaseContainer {
navigationController: makeUINavigationController()
)
}

container.register(type: InputFamilyLinkNavigatorProtocol.self) { _ in
InputFamilyLInkNavigator(navigationController: makeUINavigationController())
}
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
//
// InputFamilyLinkNavigator.swift
// App
//
// Created by 마경미 on 30.09.24.
//

import Core
import UIKit

protocol InputFamilyLinkNavigatorProtocol: BaseNavigator {
func toHome()
func pop()
}

final class InputFamilyLInkNavigator: InputFamilyLinkNavigatorProtocol {

// MARK: - Properties

var navigationController: UINavigationController

// MARK: - Intializer

init(navigationController: UINavigationController) {
self.navigationController = navigationController
}

// MARK: - To

func pop() {
navigationController.popViewController(animated: true)
}

func toHome() {
let vc = MainViewControllerWrapper().viewController
navigationController.setViewControllers([vc], animated: true)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ protocol MainNavigatorProtocol: BaseNavigator {
// alert
func showSurvivalAlert()
func pickAlert(_ name: String)
func showWidgetAlert()
func missionUnlockedAlert()


Expand Down Expand Up @@ -51,7 +52,14 @@ final class MainNavigator: MainNavigatorProtocol {
}

func missionUnlockedAlert() {
BBAlert.style(.mission).show()
let handler: BBAlertActionHandler = { [weak self] alert in
self?.toCamera(.survival)
}
BBAlert.style(.takePhoto, primaryAction: handler).show()
}

func showWidgetAlert() {
BBAlert.style(.widget).show()
}

func showToast(_ image: UIImage?, _ message: String) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ public final class AccountSignInViewController: BaseViewController<AccountSignIn
loginStack.snp.makeConstraints {
$0.height.equalTo(124)
$0.horizontalEdges.equalToSuperview().inset(20)
$0.bottom.equalTo(view.safeAreaLayoutGuide).offset(12)
$0.bottom.equalTo(view.safeAreaLayoutGuide).inset(12)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,28 +23,20 @@ public final class InputFamilyLinkReactor: Reactor {
// MARK: - Mutate
public enum Mutation {
case setLinkString(String)
case setShowHome(Bool)
case setToastMessage(String)
case setPoped(Bool)
}

// MARK: - State
public struct State {
var linkString: String = ""
var isShowHome: Bool = false
@Pulse var showToastMessage: String = ""
var isPoped: Bool = false
}

// MARK: - Properties
public let initialState: State
public let initialState: State = State()
@Injected var familyUseCase: FamilyUseCaseProtocol

@Injected var joinFamilyUseCase: JoinFamilyUseCaseProtocol

init() {
self.initialState = State()
}
@Navigator var navigator: InputFamilyLinkNavigatorProtocol
}

extension InputFamilyLinkReactor {
Expand All @@ -65,7 +57,9 @@ extension InputFamilyLinkReactor {
// Repository에서 이미 UserDefaults와 App.Repository에 저장하고 있음
App.Repository.member.familyId.accept(joinFamilyData.familyId)
App.Repository.member.familyCreatedAt.accept(joinFamilyData.createdAt)
return Observable.just(Mutation.setShowHome(true))

self.navigator.toHome()
return .empty()
}

if App.Repository.member.familyId.value != nil {
Expand Down Expand Up @@ -93,7 +87,8 @@ extension InputFamilyLinkReactor {
}
}
case .tapPopButton:
return Observable.just(Mutation.setPoped(true))
navigator.pop()
return .empty()
}
}

Expand All @@ -103,12 +98,8 @@ extension InputFamilyLinkReactor {
switch mutation {
case let .setLinkString(link):
newState.linkString = link
case let .setShowHome(isShow):
newState.isShowHome = isShow
case let .setToastMessage(message):
newState.showToastMessage = message
case let .setPoped(isPop):
newState.isPoped = isPop
}
return newState
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,37 +22,13 @@ final class InputFamilyLinkViewController: BaseViewController<InputFamilyLinkRea

override func viewDidLoad() {
super.viewDidLoad()

NotificationCenter.default.addObserver(self, selector: #selector(keyboardWillShow(_:)), name: UIResponder.keyboardWillShowNotification, object: nil)
}

override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)

linkTextField.becomeFirstResponder()
}

override func viewWillDisappear(_ animated: Bool) {
super.viewWillDisappear(animated)

linkTextField.resignFirstResponder()
}

override func setupUI() {
super.setupUI()
view.addSubviews(backButton, titleLabel, linkTextField, joinFamilyButton)
}

@objc func keyboardWillShow(_ notification: Notification) {
if let keyboardSize = (notification.userInfo?[UIResponder.keyboardFrameEndUserInfoKey] as? NSValue)?.cgRectValue {
self.keyboardHeight = keyboardSize.height
}
}

deinit {
NotificationCenter.default.removeObserver(self)
}


override func setupAutoLayout() {
super.setupAutoLayout()

Expand Down Expand Up @@ -148,14 +124,6 @@ final class InputFamilyLinkViewController: BaseViewController<InputFamilyLinkRea
}

private func bindOutput(reactor: InputFamilyLinkReactor) {
reactor.state
.map { $0.isShowHome }
.filter { $0 }
.distinctUntilChanged()
.withUnretained(self)
.bind(onNext: { $0.0.showHomeViewController() })
.disposed(by: disposeBag)

reactor.state
.map { $0.linkString }
.filter { !$0.isEmpty }
Expand All @@ -173,14 +141,6 @@ final class InputFamilyLinkViewController: BaseViewController<InputFamilyLinkRea
.withUnretained(self)
.bind(onNext: { $0.0.makeBibbiToastView(text: $0.1, image: DesignSystemAsset.warning.image, offset: $0.0.keyboardHeight + 90) })
.disposed(by: disposeBag)

reactor.state
.map { $0.isPoped }
.filter { $0 }
.distinctUntilChanged()
.withUnretained(self)
.bind(onNext: { $0.0.navigationController?.popViewController(animated: true) })
.disposed(by: disposeBag)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ final class MainViewReactor: Reactor {
case cameraViewController(UploadLocation)
case survivalAlert
case pickAlert(String, String)
case widgetAlert
case missionUnlockedAlert
case weeklycalendarViewController(String)
case familyManagementViewController
Expand All @@ -42,7 +43,8 @@ final class MainViewReactor: Reactor {
case fetchMainUseCase
case fetchMainNightUseCase

case checkFamilyManagement
case checkIsFirstWidgetAlert
case checkIsFirstFamilyManagement
case checkMissionAlert(Bool, Bool)

case openNextViewController(TapAction)
Expand All @@ -59,6 +61,7 @@ final class MainViewReactor: Reactor {
case setCamerEnabled
case setBalloonText
case setDescriptionText

case setFamilyManagement(Bool)

case setPickMember(String, String)
Expand Down Expand Up @@ -94,13 +97,15 @@ final class MainViewReactor: Reactor {

@Navigator var navigator: MainNavigatorProtocol

@Injected var pickUseCase: PickUseCaseProtocol
@Injected var provider: ServiceProviderProtocol
@Injected var fetchMainUseCase: FetchMainUseCaseProtocol
@Injected var isFirstWidgetAlertUseCase: IsFirstWidgetAlertUseCaseProtocol
@Injected var fetchMainNightUseCase: FetchNightMainViewUseCaseProtocol
@Injected var pickUseCase: PickUseCaseProtocol
@Injected var checkMissionAlertShowUseCase: CheckMissionAlertShowUseCaseProtocol
@Injected var checkFamilyManagementUseCase: FetchIsFirstFamilyManagementUseCaseProtocol
@Injected var saveFamilyManagementUseCase: UpdateFamilyManagementUseCaseProtocol
@Injected var isFirstFamilyManagementUseCase: IsFirstFamilyManagementUseCaseProtocol
@Injected var saveIsFirstFamilyManagementUseCase: SaveIsFirstFamilyManagementUseCaseProtocol
@Injected var saveIsFirstWidgetAlertUseCase: SaveIsFirstWidgetAlertUseCaseProtocol
}

extension MainViewReactor {
Expand Down Expand Up @@ -226,7 +231,7 @@ extension MainViewReactor {
self.pushViewController(type: .familyManagementViewController)

if currentState.isFirstFamilyManagement {
saveFamilyManagementUseCase.execute(false)
saveIsFirstFamilyManagementUseCase.execute(false)
return Observable<Mutation>.just(.setFamilyManagement(false))
}
case .contributorNextButtonTap:
Expand All @@ -247,11 +252,20 @@ extension MainViewReactor {
self.pushViewController(type: .missionUnlockedAlert)
return .empty()
}
case .checkFamilyManagement:
return checkFamilyManagementUseCase.execute()
case .checkIsFirstFamilyManagement:
return isFirstFamilyManagementUseCase.execute()
.flatMap {
return Observable<Mutation>.just(.setFamilyManagement($0))
}
case .checkIsFirstWidgetAlert:
return isFirstWidgetAlertUseCase.execute()
.filter { $0 }
.withUnretained(self)
.flatMap { _ -> Observable<Mutation> in
self.pushViewController(type: .widgetAlert)
self.saveIsFirstWidgetAlertUseCase.execute(false)
return .empty()
}
}
}

Expand Down Expand Up @@ -309,6 +323,8 @@ extension MainViewReactor {
navigator.showToast(image, message)
case .showErrorToast:
navigator.showToast(DesignSystemAsset.warning.image, "에러가 발생했습니다")
case .widgetAlert:
navigator.showWidgetAlert()
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,12 @@ extension MainViewController {
.disposed(by: disposeBag)

Observable.just(())
.map { Reactor.Action.checkFamilyManagement }
.map { Reactor.Action.checkIsFirstFamilyManagement }
.bind(to: reactor.action)
.disposed(by: disposeBag)

Observable.just(())
.map { Reactor.Action.checkIsFirstWidgetAlert }
.bind(to: reactor.action)
.disposed(by: disposeBag)

Expand Down
Loading

0 comments on commit 9ad25a1

Please sign in to comment.