diff --git a/MVMCoreUI/Behaviors/ReplaceableMoleculeBehaviorModel.swift b/MVMCoreUI/Behaviors/ReplaceableMoleculeBehaviorModel.swift index 8b624a7b..c35a5d19 100644 --- a/MVMCoreUI/Behaviors/ReplaceableMoleculeBehaviorModel.swift +++ b/MVMCoreUI/Behaviors/ReplaceableMoleculeBehaviorModel.swift @@ -30,7 +30,7 @@ public class ReplaceableMoleculeBehavior: PageMoleculeTransformationBehavior, Pa String(describing: Self.self) } - var hasPreviouslyBeenShown = false + var isPageShowing = false var previouslyReplacedIds = Set() var moleculeIds: [String] public var modulesToListenFor: [String] @@ -120,21 +120,22 @@ public class ReplaceableMoleculeBehavior: PageMoleculeTransformationBehavior, Pa return } previouslyReplacedIds.insert(moleculeId) + guard isPageShowing else { return } // Page has not been made visible yet. (Pulled and replaced from cache on load or background update.) Hold reporting until onPageShown. MVMCoreUILoggingHandler.shared()?.defaultLogPageUpdate(forController: viewController, from: module) } public func onPageShown(_ delegateObject: MVMCoreUIDelegateObject?) { - guard hasPreviouslyBeenShown else { - // Skip first replacement build handled in onPageNew. (Pulled and reported from cache.) - hasPreviouslyBeenShown = true - return - } - debugLog("Page reshown. Resend replaced molecule analytics for: \(previouslyReplacedIds)") + isPageShowing = true + debugLog("Page shown. Send molecule analytics for: \(previouslyReplacedIds)") previouslyReplacedIds.forEach { id in logUpdated(moleculeId: id) } } + public func onPageHidden(_ delegateObject: MVMCoreUIDelegateObject?) { + isPageShowing = false + } + deinit { debugLog("deinit") }