Skip to content

Commit

Permalink
Refactor: preview 부분 디버그에 추가, timeOver initial 부분 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
ibcylon committed Oct 8, 2023
1 parent c8aa15f commit 2305ef0
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 12 deletions.
11 changes: 9 additions & 2 deletions Falling/Sources/Feature/Main/MainViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import UIKit
import RxSwift
import RxCocoa
import RxDataSources
import SwiftUI

final class MainViewController: TFBaseViewController {

Expand Down Expand Up @@ -113,9 +112,17 @@ extension Reactive where Base: MainViewController {
return ControlEvent(events: source)
}
}
#if DEBUG
import SwiftUI

struct MainViewControllerPreView: PreviewProvider {
static var previews: some View {
MainViewController(viewModel: MainViewModel(navigator: MainNavigator(controller: UINavigationController()))).toPreView()
let navigator = MainNavigator(controller: UINavigationController())

let viewModel = MainViewModel(navigator: navigator)

return MainViewController(viewModel: viewModel)
.toPreView()
}
}
#endif
17 changes: 7 additions & 10 deletions Falling/Sources/Feature/Main/MainViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
//
// Created by SeungMin on 2023/08/15.
//
import Foundation

import RxSwift
import RxCocoa
Expand Down Expand Up @@ -40,16 +41,12 @@ final class MainViewModel: ViewModelType {
UserDTO(userIdx: 2),
])]

let userList = Observable.just(userSectionList).asDriver(onErrorJustReturn: [])

let currentPage = currentIndex.map{ $0 }.asDriver(onErrorJustReturn: 0)

timeOverTrigger.do(onNext: {
do {
currentIndex.onNext(try currentIndex.value() + 1)
} catch { }
}).drive()
.disposed(by: disposeBag)
let userList = Driver.just(userSectionList)

let currentPage = timeOverTrigger.withLatestFrom(currentIndex.asDriver(onErrorJustReturn: 0)) { _, page in
currentIndex.onNext(page + 1)
return page + 1
}.startWith(0)

return Output(
userList: userList,
Expand Down

0 comments on commit 2305ef0

Please sign in to comment.