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

Commit

Permalink
Merge pull request #338 from clappr/feature/render_mediacontrol_order
Browse files Browse the repository at this point in the history
Render plugins order
  • Loading branch information
caiobzen authored Aug 20, 2019
2 parents c0852d5 + d39fbdd commit 7f515d3
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 5 deletions.
6 changes: 4 additions & 2 deletions Sources/Clappr/Classes/Base/Core.swift
Original file line number Diff line number Diff line change
Expand Up @@ -162,12 +162,14 @@ open class Core: UIObject, UIGestureRecognizerDelegate {

fileprivate func addToContainer() {
#if os(iOS)
renderCorePlugins()
renderMediaControlElements()
if shouldEnterInFullScreen {
renderCorePlugins()
renderMediaControlElements()
fullscreenHandler?.enterInFullscreen()
} else {
renderInContainerView()
renderCorePlugins()
renderMediaControlElements()
}
#else
renderInContainerView()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -520,6 +520,8 @@ class MediaControlElementMock: MediaControl.Element {
if MediaControlElementMock.crashOnRender {
codeThatCrashes()
}

trigger("render")
}

static func reset() {
Expand Down
31 changes: 28 additions & 3 deletions Tests/Clappr_Tests/CoreTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -693,7 +693,7 @@ class CoreTests: QuickSpec {
}

#if os(iOS)
it("doesnt add plugin as subview if it is a MediaControlPlugin") {
it("doesnt add plugin as subview if it is a MediaControlElement") {
let core = Core()
let plugin = MediaControlElementMock(context: core)

Expand All @@ -702,8 +702,31 @@ class CoreTests: QuickSpec {

expect(plugin.view.superview).to(beNil())
}

it("renders MediaControlElements after CorePlugins") {
let core = Core()
let mediaControl = MediaControl(context: core)
let element = MediaControlElementMock(context: core)
let plugin = UICorePluginMock(context: core)

var renderingOrder: [String] = []
element.on("render") { _ in
renderingOrder.append("element")
}

plugin.on("render") { _ in
renderingOrder.append("plugin")
}

core.addPlugin(mediaControl)
core.addPlugin(element)
core.addPlugin(plugin)
core.render()

expect(renderingOrder).toEventually(equal(["plugin", "element"]))
}

it("calls the mediacontrol to add the plugins into the panels") {
it("calls the mediacontrol to add the elements into the panels") {
let core = CoreFactory.create(with: [:])
let mediaControlMock = MediaControlMock(context: core)
let mediaControlPluginMock = MediaControlElementMock(context: core)
Expand Down Expand Up @@ -773,13 +796,16 @@ class UICorePluginMock: UICorePlugin {
override class var name: String {
return "UICorePluginMock"
}


override func render() {
UICorePluginMock.didCallRender = true

if UICorePluginMock.crashOnRender {
codeThatCrashes()
}

trigger("render")
}

override func bindEvents() { }
Expand All @@ -805,7 +831,6 @@ class CorePluginMock: CorePlugin {
override class var name: String {
return "CorePluginMock"
}

}

#if os(iOS)
Expand Down

0 comments on commit 7f515d3

Please sign in to comment.