From b12cdaf20751e5286bd023b6fdc7a2e25eba5c75 Mon Sep 17 00:00:00 2001 From: Eric Andrews Date: Tue, 10 Dec 2024 22:38:11 -0500 Subject: [PATCH] videos stop when they disappear --- .../Shared/Images/Core/DynamicMediaView.swift | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/Mlem/App/Views/Shared/Images/Core/DynamicMediaView.swift b/Mlem/App/Views/Shared/Images/Core/DynamicMediaView.swift index a9cc0c108..a99ccea2d 100644 --- a/Mlem/App/Views/Shared/Images/Core/DynamicMediaView.swift +++ b/Mlem/App/Views/Shared/Images/Core/DynamicMediaView.swift @@ -48,10 +48,16 @@ struct DynamicMediaView: View { } var body: some View { - if #available(iOS 18.0, *) { - ios18Body() - } else { - legacyBody + Group { + if #available(iOS 18.0, *) { + ios18Body() + } else { + legacyBody + } + } + .onDisappear { + // TODO: iOS 17 deprecation remove this--redundant with onScrollVisibilityChange handler + playing = false } } @@ -59,9 +65,12 @@ struct DynamicMediaView: View { func ios18Body() -> some View { legacyBody .onScrollVisibilityChange(threshold: 0.5) { isVisible in - if autoplayMedia { + if isVisible, autoplayMedia { playing = isVisible } + if !isVisible { + playing = false + } } }