Skip to content

Commit

Permalink
added tick marks to the newReleasesSlider UISlider and snap functiona…
Browse files Browse the repository at this point in the history
…lity as detailed in issue 8. also fixed a typo.

added tick marks to the newReleasesSlider UISlider and snap functionality as detailed in issue 8. also fixed a typo.
  • Loading branch information
amustafa15 committed Sep 29, 2021
1 parent 46ba8cf commit ae449f5
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ RecentlyPlayedTracksViewModelOutput {
self.dataManager = dataManager
self.safariService = safariService

// Initializing utputs
// Initializing outputs
title = Observable.just("Your Recently Played Tracks")

trackCollections = sessionService.getRecentlyPlayedTracks(limit: 50)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ final class NewReleasesViewController: ViewControllerWithSideMenu, BindableType
configureNavigationBar()
configureTableView()
setUpView()
createTickView()
}

deinit {
Expand All @@ -63,6 +64,10 @@ final class NewReleasesViewController: ViewControllerWithSideMenu, BindableType
newReleasesSlider.trailingAnchor.constraint(equalTo: layoutGuide.trailingAnchor, constant: -Constraints.outerMargins).isActive = true
newReleasesSlider.heightAnchor.constraint(equalToConstant: Constraints.height).isActive = true

// adds target to method snap functionality on the newReleasesSlider UISlider
newReleasesSlider.addTarget(self, action: #selector(sliderChanged), for: .touchUpInside)
newReleasesSlider.isContinuous = false

tableView.topAnchor.constraint(equalTo: newReleasesSlider.bottomAnchor).isActive = true
tableView.leadingAnchor.constraint(equalTo: layoutGuide.leadingAnchor).isActive = true
tableView.trailingAnchor.constraint(equalTo: layoutGuide.trailingAnchor).isActive = true
Expand Down Expand Up @@ -93,6 +98,24 @@ final class NewReleasesViewController: ViewControllerWithSideMenu, BindableType
)
}

// creates the tick mark view and inserts it on top of the newReleasesSlider UISlider
private func createTickView() {
var tick : UIView
let tickArray = Array(1...12)
for i in 0..<tickArray.count {
tick = UIView(frame: CGRect(x: (newReleasesSlider.frame.size.width / 3) * CGFloat(i), y: (newReleasesSlider.frame.size.height - 13) / 2, width: 2, height: 13))
tick.backgroundColor = ColorPreference.tertiaryColor
newReleasesSlider.insertSubview(tick, belowSubview: newReleasesSlider)
}
}

// provides the snap functionality on the newReleasesSlider UISlider
@objc func sliderChanged(){
let step:Float = 1
let roundedStepValue = round(newReleasesSlider.value / step) * step
newReleasesSlider.value = roundedStepValue
}

func bindViewModel() {
let input = viewModel.input
let output = viewModel.output
Expand Down Expand Up @@ -143,7 +166,8 @@ final class NewReleasesViewController: ViewControllerWithSideMenu, BindableType
newReleasesSlider.rx.value
.debounce(.milliseconds(500), scheduler: MainScheduler.instance)
.bind(onNext: { [unowned self] value in
self.sliderTimeRange.text = "New releases within the past \(Int(value)) months"
// value.rounded() makes sure sliderTimeRange.text is accurate after thumbnail snaps to closest Int
self.sliderTimeRange.text = "New releases within the past \(Int(value.rounded())) months"
input.sliderValue.accept(value)
})
.disposed(by: disposeBag)
Expand Down

0 comments on commit ae449f5

Please sign in to comment.