Skip to content

[webview_flutter] Add verticalScrollBarEnabled function #8174

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

Closed
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 @@ -405,6 +405,16 @@ class WebViewController {
) {
return platform.setOnScrollPositionChange(onScrollPositionChange);
}

/// Define whether the vertical scrollbar should be drawn or not. The default value is true.
Future<void> verticalScrollBarEnabled(bool enabled) {
return platform.verticalScrollBarEnabled(enabled);
}

/// Define whether the horizontal scrollbar should be drawn or not. The default value is true.
Future<void> horizontalScrollBarEnabled(bool enabled) {
return platform.horizontalScrollBarEnabled(enabled);
}
}

/// Permissions request when web content requests access to protected resources.
Expand Down
9 changes: 6 additions & 3 deletions packages/webview_flutter/webview_flutter/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,12 @@ flutter:
dependencies:
flutter:
sdk: flutter
webview_flutter_android: ^4.0.0
webview_flutter_platform_interface: ^2.10.0
webview_flutter_wkwebview: ^3.15.0
webview_flutter_android:
path: ../webview_flutter_android
webview_flutter_platform_interface:
path: ../webview_flutter_platform_interface
webview_flutter_wkwebview:
path: ../webview_flutter_wkwebview

dev_dependencies:
build_runner: ^2.1.5
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,30 @@ void main() {
verify(mockPlatformWebViewController.scrollBy(2, 3));
});

test('verticalScrollBarEnabled', () async {
final MockPlatformWebViewController mockPlatformWebViewController =
MockPlatformWebViewController();

final WebViewController webViewController = WebViewController.fromPlatform(
mockPlatformWebViewController,
);

await webViewController.verticalScrollBarEnabled(false);
verify(mockPlatformWebViewController.verticalScrollBarEnabled(false));
});

test('horizontalScrollBarEnabled', () async {
final MockPlatformWebViewController mockPlatformWebViewController =
MockPlatformWebViewController();

final WebViewController webViewController = WebViewController.fromPlatform(
mockPlatformWebViewController,
);

await webViewController.horizontalScrollBarEnabled(false);
verify(mockPlatformWebViewController.horizontalScrollBarEnabled(false));
});

test('getScrollPosition', () async {
final MockPlatformWebViewController mockPlatformWebViewController =
MockPlatformWebViewController();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,28 @@ class MockPlatformWebViewController extends _i1.Mock
returnValueForMissingStub: _i5.Future<void>.value(),
) as _i5.Future<void>);

@override
_i5.Future<void> verticalScrollBarEnabled(bool? enabled) =>
(super.noSuchMethod(
Invocation.method(
#verticalScrollBarEnabled,
[enabled],
),
returnValue: _i5.Future<void>.value(),
returnValueForMissingStub: _i5.Future<void>.value(),
) as _i5.Future<void>);

@override
_i5.Future<void> horizontalScrollBarEnabled(bool? enabled) =>
(super.noSuchMethod(
Invocation.method(
#horizontalScrollBarEnabled,
[enabled],
),
returnValue: _i5.Future<void>.value(),
returnValueForMissingStub: _i5.Future<void>.value(),
) as _i5.Future<void>);

