Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[webview_flutter_android] Added the functionality to fullscreen html5 video #3879

Merged
merged 64 commits into from
Sep 8, 2023
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
Show all changes
64 commits
Select commit Hold shift + click to select a range
1bbd61f
Added fullscreen capabilities to the android webview
paulppn May 2, 2023
279a678
Fixed the formatting
paulppn May 2, 2023
6649aa8
Fixed some more formatting + added a nonnull
paulppn May 2, 2023
fbc3f57
Removed empty line
paulppn May 2, 2023
06935c9
Adjusted another nonnull
paulppn May 2, 2023
ff9137f
Fixed two lint warnings
paulppn May 2, 2023
bef6c2a
customviewcallback dart impl
bparrishMines May 30, 2023
0cd62d0
view dart impl
bparrishMines May 30, 2023
6ca452a
Merge branch 'main' of github.com:flutter/packages into feature/add_f…
bparrishMines May 30, 2023
ba03b6b
formatting
bparrishMines May 30, 2023
9f0dbe1
dart side of webchromeclient wrap
bparrishMines May 30, 2023
e9295b2
implement java side
bparrishMines May 30, 2023
d547039
fix java side
bparrishMines May 31, 2023
59a0da4
formatting
bparrishMines May 31, 2023
f3693b8
fix pubspec
bparrishMines May 31, 2023
47c7d98
Merge branch 'main' of github.com:flutter/packages into feature/add_f…
bparrishMines May 31, 2023
8151750
remove unneeded lines
bparrishMines May 31, 2023
759f19b
remove unneeded mocks
bparrishMines May 31, 2023
bdb0806
fix lint
bparrishMines May 31, 2023
47e3108
Merge remote-tracking branch 'origin/main' into feature/add_fullscree…
mvanbeusekom Jul 5, 2023
5ea042d
Adds Dart implementation fullscreen video
mvanbeusekom Jul 5, 2023
216757e
Adds Android fullscreen functionality
mvanbeusekom Jul 6, 2023
4ff9e75
Merge branch 'main' into feature/add_fullscreen_video
mvanbeusekom Jul 6, 2023
76c02cc
Merge remote-tracking branch 'origin/main' into feature/add_fullscree…
mvanbeusekom Jul 7, 2023
b899cb0
Merge branch 'feature/add_fullscreen_video' of github.com:paulppn/flu…
mvanbeusekom Jul 7, 2023
24bc43e
Merge remote-tracking branch 'origin/main' into feature/add_fullscree…
mvanbeusekom Jul 11, 2023
afe0b8f
Apply review feedback
mvanbeusekom Jul 11, 2023
e9d418a
Merge branch 'main' into feature/add_fullscreen_video
mvanbeusekom Jul 11, 2023
e347a49
Merge branch 'main' into feature/add_fullscreen_video
mvanbeusekom Jul 12, 2023
ab876f2
Applied PR feedback
mvanbeusekom Jul 12, 2023
9323791
Merge branch 'feature/add_fullscreen_video' of github.com:paulppn/flu…
mvanbeusekom Jul 12, 2023
4cb8746
Merge branch 'main' into feature/add_fullscreen_video
mvanbeusekom Jul 12, 2023
8baca49
Merge branch 'main' into feature/add_fullscreen_video
mvanbeusekom Jul 12, 2023
f385bcc
Merge branch 'main' into feature/add_fullscreen_video
mvanbeusekom Jul 13, 2023
178c5e7
Merge branch 'main' into feature/add_fullscreen_video
mvanbeusekom Jul 19, 2023
37edbf1
Merge remote-tracking branch 'upstream/main' into feature/add_fullscr…
mvanbeusekom Aug 2, 2023
7219770
Merge branch 'feature/add_fullscreen_video' of github.com:paulppn/flu…
mvanbeusekom Aug 2, 2023
c612ef5
Adds integration test to validate fullscreen
mvanbeusekom Aug 3, 2023
9d06cae
Merge branch 'main' into feature/add_fullscreen_video
mvanbeusekom Aug 3, 2023
041441d
Ensure the CustomViewHostApi is setup correctly
mvanbeusekom Aug 3, 2023
d4359d5
Merge branch 'feature/add_fullscreen_video' of github.com:paulppn/flu…
mvanbeusekom Aug 3, 2023
5169000
Merge branch 'main' into feature/add_fullscreen_video
mvanbeusekom Aug 3, 2023
87443f5
Merge remote-tracking branch 'upstream/main' into feature/add_fullscr…
mvanbeusekom Aug 10, 2023
1f1ee82
Merge branch 'main' of https://github.com/flutter/packages into featu…
mvanbeusekom Aug 11, 2023
5ef97bc
Remove obsolete file
mvanbeusekom Aug 11, 2023
ba39519
Merge branch 'main' into feature/add_fullscreen_video
mvanbeusekom Aug 11, 2023
269ad02
Merge branch 'feature/add_fullscreen_video' of github.com:paulppn/flu…
mvanbeusekom Aug 11, 2023
6347f98
Fixed analysis warning
mvanbeusekom Aug 11, 2023
b319604
Formatted JAVA files
mvanbeusekom Aug 14, 2023
aa35251
Merge remote-tracking branch 'upstream/main' into feature/add_fullscr…
mvanbeusekom Aug 15, 2023
d9f9812
Merge branch 'main' of https://github.com/flutter/packages into featu…
mvanbeusekom Aug 17, 2023
3e39dd2
Explain the tapAt statement in integration test
mvanbeusekom Aug 17, 2023
3e74540
Update packages/webview_flutter/webview_flutter_android/example/integ…
bparrishMines Aug 18, 2023
289cccd
update dartdocs and changelog
bparrishMines Aug 18, 2023
1e63109
Merge branch 'main' of github.com:flutter/packages into feature/add_f…
bparrishMines Aug 18, 2023
5d45ea0
provide example for fullscreen
bparrishMines Aug 18, 2023
6ca8d15
require callbacks
bparrishMines Aug 18, 2023
0b7361a
formatting
bparrishMines Aug 21, 2023
cdcff55
Merge branch 'main' of github.com:flutter/packages into feature/add_f…
bparrishMines Aug 21, 2023
45720e4
add a default handler
bparrishMines Aug 25, 2023
67d660d
Merge branch 'main' of github.com:flutter/packages into feature/add_f…
bparrishMines Aug 25, 2023
acfd11d
add integration test
bparrishMines Aug 25, 2023
7744529
switch to unit test
bparrishMines Sep 7, 2023
1a65e0f
Merge branch 'main' of github.com:flutter/packages into feature/add_f…
bparrishMines Sep 7, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
## 3.10.0

