Skip to content

Commit

Permalink
fix(ios, macos): Suspend media playback when destroying WebView on iO…
Browse files Browse the repository at this point in the history
…S/macOS (react-native-webview#3234)

* Suspend media playback when destroying WebView on iOS/macOS

* Fixes crash on iOS <15.0 and macOS <12.0 when pausing playback on dismount

---------

Co-authored-by: Thibault Malbranche <thibault@brigad.co>
  • Loading branch information
davidsharp and Titozzz committed Feb 13, 2024
1 parent d02f575 commit 7af398c
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions apple/RNCWebViewImpl.m
Original file line number Diff line number Diff line change
Expand Up @@ -569,6 +569,11 @@ - (void)removeFromSuperview
[_webView.configuration.userContentController removeScriptMessageHandlerForName:MessageHandlerName];
[_webView removeObserver:self forKeyPath:@"estimatedProgress"];
[_webView removeFromSuperview];
if (@available(iOS 15.0, macOS 12.0, *)) {
[_webView pauseAllMediaPlaybackWithCompletionHandler:nil];
} else if (@available(iOS 14.5, macOS 11.3, *)) {
[_webView suspendAllMediaPlayback:nil];
}
#if !TARGET_OS_OSX
_webView.scrollView.delegate = nil;
if (_menuItems) {
Expand Down

0 comments on commit 7af398c

Please sign in to comment.