diff --git a/example/lib/in_app_webiew_example.screen.dart b/example/lib/in_app_webiew_example.screen.dart index 3bba112f..bb384a8b 100755 --- a/example/lib/in_app_webiew_example.screen.dart +++ b/example/lib/in_app_webiew_example.screen.dart @@ -167,8 +167,6 @@ class _InAppWebViewExampleScreenState extends State { this.url = url.toString(); urlController.text = this.url; }); - await Future.delayed(Duration(seconds: 2)); - await controller.closeAllMediaPresentations(); }, onLoadError: (controller, url, code, message) { pullToRefreshController.endRefreshing(); diff --git a/lib/src/in_app_webview/in_app_webview_controller.dart b/lib/src/in_app_webview/in_app_webview_controller.dart index 0669b6df..446cd5b4 100644 --- a/lib/src/in_app_webview/in_app_webview_controller.dart +++ b/lib/src/in_app_webview/in_app_webview_controller.dart @@ -47,7 +47,7 @@ final _JAVASCRIPT_HANDLER_FORBIDDEN_NAMES = UnmodifiableListView([ ///If you are using the [InAppWebView] widget, an [InAppWebViewController] instance can be obtained by setting the [InAppWebView.onWebViewCreated] ///callback. Instead, if you are using an [InAppBrowser] instance, you can get it through the [InAppBrowser.webViewController] attribute. class InAppWebViewController - with AndroidInAppWebViewControllerMixin, IOSInAppWebViewControllerMixin { + with AndroidInAppWebViewControllerMixin, AppleInAppWebViewControllerMixin { WebView? _webview; late MethodChannel _channel; static MethodChannel _staticChannel = IN_APP_WEBVIEW_STATIC_CHANNEL; @@ -2793,63 +2793,21 @@ class InAppWebViewController await _channel.invokeMethod('addWebMessageListener', args); } - ///Pauses playback of all media in the web view. - /// - ///**NOTE for iOS**: available on iOS 15.0+. - /// - ///**Supported Platforms/Implementations**: - ///- iOS ([Official API - WKWebView.pauseAllMediaPlayback](https://developer.apple.com/documentation/webkit/wkwebview/3752240-pauseallmediaplayback)). - Future pauseAllMediaPlayback() async { - Map args = {}; - return await _channel.invokeMethod('pauseAllMediaPlayback', args); - } - - ///Changes whether the webpage is suspending playback of all media in the page. - ///Pass `true` to pause all media the web view is playing. Neither the user nor the webpage can resume playback until you call this method again with `false`. - /// - ///[suspended] represents a [bool] value that indicates whether the webpage should suspend media playback. - /// - ///**NOTE for iOS**: available on iOS 15.0+. - /// - ///**Supported Platforms/Implementations**: - ///- iOS ([Official API - WKWebView.setAllMediaPlaybackSuspended](https://developer.apple.com/documentation/webkit/wkwebview/3752242-setallmediaplaybacksuspended)). - Future setAllMediaPlaybackSuspended({required bool suspended}) async { - Map args = {}; - args.putIfAbsent("suspended", () => suspended); - return await _channel.invokeMethod('setAllMediaPlaybackSuspended', args); - } - - ///Closes all media the web view is presenting, including picture-in-picture video and fullscreen video. - /// - ///**NOTE for iOS**: available on iOS 14.5+. - /// - ///**Supported Platforms/Implementations**: - ///- iOS ([Official API - WKWebView.closeAllMediaPresentations](https://developer.apple.com/documentation/webkit/wkwebview/3752235-closeallmediapresentations)). - Future closeAllMediaPresentations() async { - Map args = {}; - return await _channel.invokeMethod('closeAllMediaPresentations', args); - } - - ///Requests the playback status of media in the web view. - ///Returns a [MediaPlaybackState] that indicates whether the media in the web view is playing, paused, or suspended. - ///If there’s no media in the web view to play, this method provides [MediaPlaybackState.NONE]. - /// - ///**NOTE for iOS**: available on iOS 15.0+. - /// - ///**Supported Platforms/Implementations**: - ///- iOS ([Official API - WKWebView.requestMediaPlaybackState](https://developer.apple.com/documentation/webkit/wkwebview/3752241-requestmediaplaybackstate)). - Future requestMediaPlaybackState() async { - Map args = {}; - return MediaPlaybackState.fromValue(await _channel.invokeMethod('requestMediaPlaybackState', args)); - } - ///Returns `true` if the webpage can scroll vertically, otherwise `false`. + /// + ///**Supported Platforms/Implementations**: + ///- Android native WebView + ///- iOS Future canScrollVertically() async { Map args = {}; return await _channel.invokeMethod('canScrollVertically', args); } ///Returns `true` if the webpage can scroll horizontally, otherwise `false`. + /// + ///**Supported Platforms/Implementations**: + ///- Android native WebView + ///- iOS Future canScrollHorizontally() async { Map args = {}; return await _channel.invokeMethod('canScrollHorizontally', args); diff --git a/lib/src/in_app_webview/ios/in_app_webview_controller.dart b/lib/src/in_app_webview/ios/in_app_webview_controller.dart index 1f0903ea..ad43faa1 100644 --- a/lib/src/in_app_webview/ios/in_app_webview_controller.dart +++ b/lib/src/in_app_webview/ios/in_app_webview_controller.dart @@ -7,7 +7,7 @@ import '../../types.dart'; import '../in_app_webview_controller.dart'; ///Class mixin that contains only iOS-specific methods for the WebView. -abstract class IOSInAppWebViewControllerMixin { +abstract class AppleInAppWebViewControllerMixin { late MethodChannel _channel; ///Reloads the current page, performing end-to-end revalidation using cache-validating conditionals if possible. @@ -59,11 +59,61 @@ abstract class IOSInAppWebViewControllerMixin { Map args = {}; return await _channel.invokeMethod('hasOnlySecureContent', args); } + + ///Pauses playback of all media in the web view. + /// + ///**NOTE for iOS**: available on iOS 15.0+. + /// + ///**Supported Platforms/Implementations**: + ///- iOS ([Official API - WKWebView.pauseAllMediaPlayback](https://developer.apple.com/documentation/webkit/wkwebview/3752240-pauseallmediaplayback)). + Future pauseAllMediaPlayback() async { + Map args = {}; + return await _channel.invokeMethod('pauseAllMediaPlayback', args); + } + + ///Changes whether the webpage is suspending playback of all media in the page. + ///Pass `true` to pause all media the web view is playing. Neither the user nor the webpage can resume playback until you call this method again with `false`. + /// + ///[suspended] represents a [bool] value that indicates whether the webpage should suspend media playback. + /// + ///**NOTE for iOS**: available on iOS 15.0+. + /// + ///**Supported Platforms/Implementations**: + ///- iOS ([Official API - WKWebView.setAllMediaPlaybackSuspended](https://developer.apple.com/documentation/webkit/wkwebview/3752242-setallmediaplaybacksuspended)). + Future setAllMediaPlaybackSuspended({required bool suspended}) async { + Map args = {}; + args.putIfAbsent("suspended", () => suspended); + return await _channel.invokeMethod('setAllMediaPlaybackSuspended', args); + } + + ///Closes all media the web view is presenting, including picture-in-picture video and fullscreen video. + /// + ///**NOTE for iOS**: available on iOS 14.5+. + /// + ///**Supported Platforms/Implementations**: + ///- iOS ([Official API - WKWebView.closeAllMediaPresentations](https://developer.apple.com/documentation/webkit/wkwebview/3752235-closeallmediapresentations)). + Future closeAllMediaPresentations() async { + Map args = {}; + return await _channel.invokeMethod('closeAllMediaPresentations', args); + } + + ///Requests the playback status of media in the web view. + ///Returns a [MediaPlaybackState] that indicates whether the media in the web view is playing, paused, or suspended. + ///If there’s no media in the web view to play, this method provides [MediaPlaybackState.NONE]. + /// + ///**NOTE for iOS**: available on iOS 15.0+. + /// + ///**Supported Platforms/Implementations**: + ///- iOS ([Official API - WKWebView.requestMediaPlaybackState](https://developer.apple.com/documentation/webkit/wkwebview/3752241-requestmediaplaybackstate)). + Future requestMediaPlaybackState() async { + Map args = {}; + return MediaPlaybackState.fromValue(await _channel.invokeMethod('requestMediaPlaybackState', args)); + } } ///Use [InAppWebViewController] instead. @Deprecated("Use InAppWebViewController instead") -class IOSInAppWebViewController with IOSInAppWebViewControllerMixin { +class IOSInAppWebViewController with AppleInAppWebViewControllerMixin { late MethodChannel _channel; IOSInAppWebViewController({required MethodChannel channel}) { this._channel = channel;