Skip to content

Commit

Permalink
videos stop when they disappear
Browse files Browse the repository at this point in the history
  • Loading branch information
EricBAndrews committed Dec 11, 2024
1 parent 65bfe87 commit b12cdaf
Showing 1 changed file with 14 additions and 5 deletions.
19 changes: 14 additions & 5 deletions Mlem/App/Views/Shared/Images/Core/DynamicMediaView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -48,20 +48,29 @@ 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
}
}

@available(iOS 18.0, *)
func ios18Body() -> some View {
legacyBody
.onScrollVisibilityChange(threshold: 0.5) { isVisible in
if autoplayMedia {
if isVisible, autoplayMedia {
playing = isVisible
}
if !isVisible {
playing = false
}
}
}

Expand Down

0 comments on commit b12cdaf

Please sign in to comment.