From b5a00cb33fd92c78a9811442e67e019d2c12e125 Mon Sep 17 00:00:00 2001 From: "Pfeil, Scott Robert" Date: Fri, 12 Feb 2021 15:28:38 -0500 Subject: [PATCH] debug cleanup --- MVMCoreUI/Atomic/Atoms/Views/Video.swift | 9 ++++---- MVMCoreUI/Atomic/Atoms/Views/VideoModel.swift | 22 ------------------- 2 files changed, 5 insertions(+), 26 deletions(-) diff --git a/MVMCoreUI/Atomic/Atoms/Views/Video.swift b/MVMCoreUI/Atomic/Atoms/Views/Video.swift index 06474f95..baee04f6 100644 --- a/MVMCoreUI/Atomic/Atoms/Views/Video.swift +++ b/MVMCoreUI/Atomic/Atoms/Views/Video.swift @@ -9,7 +9,7 @@ import AVKit open class Video: View { public let videoViewController = AVPlayerViewController() - public var delegateObject: MVMCoreUIDelegateObject? + private weak var containingView: UIView? /// Used to track the state and respond.. private var stateKVOToken: NSKeyValueObservation? @@ -24,7 +24,7 @@ open class Video: View { /// Checks if the video is visible in the molecule delegate open func isVisibleInDelegate() -> Bool { - guard let containingView = (delegateObject?.moleculeDelegate as? UIViewController)?.view else { return true } + guard let containingView = containingView else { return true } return isVisible(in: containingView) } @@ -34,11 +34,12 @@ open class Video: View { } open override func set(with model: MoleculeModelProtocol, _ delegateObject: MVMCoreUIDelegateObject?, _ additionalData: [AnyHashable: Any]?) { - self.delegateObject = delegateObject + /// Detach the view from it's previous model before setting. (self.model as? VideoModel)?.view = nil + containingView = (delegateObject?.moleculeDelegate as? UIViewController)?.view super.set(with: model, delegateObject, additionalData) - guard let model = model as? VideoModel else { return } + guard let model = model as? VideoModel else { return } if let controller = delegateObject?.moleculeDelegate as? UIViewController { controller.addChild(videoViewController) videoViewController.didMove(toParent: controller) diff --git a/MVMCoreUI/Atomic/Atoms/Views/VideoModel.swift b/MVMCoreUI/Atomic/Atoms/Views/VideoModel.swift index ac97eba0..1d079599 100644 --- a/MVMCoreUI/Atomic/Atoms/Views/VideoModel.swift +++ b/MVMCoreUI/Atomic/Atoms/Views/VideoModel.swift @@ -24,9 +24,7 @@ open class VideoModel: MoleculeModelProtocol { videoDataManager.videoState == .loaded else { return } if halted { videoDataManager.player?.pause() - printThat(string: "halted") } else { - printThat(string: "unhalted") if alwaysReset { // Always start video at the beginning. videoDataManager.player?.seek(to: .zero) @@ -83,28 +81,8 @@ open class VideoModel: MoleculeModelProtocol { try container.encode(alwaysReset, forKey: .alwaysReset) } - func printThat(string: String) { - var newString = "sss" + string + " model:\(Unmanaged.passUnretained(self).toOpaque())" - if var view: UIView = self.view { - newString = newString + " view:\(Unmanaged.passUnretained(view).toOpaque())" - while (view as? BGVideoImageMolecule) == nil { - if let superView = view.superview { - view = superView - } else { - break - } - } - if let title = (((view as? BGVideoImageMolecule)?.view as? FooterView)?.view as? TwoButtonView)?.primaryButton.title(for: .normal) { - newString = newString + " \(title)" - } - } - print(newString) - } - open func addVisibilityHalting(for view: Video, delegateObject: MVMCoreUIDelegateObject?) { - printThat(string: "before adding") self.view = view - printThat(string: "after adding") halted = false addVisibleBehavior(for: view, delegateObject: delegateObject) addScrollBehavior(for: view, delegateObject: delegateObject)