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

Android overscroll #8451

Draft
wants to merge 4 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
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
Expand Up @@ -36,3 +36,9 @@ flutter:
- assets/sample_video.mp4
- assets/www/index.html
- assets/www/styles/style.css
# FOR TESTING AND INITIAL REVIEW ONLY. DO NOT MERGE.
# See https://github.com/flutter/flutter/blob/master/docs/ecosystem/contributing/README.md#changing-federated-plugins
dependency_overrides:
webview_flutter_android: {path: ../../../../packages/webview_flutter/webview_flutter_android}
webview_flutter_platform_interface: {path: ../../../../packages/webview_flutter/webview_flutter_platform_interface}
webview_flutter_wkwebview: {path: ../../../../packages/webview_flutter/webview_flutter_wkwebview}
Original file line number Diff line number Diff line change
Expand Up @@ -405,6 +405,11 @@ class WebViewController {
) {
return platform.setOnScrollPositionChange(onScrollPositionChange);
}

/// Sets the over-scroll mode for the WebView.
Future<void> setOverScrollMode(WebViewOverScrollMode mode) async {
return platform.setOverScrollMode(mode);
}
}

/// Permissions request when web content requests access to protected resources.
Expand Down
6 changes: 6 additions & 0 deletions packages/webview_flutter/webview_flutter/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,9 @@ topics:
- html
- webview
- webview-flutter
# FOR TESTING AND INITIAL REVIEW ONLY. DO NOT MERGE.
# See https://github.com/flutter/flutter/blob/master/docs/ecosystem/contributing/README.md#changing-federated-plugins
dependency_overrides:
webview_flutter_android: {path: ../../../packages/webview_flutter/webview_flutter_android}
webview_flutter_platform_interface: {path: ../../../packages/webview_flutter/webview_flutter_platform_interface}
webview_flutter_wkwebview: {path: ../../../packages/webview_flutter/webview_flutter_wkwebview}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright 2013 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Autogenerated from Pigeon (v22.5.0), do not edit directly.
// Autogenerated from Pigeon (v22.7.2), do not edit directly.
// See also: https://pub.dev/packages/pigeon
@file:Suppress("UNCHECKED_CAST", "ArrayInDataClass", "SyntheticAccessor")

Expand Down Expand Up @@ -571,6 +571,7 @@ private class AndroidWebkitLibraryPigeonProxyApiBaseCodec(
value is String ||
value is FileChooserMode ||
value is ConsoleMessageLevel ||
value is OverScrollMode ||
value == null) {
super.writeValue(stream, value)
return
Expand Down Expand Up @@ -726,6 +727,29 @@ enum class ConsoleMessageLevel(val raw: Int) {
}
}

/**
* The over-scroll mode for a view.
*
* See https://developer.android.com/reference/android/view/View#OVER_SCROLL_ALWAYS.
*/
enum class OverScrollMode(val raw: Int) {
/** Always allow a user to over-scroll this view, provided it is a view that can scroll. */
ALWAYS(0),
/**
* Allow a user to over-scroll this view only if the content is large enough to meaningfully
* scroll, provided it is a view that can scroll.
*/
IF_CONTENT_SCROLLS(1),
/** Never allow a user to over-scroll this view. */
NEVER(2);

companion object {
fun ofRaw(raw: Int): OverScrollMode? {
return values().firstOrNull { it.raw == raw }
}
}
}

