Skip to content
This repository was archived by the owner on Jan 16, 2023. It is now read-only.

Commit 65c37d6

Browse files
Merge pull request #365 from clappr/fix/quickseek_media_control
Fix QuickSeek when media control is visible
2 parents 86cbe39 + 3c30043 commit 65c37d6

File tree

2 files changed

+78
-11
lines changed

2 files changed

+78
-11
lines changed

Sources/Clappr_iOS/Classes/Plugin/Core/MediaControl/QuickSeekMediaControlPlugin.swift

+7-5
Original file line numberDiff line numberDiff line change
@@ -24,26 +24,28 @@ public class QuickSeekMediaControlPlugin: QuickSeekPlugin {
2424

2525
@objc private func didTap(gestureRecognizer: UITapGestureRecognizer) {
2626
if gestureRecognizer.state == .recognized {
27-
let point = gestureRecognizer.location(in: view)
27+
let point = gestureRecognizer.location(in: mediaControl?.mediaControlView)
2828
if shouldSeek(point: point) {
2929
mediaControl?.hide()
3030
quickSeek(xPosition: point.x)
3131
}
3232
}
3333
}
3434

35-
private func filteredOutModalPlugins() -> [UICorePlugin]? {
35+
private func filteredOutPlugins() -> [UICorePlugin]? {
3636
let pluginsWithoutMediaControl = core?.plugins.filter({ $0.pluginName != MediaControl.name })
37+
3738
return pluginsWithoutMediaControl?
3839
.compactMap({ $0 as? UICorePlugin })
39-
.filter({ ($0 as? MediaControl.Element)?.panel != .modal })
40+
.filter({ ($0 as? MediaControl.Element)?.panel != .modal
41+
&& !$0.isKind(of: OverlayPlugin.self) })
4042
}
4143

4244
override func shouldSeek(point: CGPoint) -> Bool {
4345
guard let mediaControlView = mediaControl?.mediaControlView else { return false }
4446

45-
let pluginColidingWithGesture = filteredOutModalPlugins()?.first(where: {
46-
$0.view.point(inside: mediaControlView.convert(point, to: $0.view), with: nil)
47+
let pluginColidingWithGesture = filteredOutPlugins()?.first(where: {
48+
$0.view.alpha != 0.0 && $0.view.point(inside: mediaControlView.convert(point, to: $0.view), with: nil)
4749
})
4850

4951
return pluginColidingWithGesture == nil

Tests/Clappr_Tests/Classes/Plugin/Core/MediaControl/QuickSeekMediaControlPluginTests.swift

+71-6
Original file line numberDiff line numberDiff line change
@@ -11,18 +11,17 @@ class QuickSeekMediaControlPluginTests: QuickSpec {
1111
var core: CoreStub!
1212
var mediaControl: MediaControl!
1313
var playButton: PlayButton!
14+
var overlayPlugin: OverlayPlugin!
1415

1516
beforeEach {
1617
Loader.shared.resetPlugins()
1718
core = CoreStub()
1819
core.playbackMock?.videoDuration = 60.0
1920
quickSeekPlugin = QuickSeekMediaControlPlugin(context: core)
2021
mediaControl = MediaControl(context: core)
21-
playButton = PlayButton(context: core)
2222

2323
core.addPlugin(mediaControl)
2424
core.addPlugin(quickSeekPlugin)
25-
core.addPlugin(playButton)
2625

2726
core.view.frame = CGRect(x: 0, y: 0, width: 320, height: 200)
2827

@@ -68,14 +67,64 @@ class QuickSeekMediaControlPluginTests: QuickSpec {
6867
}
6968
}
7069

71-
context("and it colides with another UICorePlugin") {
72-
it("does not seek") {
70+
describe("and there is another UICorePlugin") {
71+
beforeEach {
72+
playButton = PlayButton(context: core)
73+
74+
core.addPlugin(playButton)
75+
core.render()
76+
77+
mediaControl.render()
7378
playButton.view.layoutIfNeeded()
7479
mediaControl.view.layoutIfNeeded()
7580

76-
let shouldSeek = quickSeekPlugin.shouldSeek(point: CGPoint(x: 100, y: 100))
81+
}
82+
83+
context("and it collides with that plugin") {
84+
it("does not seek") {
85+
let playButtonCenterInMediaControlCoordinate = playButton.view.convert(playButton.view.center, to: mediaControl.mediaControlView)
86+
87+
let shouldSeek = quickSeekPlugin.shouldSeek(point: playButtonCenterInMediaControlCoordinate)
88+
89+
expect(shouldSeek).to(beFalse())
90+
}
91+
}
92+
93+
context("and it does not collide with that plugin") {
94+
it("does seek") {
95+
let pointOutsidePlayButton = CGPoint(x: playButton.view.frame.width + 1, y: playButton.view.frame.height + 1)
96+
let outsidePointInMediaControlCoordinate = playButton.view.convert(pointOutsidePlayButton, to: mediaControl.mediaControlView)
97+
98+
let shouldSeek = quickSeekPlugin.shouldSeek(point: outsidePointInMediaControlCoordinate)
99+
100+
expect(shouldSeek).to(beTrue())
101+
}
102+
}
103+
104+
context("and that plugin is not visible") {
105+
it("does seek") {
106+
let playButtonCenterInMediaControlCoordinate = playButton.view.convert(playButton.view.center, to: mediaControl.mediaControlView)
107+
playButton.view.alpha = 0.0
108+
109+
let shouldSeek = quickSeekPlugin.shouldSeek(point: playButtonCenterInMediaControlCoordinate)
110+
111+
expect(shouldSeek).to(beTrue())
112+
}
113+
}
114+
}
115+
116+
context("and there are not visible overlay plugins") {
117+
it("ignores them and seeks") {
118+
overlayPlugin = OverlayPluginStub(context: core)
119+
core.addPlugin(overlayPlugin)
120+
core.render()
121+
overlayPlugin.render()
122+
overlayPlugin.view.layoutIfNeeded()
123+
let overlayPluginCenterInMediaControlCoordinate = overlayPlugin.view.convert(overlayPlugin.view.center, to: mediaControl.mediaControlView)
124+
125+
let shouldSeek = quickSeekPlugin.shouldSeek(point: overlayPluginCenterInMediaControlCoordinate)
77126

78-
expect(shouldSeek).to(beFalse())
127+
expect(shouldSeek).to(beTrue())
79128
}
80129
}
81130

@@ -138,3 +187,19 @@ class QuickSeekMediaControlPluginTests: QuickSpec {
138187
}
139188
}
140189
}
190+
191+
class OverlayPluginStub: OverlayPlugin {
192+
override var isModal: Bool {
193+
true
194+
}
195+
196+
override class var name: String {
197+
"OverlayPluginStub"
198+
}
199+
200+
override func bindEvents() {}
201+
202+
override func render() {
203+
view.backgroundColor = .red
204+
}
205+
}

0 commit comments

Comments
 (0)