-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
♻️#294: 마이페이지 코드 정리 및 ViewWillAppearEvent 바인딩 처리
- Loading branch information
Showing
5 changed files
with
172 additions
and
70 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
// | ||
// Map+Rx.swift | ||
// StreetDrop | ||
// | ||
// Created by thoonk on 7/10/24. | ||
// | ||
|
||
import Foundation | ||
|
||
import RxSwift | ||
|
||
extension ObservableType { | ||
func map<T>(_ element: T) -> Observable<T> { | ||
self.map({ _ in element }) | ||
} | ||
|
||
func mapVoid() -> Observable<Void> { | ||
self.map(Void()) | ||
} | ||
} |
73 changes: 73 additions & 0 deletions
73
StreetDrop/StreetDrop/Util/Extensions/UIViewController+Rx.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
// | ||
// UIViewController+Rx.swift | ||
// StreetDrop | ||
// | ||
// Created by thoonk on 7/10/24. | ||
// | ||
|
||
import Foundation | ||
import UIKit | ||
|
||
import RxSwift | ||
import RxCocoa | ||
|
||
extension Reactive where Base: UIViewController { | ||
var viewDidLoad: ControlEvent<Void> { | ||
let source = self.methodInvoked(#selector(Base.viewDidLoad)).map { _ in } | ||
return ControlEvent(events: source) | ||
} | ||
|
||
var viewWillAppear: ControlEvent<Bool> { | ||
let source = self.methodInvoked(#selector(Base.viewWillAppear)).map { $0.first as? Bool ?? false } | ||
return ControlEvent(events: source) | ||
} | ||
var viewDidAppear: ControlEvent<Bool> { | ||
let source = self.methodInvoked(#selector(Base.viewDidAppear)).map { $0.first as? Bool ?? false } | ||
return ControlEvent(events: source) | ||
} | ||
|
||
var viewWillDisappear: ControlEvent<Bool> { | ||
let source = self.methodInvoked(#selector(Base.viewWillDisappear)).map { $0.first as? Bool ?? false } | ||
return ControlEvent(events: source) | ||
} | ||
var viewDidDisappear: ControlEvent<Bool> { | ||
let source = self.methodInvoked(#selector(Base.viewDidDisappear)).map { $0.first as? Bool ?? false } | ||
return ControlEvent(events: source) | ||
} | ||
|
||
var viewWillLayoutSubviews: ControlEvent<Void> { | ||
let source = self.methodInvoked(#selector(Base.viewWillLayoutSubviews)).map { _ in } | ||
return ControlEvent(events: source) | ||
} | ||
var viewDidLayoutSubviews: ControlEvent<Void> { | ||
let source = self.methodInvoked(#selector(Base.viewDidLayoutSubviews)).map { _ in } | ||
return ControlEvent(events: source) | ||
} | ||
|
||
var willMoveToParentViewController: ControlEvent<UIViewController?> { | ||
let source = self.methodInvoked(#selector(Base.willMove)).map { $0.first as? UIViewController } | ||
return ControlEvent(events: source) | ||
} | ||
var didMoveToParentViewController: ControlEvent<UIViewController?> { | ||
let source = self.methodInvoked(#selector(Base.didMove)).map { $0.first as? UIViewController } | ||
return ControlEvent(events: source) | ||
} | ||
|
||
var didReceiveMemoryWarning: ControlEvent<Void> { | ||
let source = self.methodInvoked(#selector(Base.didReceiveMemoryWarning)).map { _ in } | ||
return ControlEvent(events: source) | ||
} | ||
|
||
/// Rx observable, triggered when the ViewController appearance state changes (true if the View is being displayed, false otherwise) | ||
var isVisible: Observable<Bool> { | ||
let viewDidAppearObservable = self.base.rx.viewDidAppear.map { _ in true } | ||
let viewWillDisappearObservable = self.base.rx.viewWillDisappear.map { _ in false } | ||
return Observable<Bool>.merge(viewDidAppearObservable, viewWillDisappearObservable) | ||
} | ||
|
||
/// Rx observable, triggered when the ViewController is being dismissed | ||
var isDismissing: ControlEvent<Bool> { | ||
let source = self.sentMessage(#selector(Base.dismiss)).map { $0.first as? Bool ?? false } | ||
return ControlEvent(events: source) | ||
} | ||
} |