Improvement UI/UX in scrubbing
This commit is contained in:
parent
7a26e69685
commit
28c6f9e760
|
@ -74,9 +74,13 @@ final class VideoPlayerViewModel: ViewModel {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Published
|
||||||
|
var isHiddenCenterViews = false
|
||||||
|
|
||||||
@Published
|
@Published
|
||||||
var sliderIsScrubbing: Bool = false {
|
var sliderIsScrubbing: Bool = false {
|
||||||
didSet {
|
didSet {
|
||||||
|
isHiddenCenterViews = sliderIsScrubbing
|
||||||
beganScrubbingCurrentSeconds = currentSeconds
|
beganScrubbingCurrentSeconds = currentSeconds
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -280,10 +284,10 @@ final class VideoPlayerViewModel: ViewModel {
|
||||||
|
|
||||||
leftLabelText = calculateTimeText(from: currentSeconds)
|
leftLabelText = calculateTimeText(from: currentSeconds)
|
||||||
rightLabelText = calculateTimeText(from: secondsScrubbedRemaining)
|
rightLabelText = calculateTimeText(from: secondsScrubbedRemaining)
|
||||||
scrubbingTimeLabelText = calculateTimeText(from: currentSeconds - beganScrubbingCurrentSeconds)
|
scrubbingTimeLabelText = calculateTimeText(from: currentSeconds - beganScrubbingCurrentSeconds, isScrubbing: true)
|
||||||
}
|
}
|
||||||
|
|
||||||
private func calculateTimeText(from duration: Double) -> String {
|
private func calculateTimeText(from duration: Double, isScrubbing: Bool = false) -> String {
|
||||||
let isNegative = duration < 0
|
let isNegative = duration < 0
|
||||||
let duration = abs(duration)
|
let duration = abs(duration)
|
||||||
let hours = floor(duration / 3600)
|
let hours = floor(duration / 3600)
|
||||||
|
@ -300,8 +304,12 @@ final class VideoPlayerViewModel: ViewModel {
|
||||||
"\(String(Int(floor(minutes))).leftPad(toWidth: 2, withString: "0")):\(String(Int(floor(seconds))).leftPad(toWidth: 2, withString: "0"))"
|
"\(String(Int(floor(minutes))).leftPad(toWidth: 2, withString: "0")):\(String(Int(floor(seconds))).leftPad(toWidth: 2, withString: "0"))"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if isScrubbing {
|
||||||
|
return "\(isNegative ? "-" : "+") \(timeText)"
|
||||||
|
} else {
|
||||||
return "\(isNegative ? "-" : "") \(timeText)"
|
return "\(isNegative ? "-" : "") \(timeText)"
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// MARK: Injected Values
|
// MARK: Injected Values
|
||||||
|
|
|
@ -323,6 +323,7 @@ struct VLCPlayerOverlayView: View {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
.font(.system(size: 48))
|
.font(.system(size: 48))
|
||||||
|
.opacity(viewModel.isHiddenCenterViews ? 0 : 1)
|
||||||
}
|
}
|
||||||
|
|
||||||
Spacer()
|
Spacer()
|
||||||
|
|
|
@ -360,6 +360,7 @@ class VLCPlayerViewController: UIViewController {
|
||||||
private func didHorizontalPan(_ gestureRecognizer: UIPanGestureRecognizer) {
|
private func didHorizontalPan(_ gestureRecognizer: UIPanGestureRecognizer) {
|
||||||
switch gestureRecognizer.state {
|
switch gestureRecognizer.state {
|
||||||
case .began:
|
case .began:
|
||||||
|
exchangeOverlayView(isBringToFrontThanGestureView: false)
|
||||||
panBeganPoint = gestureRecognizer.location(in: mainGestureView)
|
panBeganPoint = gestureRecognizer.location(in: mainGestureView)
|
||||||
panBeganSliderPercentage = viewModel.sliderPercentage
|
panBeganSliderPercentage = viewModel.sliderPercentage
|
||||||
viewModel.sliderIsScrubbing = true
|
viewModel.sliderIsScrubbing = true
|
||||||
|
@ -370,8 +371,10 @@ class VLCPlayerViewController: UIViewController {
|
||||||
|
|
||||||
viewModel.sliderPercentage = min(max(0, panBeganSliderPercentage - changedValue), 1)
|
viewModel.sliderPercentage = min(max(0, panBeganSliderPercentage - changedValue), 1)
|
||||||
showSliderOverlay()
|
showSliderOverlay()
|
||||||
|
showOverlay()
|
||||||
default:
|
default:
|
||||||
viewModel.sliderIsScrubbing = false
|
viewModel.sliderIsScrubbing = false
|
||||||
|
hideOverlay()
|
||||||
hideSystemControlOverlay()
|
hideSystemControlOverlay()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -502,6 +505,17 @@ class VLCPlayerViewController: UIViewController {
|
||||||
|
|
||||||
currentJumpForwardOverlayView = newJumpForwardImageView
|
currentJumpForwardOverlayView = newJumpForwardImageView
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private var isOverlayViewBringToFrontThanGestureView = true
|
||||||
|
private func exchangeOverlayView(isBringToFrontThanGestureView: Bool) {
|
||||||
|
guard isBringToFrontThanGestureView != isOverlayViewBringToFrontThanGestureView,
|
||||||
|
let currentOverlayView = currentOverlayHostingController?.view,
|
||||||
|
let mainGestureViewIndex = view.subviews.firstIndex(of: mainGestureView),
|
||||||
|
let currentOVerlayViewIndex = view.subviews.firstIndex(of: currentOverlayView) else { return }
|
||||||
|
isOverlayViewBringToFrontThanGestureView = isBringToFrontThanGestureView
|
||||||
|
view.exchangeSubview(at: mainGestureViewIndex,
|
||||||
|
withSubviewAt: currentOVerlayViewIndex)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// MARK: setupMediaPlayer
|
// MARK: setupMediaPlayer
|
||||||
|
@ -679,14 +693,12 @@ extension VLCPlayerViewController {
|
||||||
guard overlayHostingController.view.alpha != 0 else { return }
|
guard overlayHostingController.view.alpha != 0 else { return }
|
||||||
|
|
||||||
// for gestures UX
|
// for gestures UX
|
||||||
view.exchangeSubview(at: view.subviews.firstIndex(of: mainGestureView)!,
|
exchangeOverlayView(isBringToFrontThanGestureView: false)
|
||||||
withSubviewAt: view.subviews.firstIndex(of: overlayHostingController.view)!)
|
|
||||||
UIView.animate(withDuration: 0.2, delay: 0, options: .curveEaseInOut) {
|
UIView.animate(withDuration: 0.2, delay: 0, options: .curveEaseInOut) {
|
||||||
overlayHostingController.view.alpha = 0
|
overlayHostingController.view.alpha = 0
|
||||||
} completion: { [weak self] _ in
|
} completion: { [weak self] _ in
|
||||||
guard let self = self else { return }
|
guard let self = self else { return }
|
||||||
self.view.exchangeSubview(at: self.view.subviews.firstIndex(of: self.mainGestureView)!,
|
self.exchangeOverlayView(isBringToFrontThanGestureView: true)
|
||||||
withSubviewAt: self.view.subviews.firstIndex(of: overlayHostingController.view)!)
|
|
||||||
self.viewModel.isHiddenOverlay = true
|
self.viewModel.isHiddenOverlay = true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -773,8 +785,6 @@ extension VLCPlayerViewController {
|
||||||
}
|
}
|
||||||
|
|
||||||
private func showSliderOverlay() {
|
private func showSliderOverlay() {
|
||||||
guard !displayingOverlay else { return }
|
|
||||||
|
|
||||||
let imageAttachment = NSTextAttachment()
|
let imageAttachment = NSTextAttachment()
|
||||||
imageAttachment.image = UIImage(systemName: "clock.arrow.circlepath",
|
imageAttachment.image = UIImage(systemName: "clock.arrow.circlepath",
|
||||||
withConfiguration: UIImage.SymbolConfiguration(pointSize: 48))?
|
withConfiguration: UIImage.SymbolConfiguration(pointSize: 48))?
|
||||||
|
|
Loading…
Reference in New Issue