-
Notifications
You must be signed in to change notification settings - Fork 0
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
ain-RxFlow #19
base: master
Are you sure you want to change the base?
ain-RxFlow #19
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,130 @@ | ||
# RxFlow | ||
|
||
<br> | ||
|
||
Coordinator 패턴을 RxSwift와 함께 사용할 수 있도록 랩핑한 프레임워크 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 왜 RxSwift로 Coordinator를 래핑하여 쓰게 하였을까요? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. RxSwift의 비동기 처리 능력을 활용하여 화면 전환을 효율적으로 관리하기 위해서 라고 생각합니다. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 비동기 처리 능력이 어떻게 화면 전환을 효율적으로 관리할 수 있는건가요? |
||
|
||
<br><br><br> | ||
|
||
## **Coordinator패턴과의 차이** | ||
|
||
<br> | ||
|
||
- RxFlow에서는 화면을 **State**로, 화면 전환을 **Concept**로 정의한다. | ||
|
||
- Coordinator 패턴은 주로 동기적인 화면 전환을 처리한다면 RxFlow는 비동기적인 화면 전환을 처리한다. | ||
|
||
<br><br><br> | ||
|
||
## RxFlow 사용법 | ||
|
||
<br> | ||
|
||
```swift | ||
enum AppStep: Step { | ||
case firstScreen | ||
case secondScreen | ||
} | ||
``` | ||
|
||
RxFlow를 프로젝트에 추가하고 State와 Concept를 정의한다. | ||
|
||
<br> | ||
|
||
```swift | ||
// FirstViewController | ||
class FirstViewController: UIViewController, Stepper { | ||
var steps = PublishRelay<Step>() | ||
@IBAction func goToSecondScreenButtonTapped() { | ||
steps.accept(AppStep.secondScreen) | ||
} | ||
} | ||
|
||
// SecondViewController | ||
class SecondViewController: UIViewController, Stepper { | ||
var steps = PublishRelay<Step>() | ||
} | ||
``` | ||
|
||
화면 전환에 사용되는 FirstViewController, SecondViewController | ||
|
||
<br><br> | ||
|
||
```swift | ||
class AppFlowCoordinator: FlowCoordinator { | ||
var root: Presentable { | ||
return self.navigationController | ||
} | ||
|
||
let navigationController = UINavigationController() | ||
|
||
func navigate(to step: Step) -> FlowContributors { | ||
guard let step = step as? AppStep else { return .none } | ||
switch step { | ||
case .firstScreen: | ||
let firstViewController = FirstViewController() | ||
firstViewController.navigationItem.rightBarButtonItem = UIBarButtonItem(title: "Next", style: .plain, target: self, action: #selector(goToSecondScreen)) | ||
navigationController.viewControllers = [firstViewController] | ||
return .one(flowContributor: .contribute(withNextPresentable: firstViewController, withNextStepper: firstViewController)) | ||
case .secondScreen: | ||
let secondViewController = SecondViewController() | ||
navigationController.pushViewController(secondViewController, animated: true) | ||
return .none | ||
Comment on lines
+64
to
+72
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. FlowContributors를 반환하는 곳이 있고, 반환하지 않는 곳도 있는데, 반환하는 때와 반환하지 않는 때는 어떤 상황이라고 생각하시나요? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 이후에 다른 화면전환이 있을 때는 다음 화면에 대한 정보를 함께 반환하고 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 다음 화면에 대한 정보가 무엇인가요? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 전환할 화면과 전환에 사용되는 Step입니다. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 민재 : 다음 화면에 대한 정보? 말이 좀 애매한거같은데, 아니지 않냐? |
||
} | ||
} | ||
|
||
Comment on lines
+60
to
+75
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. RxFlow로 화면과 화면간에 데이터를 전달할때는 어떻게 할 수 있을지 한 번 작성해보는거 어떤가요? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 겸사겸사 더해서 push된 화면에서 이전 화면에 무언가 결과를 보내려면은 어떻게 할 수 있을지 고민해보면 좋을거같아요. |
||
@objc private func goToSecondScreen() { | ||
steps.accept(AppStep.secondScreen) | ||
} | ||
} | ||
|
||
``` | ||
|
||
RxFlowCoordinator를 구현하여 각 Concept에 대한 화면 전환 로직을 처리한다. | ||
|
||
위 코드는 첫번째 화면의 Next버튼을 누르면 두번째 화면으로 전환되는 코드이다 ! | ||
|
||
<br><br> | ||
|
||
```swift | ||
let appFlow = AppFlowCoordinator() | ||
let appStepper = OneStepper(withSingleStep: AppStep.firstScreen) | ||
|
||
Flows.whenReady(flow1: appFlow, block: { [unowned self] root in | ||
self.window.rootViewController = root | ||
self.window.makeKeyAndVisible() | ||
}) | ||
|
||
Comment on lines
+92
to
+97
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
self.coordinator.coordinate(flow: appFlow, with: appStepper) | ||
``` | ||
|
||
AppDelegate에 RxFlow를 초기화하고 실행하는 코드를 작성한다. | ||
|
||
<br><br> | ||
|
||
- **Flow**: 어플리케이션 내부의 네비게이션 공간 | ||
|
||
화면 전환을 관리하며, 각 Flow 내에서 화면 전환 스택을 관리한다. | ||
|
||
- **Step**: 어플리케이션 내부의 네비게이션 상태 | ||
|
||
- **Stepper**: 사용자의 입력 또는 이벤트를 통해 화면 전환을 시작하는 역할 | ||
|
||
- **Presentable**: Flow 내부에서 화면을 나타내는데 사용되는 프로토콜 | ||
|
||
UIViewController나 UINavigationController를 채택하며, Flow 내에서 화면을 나타내는 역할을 한다. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
|
||
- **NextFlowItem**: 현재 화면 전환 이후에 다음에 어떤 화면이 나타날지를 정의하는 객체 | ||
|
||
Step과 함께 사용되며 다음 화면을 결정하는 역할을 한다. | ||
|
||
<br><br><br> | ||
|
||
|
||
## RxFlow의 장점 | ||
|
||
<br> | ||
|
||
- Coordinator 패턴을 쉽게 적용할 수 있다. | ||
|
||
- 앱의 화면 전환을 효과적으로 관리할 수 있다. | ||
Comment on lines
+124
to
+130
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 반대로 단점은..? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Coordinator 의 핵심은 화면로직을 ViewController로부터 '분리'한다는 것이 핵심입니다. Coordinator를 사용하지 않고 다른 방법으로 화면로직 로직을 분리할 수 없을까요?