Skip to content

Commit

Permalink
refactor/#388 SegmentedControl 기능 추가 및 Observable Pattern 맞게 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
youz2me committed Sep 16, 2024
1 parent 89764bc commit e81ec57
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ class PromiseViewController: BaseViewController {
transitionStyle: .scroll,
navigationOrientation: .vertical
)

private var removePromiseViewContoller: RemovePromiseViewController = RemovePromiseViewController(promiseName: "")
private var promiseViewControllerList: [BaseViewController] = []
private lazy var promiseSegmentedControl = PagePromiseSegmentedControl(items: ["약속 정보", "준비 현황", "지각 꾸물이"])
Expand Down Expand Up @@ -149,29 +148,28 @@ private extension PromiseViewController {
owner.navigationController?.navigationItem.rightBarButtonItem = info.isParticipant ? moreButton : nil
owner.setupNavigationBarTitle(with: info.promiseName, isBorderHidden: true)
}

viewModel.currentPageIndex.bindOnMain(with: self) { owner, index in
let direction: UIPageViewController.NavigationDirection = owner.viewModel.pageControlDirection ? .forward : .reverse
let (width, count) = (
owner.promiseSegmentedControl.bounds.width,
owner.promiseSegmentedControl.numberOfSegments
)

owner.promiseSegmentedControl.selectedUnderLineView.snp.updateConstraints {
$0.leading.equalToSuperview().offset((width / CGFloat(count)) * CGFloat(index))
}

owner.promisePageViewController.setViewControllers([
owner.promiseViewControllerList[index]
], direction: direction, animated: false)
}
}

@objc
func didSegmentedControlIndexUpdated() {
// let condition = viewModel.currentPageIndex.value <= promiseSegmentedControl.selectedSegmentIndex
// let direction: UIPageViewController.NavigationDirection = condition ? .forward : .reverse
// let (width, count, selectedIndex) = (
// promiseSegmentedControl.bounds.width,
// promiseSegmentedControl.numberOfSegments,
// promiseSegmentedControl.selectedSegmentIndex
// )
//
// promiseSegmentedControl.selectedUnderLineView.snp.updateConstraints {
// $0.leading.equalToSuperview().offset((width / CGFloat(count)) * CGFloat(selectedIndex))
// }
//
// viewModel.segmentIndexDidChange(
// index: promiseSegmentedControl.selectedSegmentIndex
// )
//
// promisePageViewController.setViewControllers([
// promiseViewControllerList[viewModel.currentPageIndex.value]
// ], direction: direction, animated: false)
viewModel.pageControlDirection = viewModel.currentPageIndex.value <= promiseSegmentedControl.selectedSegmentIndex
viewModel.currentPageIndex.value = promiseSegmentedControl.selectedSegmentIndex
}

@objc
Expand Down
3 changes: 3 additions & 0 deletions KkuMulKum/Source/Promise/ViewModel/PromiseViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,16 @@ class PromiseViewModel {
// MARK: Property

let promiseID: Int
let currentPageIndex = ObservablePattern<Int>(0)
let promiseInfo = ObservablePattern<PromiseInfoModel?>(nil)
let isPastDue = ObservablePattern<Bool?>(nil)
let penalty = ObservablePattern<String?>(nil)
let dDay = ObservablePattern<Int?>(nil)
let participantList = ObservablePattern<[Participant]>([])
let tardyList = ObservablePattern<[Comer]>([])

var pageControlDirection = false

private let service: PromiseServiceProtocol


Expand Down

0 comments on commit e81ec57

Please sign in to comment.