private open class AndroidWebkitLibraryPigeonCodec : StandardMessageCodec() {
override fun readValueOfType(type: Byte, buffer: ByteBuffer): Any? {
return when (type) {
Expand All @@ -735,6 +759,9 @@ private open class AndroidWebkitLibraryPigeonCodec : StandardMessageCodec() {
130.toByte() -> {
return (readValue(buffer) as Long?)?.let { ConsoleMessageLevel.ofRaw(it.toInt()) }
}
131.toByte() -> {
return (readValue(buffer) as Long?)?.let { OverScrollMode.ofRaw(it.toInt()) }
}
else -> super.readValueOfType(type, buffer)
}
}
Expand All @@ -749,6 +776,10 @@ private open class AndroidWebkitLibraryPigeonCodec : StandardMessageCodec() {
stream.write(130)
writeValue(stream, value.raw)
}
is OverScrollMode -> {
stream.write(131)
writeValue(stream, value.raw)
}
else -> super.writeValue(stream, value)
}
}
Expand Down Expand Up @@ -4451,6 +4482,9 @@ abstract class PigeonApiView(
/** Return the scrolled position of this view. */
abstract fun getScrollPosition(pigeon_instance: android.view.View): WebViewPoint

/** Set the over-scroll mode for this view. */
abstract fun setOverScrollMode(pigeon_instance: android.view.View, mode: OverScrollMode)

companion object {
@Suppress("LocalVariableName")
fun setUpMessageHandlers(binaryMessenger: BinaryMessenger, api: PigeonApiView?) {
Expand Down Expand Up @@ -4523,6 +4557,30 @@ abstract class PigeonApiView(
channel.setMessageHandler(null)
}
}
run {
val channel =
BasicMessageChannel<Any?>(
binaryMessenger,
"dev.flutter.pigeon.webview_flutter_android.View.setOverScrollMode",
codec)
if (api != null) {
channel.setMessageHandler { message, reply ->
val args = message as List<Any?>
val pigeon_instanceArg = args[0] as android.view.View
val modeArg = args[1] as OverScrollMode
val wrapped: List<Any?> =
try {
api.setOverScrollMode(pigeon_instanceArg, modeArg)
listOf(null)
} catch (exception: Throwable) {
wrapError(exception)
}
reply.reply(wrapped)
}
} else {
channel.setMessageHandler(null)
}
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,19 @@ public void scrollBy(@NonNull View pigeon_instance, long x, long y) {
public WebViewPoint getScrollPosition(@NonNull View pigeon_instance) {
return new WebViewPoint(pigeon_instance.getScrollX(), pigeon_instance.getScrollY());
}

@Override
public void setOverScrollMode(@NonNull View pigeon_instance, @NonNull OverScrollMode mode) {
switch (mode) {
case ALWAYS:
pigeon_instance.setOverScrollMode(View.OVER_SCROLL_ALWAYS);
break;
case IF_CONTENT_SCROLLS:
pigeon_instance.setOverScrollMode(View.OVER_SCROLL_IF_CONTENT_SCROLLS);
break;
case NEVER:
pigeon_instance.setOverScrollMode(View.OVER_SCROLL_NEVER);
break;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,15 @@ public void getScrollPosition() {
assertEquals(value.getX(), api.getScrollPosition(instance).getX());
assertEquals(value.getY(), api.getScrollPosition(instance).getY());
}

@Test
public void setOverScrollMode() {
final PigeonApiView api = new TestProxyApiRegistrar().getPigeonApiView();

final View instance = mock(View.class);
final OverScrollMode mode = io.flutter.plugins.webviewflutter.OverScrollMode.ALWAYS;
api.setOverScrollMode(instance, mode);

verify(instance).setOverScrollMode(View.OVER_SCROLL_ALWAYS);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,7 @@ flutter:
- assets/sample_video.mp4
- assets/www/index.html
- assets/www/styles/style.css
# FOR TESTING AND INITIAL REVIEW ONLY. DO NOT MERGE.
# See https://github.com/flutter/flutter/blob/master/docs/ecosystem/contributing/README.md#changing-federated-plugins
dependency_overrides:
webview_flutter_platform_interface: {path: ../../../../packages/webview_flutter/webview_flutter_platform_interface}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright 2013 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Autogenerated from Pigeon (v22.5.0), do not edit directly.
// Autogenerated from Pigeon (v22.7.2), do not edit directly.
// See also: https://pub.dev/packages/pigeon
// ignore_for_file: public_member_api_docs, non_constant_identifier_names, avoid_as, unused_import, unnecessary_parenthesis, prefer_null_aware_operators, omit_local_variable_types, unused_shown_name, unnecessary_import, no_leading_underscores_for_local_identifiers

Expand Down Expand Up @@ -53,7 +53,6 @@ abstract class PigeonInternalProxyApiBaseClass {
final BinaryMessenger? pigeon_binaryMessenger;

/// Maintains instances stored to communicate with native language objects.
@protected
final PigeonInstanceManager pigeon_instanceManager;

/// Instantiates and returns a functionally identical object to oneself.
Expand Down Expand Up @@ -503,6 +502,22 @@ enum ConsoleMessageLevel {
unknown,
}

/// The over-scroll mode for a view.
///
/// See https://developer.android.com/reference/android/view/View#OVER_SCROLL_ALWAYS.
enum OverScrollMode {
/// Always allow a user to over-scroll this view, provided it is a view that
/// can scroll.
always,

/// Allow a user to over-scroll this view only if the content is large enough
/// to meaningfully scroll, provided it is a view that can scroll.
ifContentScrolls,

/// Never allow a user to over-scroll this view.
never,
}

class _PigeonCodec extends StandardMessageCodec {
const _PigeonCodec();
@override
Expand All @@ -516,6 +531,9 @@ class _PigeonCodec extends StandardMessageCodec {
} else if (value is ConsoleMessageLevel) {
buffer.putUint8(130);
writeValue(buffer, value.index);
} else if (value is OverScrollMode) {
buffer.putUint8(131);
writeValue(buffer, value.index);
} else {
super.writeValue(buffer, value);
}
Expand All @@ -530,6 +548,9 @@ class _PigeonCodec extends StandardMessageCodec {
case 130:
final int? value = readValue(buffer) as int?;
return value == null ? null : ConsoleMessageLevel.values[value];
case 131:
final int? value = readValue(buffer) as int?;
return value == null ? null : OverScrollMode.values[value];
default:
return super.readValueOfType(type, buffer);
}
Expand Down Expand Up @@ -5918,6 +5939,34 @@ class View extends PigeonInternalProxyApiBaseClass {
}
}

/// Set the over-scroll mode for this view.
Future<void> setOverScrollMode(OverScrollMode mode) async {
final _PigeonInternalProxyApiBaseCodec pigeonChannelCodec =
_pigeonVar_codecView;
final BinaryMessenger? pigeonVar_binaryMessenger = pigeon_binaryMessenger;
const String pigeonVar_channelName =
'dev.flutter.pigeon.webview_flutter_android.View.setOverScrollMode';
final BasicMessageChannel<Object?> pigeonVar_channel =
BasicMessageChannel<Object?>(
pigeonVar_channelName,
pigeonChannelCodec,
binaryMessenger: pigeonVar_binaryMessenger,
);
final List<Object?>? pigeonVar_replyList =
await pigeonVar_channel.send(<Object?>[this, mode]) as List<Object?>?;
if (pigeonVar_replyList == null) {
throw _createConnectionError(pigeonVar_channelName);
} else if (pigeonVar_replyList.length > 1) {
throw PlatformException(
code: pigeonVar_replyList[0]! as String,
message: pigeonVar_replyList[1] as String?,
details: pigeonVar_replyList[2],
);
} else {
return;
}
}

@override
View pigeon_copy() {
return View.pigeon_detached(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -731,6 +731,28 @@ class AndroidWebViewController extends PlatformWebViewController {
_onJavaScriptPrompt = onJavaScriptTextInputDialog;
return _webChromeClient.setSynchronousReturnValueForOnJsPrompt(true);
}

@override
Future<void> setOverScrollMode(WebViewOverScrollMode mode) async {
switch (mode) {
case WebViewOverScrollMode.always:
return _webView.setOverScrollMode(
android_webview.OverScrollMode.always,
);
case WebViewOverScrollMode.ifContentScrolls:
return _webView.setOverScrollMode(
android_webview.OverScrollMode.ifContentScrolls,
);
case WebViewOverScrollMode.never:
return _webView.setOverScrollMode(
android_webview.OverScrollMode.never,
);
// This prevents future additions from causing a breaking change.
// ignore: unreachable_switch_case
case _:
throw UnsupportedError('Android does not support $mode.');
}
}
}

/// Android implementation of [PlatformWebViewPermissionRequest].
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,22 @@ enum ConsoleMessageLevel {
unknown,
}

/// The over-scroll mode for a view.
///
/// See https://developer.android.com/reference/android/view/View#OVER_SCROLL_ALWAYS.
enum OverScrollMode {
/// Always allow a user to over-scroll this view, provided it is a view that
/// can scroll.
always,

/// Allow a user to over-scroll this view only if the content is large enough
/// to meaningfully scroll, provided it is a view that can scroll.
ifContentScrolls,

/// Never allow a user to over-scroll this view.
never,
}

/// Encompasses parameters to the `WebViewClient.shouldInterceptRequest` method.
///
/// See https://developer.android.com/reference/android/webkit/WebResourceRequest.
Expand Down Expand Up @@ -763,6 +779,9 @@ abstract class View {

/// Return the scrolled position of this view.
WebViewPoint getScrollPosition();

/// Set the over-scroll mode for this view.
void setOverScrollMode(OverScrollMode mode);
}

/// A callback interface used by the host application to set the Geolocation
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,13 @@ dev_dependencies:
flutter_test:
sdk: flutter
mockito: ^5.4.4
pigeon: ^22.5.0
pigeon: ^22.7.2

topics:
- html
- webview
- webview-flutter
# FOR TESTING AND INITIAL REVIEW ONLY. DO NOT MERGE.
# See https://github.com/flutter/flutter/blob/master/docs/ecosystem/contributing/README.md#changing-federated-plugins
dependency_overrides:
webview_flutter_platform_interface: {path: ../../../packages/webview_flutter/webview_flutter_platform_interface}
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,13 @@ abstract class PlatformWebViewController extends PlatformInterface {
'setOnJavaScriptTextInputDialog is not implemented on the current platform',
);
}

/// Sets the over-scroll mode for the WebView.
Future<void> setOverScrollMode(WebViewOverScrollMode mode) async {
throw UnimplementedError(
'setOverScrollMode is not implemented on the current platform',
);
}
}

/// Describes the parameters necessary for registering a JavaScript channel.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// Copyright 2013 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

/// Defines the over-scroll behavior of a WebView.
enum WebViewOverScrollMode {
/// Always allow a user to over-scroll the WebView.
always,

/// Allow a user to over-scroll the WebView only if the content is large
/// enough to meaningfully scroll.
ifContentScrolls,

/// Never allow a user to over-scroll the WebView.
never,
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ export 'javascript_mode.dart';
export 'load_request_params.dart';
export 'navigation_decision.dart';
export 'navigation_request.dart';
export 'over_scroll_mode.dart';
export 'platform_navigation_delegate_creation_params.dart';
export 'platform_webview_controller_creation_params.dart';
export 'platform_webview_cookie_manager_creation_params.dart';
Expand Down
Loading