Skip to content

Commit

Permalink
Merge pull request #350 from boostcampwm2023/iOS/task/Rewind-Fix
Browse files Browse the repository at this point in the history
[iOS] ์—ฌ์ • ์กฐํšŒ ๊ฐœ์„ 
  • Loading branch information
SwiftyJunnos authored Jan 26, 2024
2 parents be4b1bf + fe42a21 commit 8ac1187
Show file tree
Hide file tree
Showing 18 changed files with 523 additions and 295 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -126,9 +126,7 @@ public final class HomeViewController: HomeBottomSheetViewController {
super.viewDidAppear(animated)

// ํ™”๋ฉด ์‹œ์ž‘ ์‹œ ์ƒˆ๋กœ๊ณ ์นจ ๋ฒ„ํŠผ ๊ธฐ๋Šฅ ํ•œ๋ฒˆ ์‹คํ–‰
if !self.viewModel.state.isRecording.value {
self.refreshButton.sendActions(for: .touchUpInside)
}
self.refreshButtonDidTap()
}

// MARK: - Combine Binding
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import Combine
import Foundation

import MSData
import MSDomain
import MSLogger

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,20 @@
// Created by ์ „๋ฏผ๊ฑด on 11/22/23.
//

import UIKit
import Combine
import UIKit

public final class MSProgressView: UIProgressView {

// MARK: - Properties

private let progressViewModel = MSProgressViewModel()
private var timerSubscriber: Set<AnyCancellable> = []
internal var percentage: Float = 0.0 {
didSet {
syncProgress(percentage: percentage)
}
private var progressViewModel: MSProgressViewModel!
private var timer: Set<AnyCancellable> = []

internal var percentage: Double = 0.0 {
willSet { self.syncProgress(percentage: newValue) }
}

internal var isHighlighted: Bool = false {
didSet {
if self.isHighlighted {
Expand All @@ -34,18 +34,24 @@ public final class MSProgressView: UIProgressView {
}
}
}

internal var isLeftOfCurrentHighlighting: Bool = false

// MARK: - Initializer

public override init(frame: CGRect) {
override init(frame: CGRect) {
super.init(frame: frame)
}

convenience init(frame: CGRect = .zero, duration: TimeInterval) {
self.init(frame: frame)
self.configureColor()
self.timerBinding()
self.progressViewModel = MSProgressViewModel(duration: duration)
self.bind()
}

required init?(coder: NSCoder) {
fatalError("MusicSpot์€ code-based ๋กœ ๊ฐœ๋ฐœ๋˜์—ˆ์Šต๋‹ˆ๋‹ค.")
fatalError("MusicSpot์€ code-based๋กœ๋งŒ ์ž‘์—… ์ค‘์ž…๋‹ˆ๋‹ค.")
}

// MARK: - Configure
Expand All @@ -57,18 +63,18 @@ public final class MSProgressView: UIProgressView {

// MARK: - Functions: change progress

private func syncProgress(percentage: Float) {
DispatchQueue.main.async { self.progress = percentage }
private func syncProgress(percentage: Double) {
DispatchQueue.main.async { self.progress = Float(percentage) }
}

// MARK: - Timer

private func timerBinding() {
private func bind() {
self.progressViewModel.timerPublisher
.sink { [weak self] currentPercentage in
self?.percentage = currentPercentage
}
.store(in: &timerSubscriber)
.store(in: &self.timer)
}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,43 +5,48 @@
// Created by ์ „๋ฏผ๊ฑด on 12/4/23.
//

import Foundation
import Combine
import Foundation

final class MSProgressViewModel {

// MARK: - Constants

private let timerDuration: Double = 4.0
private let timerTimeInterval: Double = 0.01
private enum Metric {
static let timeInterval: Double = 0.01
}

// MARK: - Properties

internal let timerPublisher = PassthroughSubject<Float, Never>()
internal let timerPublisher = PassthroughSubject<Double, Never>()
private var timer: AnyCancellable?

private let timerDuration: Double
private var remainingTime: Double

// MARK: Initializers

init() {
self.remainingTime = self.timerDuration
internal init(duration: TimeInterval) {
self.timerDuration = duration
self.remainingTime = duration
}

// MARK: - Functions: Timers

internal func startTimer() {
self.timer = Timer.publish(every: self.timerTimeInterval, on: .current, in: .common)
self.timer = Timer.publish(every: Metric.timeInterval, on: .current, in: .common)
.autoconnect()
.receive(on: DispatchQueue.global(qos: .background))
.sink { [weak self] _ in
guard let remainingTime = self?.remainingTime,
let timerDuration = self?.timerDuration,
let timerTimeInterval = self?.timerTimeInterval else { return }
let timerDuration = self?.timerDuration else {
return
}

self?.remainingTime -= timerTimeInterval
self?.remainingTime -= Metric.timeInterval
if remainingTime >= 0 {
let currentPercentage = ( timerDuration - remainingTime ) / timerDuration
self?.timerPublisher.send(Float(currentPercentage))
let currentPercentage: Double = (timerDuration - remainingTime) / timerDuration
self?.timerPublisher.send(currentPercentage)
} else {
self?.timerPublisher.send(1.0)
self?.stopTimer()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import UIKit

private enum Metric {

static let movedXPositionToBackScene: CGFloat = 50.0
static let movedYPositionToBackScene: CGFloat = 50.0
static let animationDuration: Double = 0.3

}
Expand All @@ -22,10 +22,10 @@ private enum Metric {
internal extension RewindJourneyViewController {

func configureLeftToRightSwipeGesture() {
let panGesture = UIPanGestureRecognizer(target: self, action: #selector(panGestureDismiss(_:)))
self.view.addGestureRecognizer(panGesture)
let panGesture = UIPanGestureRecognizer(target: self, action: #selector(self.panGestureDismiss(_:)))
self.view.addGestureRecognizer(panGesture)
}

@objc
private func panGestureDismiss(_ sender: UIPanGestureRecognizer) {
let touchPoint = sender.location(in: self.view.window)
Expand All @@ -35,14 +35,14 @@ internal extension RewindJourneyViewController {
case .began:
self.initialTouchPoint = touchPoint
case .changed:
if touchPoint.x - self.initialTouchPoint.x > .zero {
self.view.frame = CGRect(x: touchPoint.x - self.initialTouchPoint.x,
y: .zero,
if touchPoint.y - self.initialTouchPoint.y > .zero {
self.view.frame = CGRect(x: .zero,
y: touchPoint.y - self.initialTouchPoint.y,
width: width,
height: height)
}
case .ended, .cancelled:
if touchPoint.x - self.initialTouchPoint.x > Metric.movedXPositionToBackScene {
if touchPoint.y - self.initialTouchPoint.y > Metric.movedYPositionToBackScene {
self.navigationDelegate?.popToHome()
} else {
self.view.frame = CGRect(x: .zero,
Expand All @@ -51,11 +51,11 @@ internal extension RewindJourneyViewController {
height: height)
}
default:
UIView.animate(withDuration: Metric.animationDuration) {
self.view.frame = CGRect(x: .zero,
y: .zero,
width: width,
height: height)
UIView.animate(withDuration: Metric.animationDuration) { [weak self] in
self?.view.frame = CGRect(x: .zero,
y: .zero,
width: width,
height: height)
}
}
}
Expand Down
Loading

0 comments on commit 8ac1187

Please sign in to comment.