* Adds support for playing video in fullscreen.
* Adds support for playing video in fullscreen. See
`AndroidWebViewController.setCustomWidgetCallbacks`.
* Updates minimum supported SDK version to Flutter 3.7/Dart 2.19.

## 3.9.3

Expand Down
23 changes: 22 additions & 1 deletion packages/webview_flutter/webview_flutter_android/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ This can be configured for versions >=23 with
`AndroidWebViewWidgetCreationParams.displayWithHybridComposition`. See https://pub.dev/packages/webview_flutter#platform-specific-features
for more details on setting platform-specific features in the main plugin.

### External Native API
## External Native API
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wasn't this correct before? This section seems to be Android-only as written.


The plugin also provides a native API accessible by the native code of Android applications or
packages. This API follows the convention of breaking changes of the Dart API, which means that any
Expand All @@ -52,6 +52,27 @@ Java:
import io.flutter.plugins.webviewflutter.WebViewFlutterAndroidExternalApi;
```

## Fullscreen Video

To display a video as fullscreen, an app must manually handle the notification that the current page
has entered fullscreen mode. This can be done by calling
`AndroidWebViewController.setCustomWidgetCallbacks`. Below is an example implementation.

<?code-excerpt "example/lib/main.dart (fullscreen_example)"?>
```dart
androidController.setCustomWidgetCallbacks(
onShowCustomWidget: (Widget widget, OnHideCustomWidgetCallback callback) {
Navigator.of(context).push(MaterialPageRoute<void>(
builder: (BuildContext context) => widget,
fullscreenDialog: true,
));
},
onHideCustomWidget: () {
Navigator.of(context).pop();
},
);
```

## Contributing

This package uses [pigeon][3] to generate the communication layer between Flutter and the host
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -581,6 +581,13 @@ Future<void> main() async {

await tester.pumpAndSettle();

// Due to security reasons, Chrome doesn't allow to programmatically
// toggle a video to fullscreen unless the call is directly comming from
// a user triggered event.
// The top half of the loaded web content contains a clickable div, which
// is tapped using the code below, triggering a user event.
//
// The offset of 20 x 20 is chosen at random.
await tester.tapAt(const Offset(20, 20));
stuartmorgan marked this conversation as resolved.
Show resolved Hide resolved

await expectLater(fullscreenEntered.future, completes);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -423,6 +423,7 @@ class SampleMenu extends StatelessWidget {
Future<void> _onVideoExample(BuildContext context) {
final AndroidWebViewController androidController =
webViewController as AndroidWebViewController;
// #docregion fullscreen_example
androidController.setCustomWidgetCallbacks(
onShowCustomWidget: (Widget widget, OnHideCustomWidgetCallback callback) {
Navigator.of(context).push(MaterialPageRoute<void>(
Expand All @@ -434,6 +435,7 @@ class SampleMenu extends StatelessWidget {
Navigator.of(context).pop();
},
);
// #enddocregion fullscreen_example

return androidController.loadRequest(
LoadRequestParams(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -538,21 +538,28 @@ class AndroidWebViewController extends PlatformWebViewController {
}

/// Sets the callbacks that are invoked when the host application wants to
/// show or hide a custom view.
/// show or hide a custom widget.
///
/// The most common use case these methods are invoked a video element wants
/// to be displayed in fullscreen.
///
/// The [onShowCustomWidget] notifies the host application that web content
/// from the specified origin wants to be displayed in a custom view. After
/// this call, web content will no longer be rendered in the WebViewWidget,
/// but will instead be rendered in the custom widget.
/// from the specified origin wants to be displayed in a custom widget. After
/// this call, web content will no longer be rendered in the `WebViewWidget`,
/// but will instead be rendered in the custom widget. The application may
/// explicitly exit fullscreen mode by invoking `onCustomWidgetHidden` in the
/// [onShowCustomWidget] callback (ex. when the user presses the back
/// button). However, this is generally not necessary as the web page will
/// often show its own UI to close out of fullscreen. Regardless of how the
/// WebView exits fullscreen mode, WebView will invoke [onHideCustomWidget],
/// signaling for the application to remove the custom widget.
///
/// The [onHideCustomWidget] notifies the host application that the custom
/// view should be hidden.
/// widget must be hidden. After this call, web content will render in the
/// original `WebViewWidget` again.
Future<void> setCustomWidgetCallbacks({
OnShowCustomWidgetCallback? onShowCustomWidget,
OnHideCustomWidgetCallback? onHideCustomWidget,
required OnShowCustomWidgetCallback? onShowCustomWidget,
required OnHideCustomWidgetCallback? onHideCustomWidget,
}) async {
_onShowCustomWidgetCallback = onShowCustomWidget;
_onHideCustomWidgetCallback = onHideCustomWidget;
Expand Down