Skip to content

Commit d6dd0a2

Browse files
authored
Merge branch 'master' into add_resizeToAvoidBottomPadding
2 parents 9ef1638 + 8cdfa02 commit d6dd0a2

File tree

6 files changed

+52
-6
lines changed

6 files changed

+52
-6
lines changed

android/src/main/java/com/flutter_webview_plugin/FlutterWebviewPlugin.java

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ private void openUrl(MethodCall call, MethodChannel.Result result) {
9797
Map<String, String> headers = call.argument("headers");
9898
boolean scrollBar = call.argument("scrollBar");
9999
boolean allowFileURLs = call.argument("allowFileURLs");
100+
boolean geolocationEnabled = call.argument("geolocationEnabled");
100101

101102
if (webViewManager == null || webViewManager.closed == true) {
102103
webViewManager = new WebviewManager(activity);
@@ -118,7 +119,8 @@ private void openUrl(MethodCall call, MethodChannel.Result result) {
118119
scrollBar,
119120
supportMultipleWindows,
120121
appCacheEnabled,
121-
allowFileURLs
122+
allowFileURLs,
123+
geolocationEnabled
122124
);
123125
result.success(null);
124126
}
@@ -147,6 +149,7 @@ private void stopLoading(MethodCall call, MethodChannel.Result result) {
147149
if (webViewManager != null) {
148150
webViewManager.stopLoading(call, result);
149151
}
152+
result.success(null);
150153
}
151154

152155
private void close(MethodCall call, MethodChannel.Result result) {
@@ -163,6 +166,7 @@ private void back(MethodCall call, MethodChannel.Result result) {
163166
if (webViewManager != null) {
164167
webViewManager.back(call, result);
165168
}
169+
result.success(null);
166170
}
167171

168172
/**
@@ -172,6 +176,7 @@ private void forward(MethodCall call, MethodChannel.Result result) {
172176
if (webViewManager != null) {
173177
webViewManager.forward(call, result);
174178
}
179+
result.success(null);
175180
}
176181

177182
/**
@@ -181,13 +186,15 @@ private void reload(MethodCall call, MethodChannel.Result result) {
181186
if (webViewManager != null) {
182187
webViewManager.reload(call, result);
183188
}
189+
result.success(null);
184190
}
185191

186192
private void reloadUrl(MethodCall call, MethodChannel.Result result) {
187193
if (webViewManager != null) {
188194
String url = call.argument("url");
189195
webViewManager.reloadUrl(url);
190196
}
197+
result.success(null);
191198
}
192199

193200
private void eval(MethodCall call, final MethodChannel.Result result) {
@@ -208,12 +215,14 @@ private void hide(MethodCall call, final MethodChannel.Result result) {
208215
if (webViewManager != null) {
209216
webViewManager.hide(call, result);
210217
}
218+
result.success(null);
211219
}
212220

213221
private void show(MethodCall call, final MethodChannel.Result result) {
214222
if (webViewManager != null) {
215223
webViewManager.show(call, result);
216224
}
225+
result.success(null);
217226
}
218227

219228
private void cleanCookies(MethodCall call, final MethodChannel.Result result) {

android/src/main/java/com/flutter_webview_plugin/WebviewManager.java

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import android.view.View;
1111
import android.view.ViewGroup;
1212
import android.webkit.CookieManager;
13+
import android.webkit.GeolocationPermissions;
1314
import android.webkit.ValueCallback;
1415
import android.webkit.WebChromeClient;
1516
import android.webkit.WebSettings;
@@ -204,7 +205,8 @@ void openUrl(
204205
boolean scrollBar,
205206
boolean supportMultipleWindows,
206207
boolean appCacheEnabled,
207-
boolean allowFileURLs
208+
boolean allowFileURLs,
209+
boolean geolocationEnabled
208210
) {
209211
webView.getSettings().setJavaScriptEnabled(withJavascript);
210212
webView.getSettings().setBuiltInZoomControls(withZoom);
@@ -219,6 +221,16 @@ void openUrl(
219221
webView.getSettings().setAllowFileAccessFromFileURLs(allowFileURLs);
220222
webView.getSettings().setAllowUniversalAccessFromFileURLs(allowFileURLs);
221223

224+
if (geolocationEnabled) {
225+
webView.getSettings().setGeolocationEnabled(true);
226+
webView.setWebChromeClient(new WebChromeClient() {
227+
@Override
228+
public void onGeolocationPermissionsShowPrompt(String origin, GeolocationPermissions.Callback callback) {
229+
callback.invoke(origin, true, false);
230+
}
231+
});
232+
}
233+
222234
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
223235
webView.getSettings().setMixedContentMode(WebSettings.MIXED_CONTENT_COMPATIBILITY_MODE);
224236
}
@@ -228,7 +240,7 @@ void openUrl(
228240
}
229241

230242
if (hidden) {
231-
webView.setVisibility(View.INVISIBLE);
243+
webView.setVisibility(View.GONE);
232244
}
233245

234246
if (clearCookies) {
@@ -325,7 +337,7 @@ boolean canGoForward() {
325337
}
326338
void hide(MethodCall call, MethodChannel.Result result) {
327339
if (webView != null) {
328-
webView.setVisibility(View.INVISIBLE);
340+
webView.setVisibility(View.GONE);
329341
}
330342
}
331343
void show(MethodCall call, MethodChannel.Result result) {

ios/Classes/FlutterWebviewPlugin.m

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
static NSString *const CHANNEL_NAME = @"flutter_webview_plugin";
44

55
// UIWebViewDelegate
6-
@interface FlutterWebviewPlugin() <WKNavigationDelegate, UIScrollViewDelegate> {
6+
@interface FlutterWebviewPlugin() <WKNavigationDelegate, UIScrollViewDelegate, WKUIDelegate> {
77
BOOL _enableAppScheme;
88
BOOL _enableZoom;
99
}
@@ -105,6 +105,7 @@ - (void)initWebview:(FlutterMethodCall*)call {
105105
}
106106

107107
self.webview = [[WKWebView alloc] initWithFrame:rc];
108+
self.webview.UIDelegate = self;
108109
self.webview.navigationDelegate = self;
109110
self.webview.scrollView.delegate = self;
110111
self.webview.hidden = [hidden boolValue];
@@ -260,6 +261,15 @@ - (void)webView:(WKWebView *)webView decidePolicyForNavigationAction:(WKNavigati
260261
}
261262
}
262263

264+
- (WKWebView *)webView:(WKWebView *)webView createWebViewWithConfiguration:(WKWebViewConfiguration *)configuration
265+
forNavigationAction:(WKNavigationAction *)navigationAction windowFeatures:(WKWindowFeatures *)windowFeatures {
266+
267+
if (!navigationAction.targetFrame.isMainFrame) {
268+
[webView loadRequest:navigationAction.request];
269+
}
270+
271+
return nil;
272+
}
263273

264274
- (void)webView:(WKWebView *)webView didStartProvisionalNavigation:(WKNavigation *)navigation {
265275
[channel invokeMethod:@"onState" arguments:@{@"type": @"startLoad", @"url": webView.URL.absoluteString}];

lib/src/base.dart

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ class FlutterWebviewPlugin {
110110
bool supportMultipleWindows,
111111
bool appCacheEnabled,
112112
bool allowFileURLs,
113+
bool geolocationEnabled,
113114
}) async {
114115
final args = <String, dynamic>{
115116
'url': url,
@@ -126,6 +127,7 @@ class FlutterWebviewPlugin {
126127
'supportMultipleWindows': supportMultipleWindows ?? false,
127128
'appCacheEnabled': appCacheEnabled ?? false,
128129
'allowFileURLs': allowFileURLs ?? false,
130+
'geolocationEnabled': geolocationEnabled ?? false,
129131
};
130132

131133
if (headers != null) {

lib/src/webview_scaffold.dart

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ class WebviewScaffold extends StatefulWidget {
3131
this.initialChild,
3232
this.allowFileURLs,
3333
this.resizeToAvoidBottomPadding = true,
34+
this.geolocationEnabled
3435
}) : super(key: key);
3536

3637
final PreferredSizeWidget appBar;
@@ -54,6 +55,7 @@ class WebviewScaffold extends StatefulWidget {
5455
final Widget initialChild;
5556
final bool allowFileURLs;
5657
final bool resizeToAvoidBottomPadding;
58+
final bool geolocationEnabled;
5759

5860
@override
5961
_WebviewScaffoldState createState() => _WebviewScaffoldState();
@@ -65,11 +67,19 @@ class _WebviewScaffoldState extends State<WebviewScaffold> {
6567
Timer _resizeTimer;
6668
StreamSubscription<WebViewStateChanged> _onStateChanged;
6769

70+
var _onDestroy;
71+
6872
@override
6973
void initState() {
7074
super.initState();
7175
webviewReference.close();
7276

77+
_onDestroy = webviewReference.onDestroy.listen((_) {
78+
if (mounted) {
79+
Navigator.of(context).pop();
80+
}
81+
});
82+
7383
if (widget.hidden) {
7484
_onStateChanged = webviewReference.onStateChanged.listen((WebViewStateChanged state) {
7585
if (state.type == WebViewState.finishLoad) {
@@ -82,6 +92,7 @@ class _WebviewScaffoldState extends State<WebviewScaffold> {
8292
@override
8393
void dispose() {
8494
super.dispose();
95+
_onDestroy?.cancel();
8596
_resizeTimer?.cancel();
8697
webviewReference.close();
8798
if (widget.hidden) {
@@ -95,6 +106,7 @@ class _WebviewScaffoldState extends State<WebviewScaffold> {
95106
return Scaffold(
96107
appBar: widget.appBar,
97108
resizeToAvoidBottomPadding: widget.resizeToAvoidBottomPadding,
109+
resizeToAvoidBottomInset: false,
98110
persistentFooterButtons: widget.persistentFooterButtons,
99111
bottomNavigationBar: widget.bottomNavigationBar,
100112
body: _WebviewPlaceholder(
@@ -118,6 +130,7 @@ class _WebviewScaffoldState extends State<WebviewScaffold> {
118130
supportMultipleWindows: widget.supportMultipleWindows,
119131
appCacheEnabled: widget.appCacheEnabled,
120132
allowFileURLs: widget.allowFileURLs,
133+
geolocationEnabled: widget.geolocationEnabled
121134
);
122135
} else {
123136
if (_rect != value) {

pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ authors:
77
- Simon Lightfoot <[email protected]>
88
- Rafal Wachol <[email protected]>
99
homepage: https://github.com/dart-flitter/flutter_webview_plugin
10-
version: 0.3.0+2
10+
version: 0.3.1
1111
maintainer: Simon Lightfoot (@slightfoot)
1212

1313
environment:

0 commit comments

Comments
 (0)