-
Notifications
You must be signed in to change notification settings - Fork 9.7k
[webview_flutter_wkwebview] Add WKWebView method stubs #4990
Changes from 2 commits
6b12960
e4b8627
cf7a649
4c89654
b3bb74a
ef61349
c0a4158
6af4ff5
7e80f31
99605b3
e551f2b
427af47
a4c7359
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| // 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. | ||
|
|
||
| import 'dart:async'; | ||
| import 'dart:math'; | ||
|
|
||
| import '../web_kit/web_kit.dart'; | ||
|
|
||
| /// A view that allows the scrolling and zooming of its contained views. | ||
| /// | ||
| /// Wraps [UIScrollView](https://developer.apple.com/documentation/uikit/uiscrollview?language=objc). | ||
| class UIScrollView { | ||
| /// Constructs a [UIScrollView] that is owned by [webView]. | ||
| // TODO(bparrishMines): Remove ignore once constructor is implemented. | ||
| // ignore: avoid_unused_constructor_parameters | ||
| UIScrollView.fromWebView(WKWebView webView); | ||
|
|
||
| /// Point at which the origin of the content view is offset from the origin of the scroll view. | ||
| Future<Point<double>> get contentOffset { | ||
| throw UnimplementedError(); | ||
| } | ||
|
|
||
| /// Set point at which the origin of the content view is offset from the origin of the scroll view. | ||
| /// | ||
| /// The default value is `Point<double>(0.0, 0.0)`. | ||
| set contentOffset(FutureOr<Point<double>> offset) { | ||
| throw UnimplementedError(); | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,11 +3,14 @@ | |
| // found in the LICENSE file. | ||
|
|
||
| import 'dart:async'; | ||
| import 'dart:math'; | ||
|
|
||
| import 'package:flutter/foundation.dart'; | ||
| import 'package:flutter/widgets.dart'; | ||
| import 'package:path/path.dart' as path; | ||
| import 'package:webview_flutter_platform_interface/webview_flutter_platform_interface.dart'; | ||
|
|
||
| import 'foundation/foundation.dart'; | ||
| import 'web_kit/web_kit.dart'; | ||
|
|
||
| /// A [Widget] that displays a [WKWebView]. | ||
|
|
@@ -161,6 +164,112 @@ class WebKitWebViewPlatformController extends WebViewPlatformController { | |
| }; | ||
| } | ||
|
|
||
| @override | ||
| Future<void> loadHtmlString(String html, {String? baseUrl}) { | ||
| return webView.loadHtmlString(html, baseUrl); | ||
| } | ||
|
|
||
| @override | ||
| Future<void> loadFile(String absoluteFilePath) async { | ||
| await webView.loadFileUrl( | ||
| absoluteFilePath, | ||
| path.dirname(absoluteFilePath), | ||
stuartmorgan-g marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| ); | ||
| } | ||
|
|
||
| @override | ||
| Future<void> loadFlutterAsset(String key) async { | ||
| assert(key.isNotEmpty); | ||
| return webView.loadFlutterAsset(key); | ||
| } | ||
|
|
||
| @override | ||
| Future<void> loadUrl(String url, Map<String, String>? headers) async { | ||
| final NSUrlRequest request = NSUrlRequest( | ||
| url: url, | ||
| allHttpHeaderFields: headers ?? <String, String>{}, | ||
| ); | ||
| return webView.loadRequest(request); | ||
| } | ||
|
|
||
| @override | ||
| Future<void> loadRequest(WebViewRequest request) async { | ||
| if (!request.uri.hasScheme) { | ||
| throw ArgumentError('WebViewRequest#uri is required to have a scheme.'); | ||
| } | ||
|
|
||
| final NSUrlRequest urlRequest = NSUrlRequest( | ||
| url: request.uri.toString(), | ||
| allHttpHeaderFields: request.headers, | ||
| httpMethod: describeEnum(request.method), | ||
| httpBody: request.body, | ||
| ); | ||
|
|
||
| return webView.loadRequest(urlRequest); | ||
| } | ||
|
|
||
| @override | ||
| Future<bool> canGoBack() => webView.canGoBack; | ||
|
|
||
| @override | ||
| Future<bool> canGoForward() => webView.canGoForward; | ||
|
|
||
| @override | ||
| Future<void> goBack() => webView.goBack(); | ||
|
|
||
| @override | ||
| Future<void> goForward() => webView.goForward(); | ||
|
|
||
| @override | ||
| Future<void> reload() => webView.reload(); | ||
|
|
||
| @override | ||
| Future<String> evaluateJavascript(String javascript) async { | ||
| return runJavascriptReturningResult(javascript); | ||
|
||
| } | ||
|
|
||
| @override | ||
| Future<void> runJavascript(String javascript) async { | ||
| await webView.evaluateJavaScript(javascript); | ||
|
||
| } | ||
|
|
||
| @override | ||
| Future<String> runJavascriptReturningResult(String javascript) async { | ||
| return await webView.evaluateJavaScript(javascript) ?? ''; | ||
|
||
| } | ||
|
|
||
| @override | ||
| Future<String?> getTitle() => webView.title; | ||
|
|
||
| @override | ||
| Future<void> scrollTo(int x, int y) async { | ||
| webView.scrollView.contentOffset = Point<double>( | ||
| x.toDouble(), | ||
| y.toDouble(), | ||
| ); | ||
| } | ||
|
|
||
| @override | ||
| Future<void> scrollBy(int x, int y) async { | ||
| final Point<double> offset = await webView.scrollView.contentOffset; | ||
| webView.scrollView.contentOffset = Point<double>( | ||
| offset.x + x.toDouble(), | ||
| offset.y + y.toDouble(), | ||
| ); | ||
|
||
| } | ||
|
|
||
| @override | ||
| Future<int> getScrollX() async { | ||
| final Point<double> offset = await webView.scrollView.contentOffset; | ||
| return offset.x.toInt(); | ||
| } | ||
|
|
||
| @override | ||
| Future<int> getScrollY() async { | ||
| final Point<double> offset = await webView.scrollView.contentOffset; | ||
| return offset.y.toInt(); | ||
| } | ||
|
|
||
| @override | ||
| Future<void> addJavascriptChannels(Set<String> javascriptChannelNames) async { | ||
| await Future.wait<void>( | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is one of those things that makes me suspect going all the way to the native boundary isn't going to be a great experience (at least not without automatic language projection); having to plumb in new ancillary objects for minor usage could get ugly.
(No change needed here, just flagging as something we'll want to watch for over time as we evaluate this approach and think about whether we want to flex the boundary back a little.)