@override
_i5.Future<_i3.Offset> getScrollPosition() => (super.noSuchMethod(
Invocation.method(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,28 @@ class MockPlatformWebViewController extends _i1.Mock
returnValueForMissingStub: _i7.Future<void>.value(),
) as _i7.Future<void>);

@override
_i7.Future<void> verticalScrollBarEnabled(bool? enabled) =>
(super.noSuchMethod(
Invocation.method(
#verticalScrollBarEnabled,
[enabled],
),
returnValue: _i7.Future<void>.value(),
returnValueForMissingStub: _i7.Future<void>.value(),
) as _i7.Future<void>);

@override
_i7.Future<void> horizontalScrollBarEnabled(bool? enabled) =>
(super.noSuchMethod(
Invocation.method(
#horizontalScrollBarEnabled,
[enabled],
),
returnValue: _i7.Future<void>.value(),
returnValueForMissingStub: _i7.Future<void>.value(),
) as _i7.Future<void>);

@override
_i7.Future<_i3.Offset> getScrollPosition() => (super.noSuchMethod(
Invocation.method(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1387,6 +1387,12 @@ abstract class PigeonApiWebView(
/** Sets the background color for this view. */
abstract fun setBackgroundColor(pigeon_instance: android.webkit.WebView, color: Long)

/** Define whether the vertical scrollbar should be drawn or not. The default value is true. */
abstract fun verticalScrollBarEnabled(pigeon_instance: android.webkit.WebView, enabled: Boolean)

/** Define whether the horizontal scrollbar should be drawn or not. The default value is true. */
abstract fun horizontalScrollBarEnabled(pigeon_instance: android.webkit.WebView, enabled: Boolean)

/** Destroys the internal state of this WebView. */
abstract fun destroy(pigeon_instance: android.webkit.WebView)

Expand Down Expand Up @@ -1924,6 +1930,54 @@ abstract class PigeonApiWebView(
channel.setMessageHandler(null)
}
}
run {
val channel =
BasicMessageChannel<Any?>(
binaryMessenger,
"dev.flutter.pigeon.webview_flutter_android.WebView.verticalScrollBarEnabled",
codec)
if (api != null) {
channel.setMessageHandler { message, reply ->
val args = message as List<Any?>
val pigeon_instanceArg = args[0] as android.webkit.WebView
val enabledArg = args[1] as Boolean
val wrapped: List<Any?> =
try {
api.verticalScrollBarEnabled(pigeon_instanceArg, enabledArg)
listOf(null)
} catch (exception: Throwable) {
wrapError(exception)
}
reply.reply(wrapped)
}
} else {
channel.setMessageHandler(null)
}
}
run {
val channel =
BasicMessageChannel<Any?>(
binaryMessenger,
"dev.flutter.pigeon.webview_flutter_android.WebView.horizontalScrollBarEnabled",
codec)
if (api != null) {
channel.setMessageHandler { message, reply ->
val args = message as List<Any?>
val pigeon_instanceArg = args[0] as android.webkit.WebView
val enabledArg = args[1] as Boolean
val wrapped: List<Any?> =
try {
api.horizontalScrollBarEnabled(pigeon_instanceArg, enabledArg)
listOf(null)
} catch (exception: Throwable) {
wrapError(exception)
}
reply.reply(wrapped)
}
} else {
channel.setMessageHandler(null)
}
}
run {
val channel =
BasicMessageChannel<Any?>(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,16 @@ public void setBackgroundColor(@NonNull WebView pigeon_instance, long color) {
pigeon_instance.setBackgroundColor((int) color);
}

@Override
public void verticalScrollBarEnabled(@NonNull WebView pigeon_instance, boolean enabled) {
pigeon_instance.setVerticalScrollBarEnabled(enabled);
}

@Override
public void horizontalScrollBarEnabled(@NonNull WebView pigeon_instance, boolean enabled) {
pigeon_instance.setHorizontalScrollBarEnabled(enabled);
}

@NonNull
@Override
public ProxyApiRegistrar getPigeonRegistrar() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2170,6 +2170,62 @@ class WebView extends View {
}
}

/// Define whether the vertical scrollbar should be drawn or not. The default value is true.
Future<void> verticalScrollBarEnabled(bool enabled) async {
final _PigeonInternalProxyApiBaseCodec pigeonChannelCodec =
_pigeonVar_codecWebView;
final BinaryMessenger? pigeonVar_binaryMessenger = pigeon_binaryMessenger;
const String pigeonVar_channelName =
'dev.flutter.pigeon.webview_flutter_android.WebView.verticalScrollBarEnabled';
final BasicMessageChannel<Object?> pigeonVar_channel =
BasicMessageChannel<Object?>(
pigeonVar_channelName,
pigeonChannelCodec,
binaryMessenger: pigeonVar_binaryMessenger,
);
final List<Object?>? pigeonVar_replyList = await pigeonVar_channel
.send(<Object?>[this, enabled]) 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;
}
}

/// Define whether the horizontal scrollbar should be drawn or not. The default value is true.
Future<void> horizontalScrollBarEnabled(bool enabled) async {
final _PigeonInternalProxyApiBaseCodec pigeonChannelCodec =
_pigeonVar_codecWebView;
final BinaryMessenger? pigeonVar_binaryMessenger = pigeon_binaryMessenger;
const String pigeonVar_channelName =
'dev.flutter.pigeon.webview_flutter_android.WebView.horizontalScrollBarEnabled';
final BasicMessageChannel<Object?> pigeonVar_channel =
BasicMessageChannel<Object?>(
pigeonVar_channelName,
pigeonChannelCodec,
binaryMessenger: pigeonVar_binaryMessenger,
);
final List<Object?>? pigeonVar_replyList = await pigeonVar_channel
.send(<Object?>[this, enabled]) 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;
}
}

/// Destroys the internal state of this WebView.
Future<void> destroy() async {
final _PigeonInternalProxyApiBaseCodec pigeonChannelCodec =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -712,6 +712,14 @@ class AndroidWebViewController extends PlatformWebViewController {
_onJavaScriptPrompt = onJavaScriptTextInputDialog;
return _webChromeClient.setSynchronousReturnValueForOnJsPrompt(true);
}

@override
Future<void> verticalScrollBarEnabled(bool enabled) =>
_webView.verticalScrollBarEnabled(enabled);

@override
Future<void> horizontalScrollBarEnabled(bool enabled) =>
_webView.horizontalScrollBarEnabled(enabled);
}

/// Android implementation of [PlatformWebViewPermissionRequest].
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ flutter:
dependencies:
flutter:
sdk: flutter
webview_flutter_platform_interface: ^2.10.0
webview_flutter_platform_interface:
path: ../webview_flutter_platform_interface

dev_dependencies:
build_runner: ^2.1.4
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1401,6 +1401,28 @@ void main() {
verify(mockWebView.scrollBy(4, 2)).called(1);
});

test('verticalScrollBarEnabled', () async {
final MockWebView mockWebView = MockWebView();
final AndroidWebViewController controller = createControllerWithMocks(
mockWebView: mockWebView,
);

await controller.verticalScrollBarEnabled(false);

verify(mockWebView.verticalScrollBarEnabled(false)).called(1);
});

test('horizontalScrollBarEnabled', () async {
final MockWebView mockWebView = MockWebView();
final AndroidWebViewController controller = createControllerWithMocks(
mockWebView: mockWebView,
);

await controller.horizontalScrollBarEnabled(false);

verify(mockWebView.horizontalScrollBarEnabled(false)).called(1);
});

test('getScrollPosition', () async {
final MockWebView mockWebView = MockWebView();
final AndroidWebViewController controller = createControllerWithMocks(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -911,6 +911,28 @@ class MockAndroidWebViewController extends _i1.Mock
returnValue: _i8.Future<void>.value(),
returnValueForMissingStub: _i8.Future<void>.value(),
) as _i8.Future<void>);

@override
_i8.Future<void> verticalScrollBarEnabled(bool? enabled) =>
(super.noSuchMethod(
Invocation.method(
#verticalScrollBarEnabled,
[enabled],
),
returnValue: _i8.Future<void>.value(),
returnValueForMissingStub: _i8.Future<void>.value(),
) as _i8.Future<void>);

@override
_i8.Future<void> horizontalScrollBarEnabled(bool? enabled) =>
(super.noSuchMethod(
Invocation.method(
#horizontalScrollBarEnabled,
[enabled],
),
returnValue: _i8.Future<void>.value(),
returnValueForMissingStub: _i8.Future<void>.value(),
) as _i8.Future<void>);
}

/// A class which mocks [AndroidWebViewProxy].
Expand Down Expand Up @@ -2977,6 +2999,28 @@ class MockWebView extends _i1.Mock implements _i2.WebView {
returnValueForMissingStub: _i8.Future<void>.value(),
) as _i8.Future<void>);

@override
_i8.Future<void> verticalScrollBarEnabled(bool? enabled) =>
(super.noSuchMethod(
Invocation.method(
#verticalScrollBarEnabled,
[enabled],
),
returnValue: _i8.Future<void>.value(),
returnValueForMissingStub: _i8.Future<void>.value(),
) as _i8.Future<void>);

@override
_i8.Future<void> horizontalScrollBarEnabled(bool? enabled) =>
(super.noSuchMethod(
Invocation.method(
#horizontalScrollBarEnabled,
[enabled],
),
returnValue: _i8.Future<void>.value(),
returnValueForMissingStub: _i8.Future<void>.value(),
) as _i8.Future<void>);

@override
_i8.Future<void> destroy() => (super.noSuchMethod(
Invocation.method(
Expand Down
Loading