This commit is contained in:
Lorenzo Pichilli 2022-04-20 19:15:31 +02:00
parent fa9a04bce6
commit 9dd5a28541
3 changed files with 61 additions and 55 deletions

View File

@ -167,8 +167,6 @@ class _InAppWebViewExampleScreenState extends State<InAppWebViewExampleScreen> {
this.url = url.toString();
urlController.text = this.url;
});
await Future.delayed(Duration(seconds: 2));
await controller.closeAllMediaPresentations();
},
onLoadError: (controller, url, code, message) {
pullToRefreshController.endRefreshing();

View File

@ -47,7 +47,7 @@ final _JAVASCRIPT_HANDLER_FORBIDDEN_NAMES = UnmodifiableListView<String>([
///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<void> pauseAllMediaPlayback() async {
Map<String, dynamic> args = <String, dynamic>{};
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<void> setAllMediaPlaybackSuspended({required bool suspended}) async {
Map<String, dynamic> args = <String, dynamic>{};
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<void> closeAllMediaPresentations() async {
Map<String, dynamic> args = <String, dynamic>{};
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 theres 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<MediaPlaybackState?> requestMediaPlaybackState() async {
Map<String, dynamic> args = <String, dynamic>{};
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<bool> canScrollVertically() async {
Map<String, dynamic> args = <String, dynamic>{};
return await _channel.invokeMethod('canScrollVertically', args);
}
///Returns `true` if the webpage can scroll horizontally, otherwise `false`.
///
///**Supported Platforms/Implementations**:
///- Android native WebView
///- iOS
Future<bool> canScrollHorizontally() async {
Map<String, dynamic> args = <String, dynamic>{};
return await _channel.invokeMethod('canScrollHorizontally', args);

View File

@ -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<String, dynamic> args = <String, dynamic>{};
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<void> pauseAllMediaPlayback() async {
Map<String, dynamic> args = <String, dynamic>{};
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<void> setAllMediaPlaybackSuspended({required bool suspended}) async {
Map<String, dynamic> args = <String, dynamic>{};
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<void> closeAllMediaPresentations() async {
Map<String, dynamic> args = <String, dynamic>{};
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 theres 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<MediaPlaybackState?> requestMediaPlaybackState() async {
Map<String, dynamic> args = <String, dynamic>{};
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;