Skip to content
This repository was archived by the owner on Feb 22, 2023. It is now read-only.
Merged
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
4 changes: 4 additions & 0 deletions packages/webview_flutter/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 0.3.19

* Add setting for iOS to allow gesture based navigation.

## 0.3.18+1

* Be explicit that keyboard is not ready for production in README.md.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,8 @@ private void applySettings(Map<String, Object> settings) {

webView.setWebContentsDebuggingEnabled(debuggingEnabled);
break;
case "gestureNavigationEnabled":
break;
case "userAgent":
updateUserAgent((String) settings.get(key));
break;
Expand Down
1 change: 1 addition & 0 deletions packages/webview_flutter/example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ class _WebViewExampleState extends State<WebViewExample> {
onPageFinished: (String url) {
print('Page finished loading: $url');
},
gestureNavigationEnabled: true,
);
}),
floatingActionButton: favoriteButton(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -652,6 +652,32 @@ void main() {
expect(currentUrl, 'https://www.google.com/');
});
});

testWidgets('launches with gestureNavigationEnabled on iOS',
(WidgetTester tester) async {
final Completer<WebViewController> controllerCompleter =
Completer<WebViewController>();
await tester.pumpWidget(
Directionality(
textDirection: TextDirection.ltr,
child: SizedBox(
width: 400,
height: 300,
child: WebView(
key: GlobalKey(),
initialUrl: 'https://flutter.dev/',
gestureNavigationEnabled: true,
onWebViewCreated: (WebViewController controller) {
controllerCompleter.complete(controller);
},
),
),
),
);
final WebViewController controller = await controllerCompleter.future;
final String currentUrl = await controller.currentUrl();
expect(currentUrl, 'https://flutter.dev/');
});
}

// JavaScript booleans evaluate to different string values on Android and iOS.
Expand Down
4 changes: 4 additions & 0 deletions packages/webview_flutter/ios/Classes/FlutterWebView.m
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,10 @@ - (NSString*)applySettings:(NSDictionary<NSString*, id>*)settings {
_navigationDelegate.hasDartNavigationDelegate = [hasDartNavigationDelegate boolValue];
} else if ([key isEqualToString:@"debuggingEnabled"]) {
// no-op debugging is always enabled on iOS.
} else if ([key isEqualToString:@"gestureNavigationEnabled"]) {
NSNumber* allowsBackForwardNavigationGestures = settings[key];
_webView.allowsBackForwardNavigationGestures =
[allowsBackForwardNavigationGestures boolValue];
} else if ([key isEqualToString:@"userAgent"]) {
NSString* userAgent = settings[key];
[self updateUserAgent:[userAgent isEqual:[NSNull null]] ? nil : userAgent];
Expand Down
8 changes: 7 additions & 1 deletion packages/webview_flutter/lib/platform_interface.dart
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,7 @@ class WebSettings {
this.javascriptMode,
this.hasNavigationDelegate,
this.debuggingEnabled,
this.gestureNavigationEnabled,
@required this.userAgent,
}) : assert(userAgent != null);

Expand All @@ -255,9 +256,14 @@ class WebSettings {
/// See also [WebView.userAgent].
final WebSetting<String> userAgent;

/// Whether to allow swipe based navigation in iOS.
///
/// See also: [WebView.gestureNavigationEnabled]
final bool gestureNavigationEnabled;

@override
String toString() {
return 'WebSettings(javascriptMode: $javascriptMode, hasNavigationDelegate: $hasNavigationDelegate, debuggingEnabled: $debuggingEnabled, userAgent: $userAgent,)';
return 'WebSettings(javascriptMode: $javascriptMode, hasNavigationDelegate: $hasNavigationDelegate, debuggingEnabled: $debuggingEnabled, gestureNavigationEnabled: $gestureNavigationEnabled, userAgent: $userAgent)';
}
}

Expand Down
2 changes: 2 additions & 0 deletions packages/webview_flutter/lib/src/webview_method_channel.dart
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,8 @@ class MethodChannelWebViewPlatform implements WebViewPlatformController {
_addIfNonNull('jsMode', settings.javascriptMode?.index);
_addIfNonNull('hasNavigationDelegate', settings.hasNavigationDelegate);
_addIfNonNull('debuggingEnabled', settings.debuggingEnabled);
_addIfNonNull(
'gestureNavigationEnabled', settings.gestureNavigationEnabled);
_addSettingIfPresent('userAgent', settings.userAgent);
return map;
}
Expand Down
9 changes: 9 additions & 0 deletions packages/webview_flutter/lib/webview_flutter.dart
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ class WebView extends StatefulWidget {
this.onPageStarted,
this.onPageFinished,
this.debuggingEnabled = false,
this.gestureNavigationEnabled = false,
this.userAgent,
this.initialMediaPlaybackPolicy =
AutoMediaPlaybackPolicy.require_user_action_for_all_media_types,
Expand Down Expand Up @@ -290,6 +291,13 @@ class WebView extends StatefulWidget {
final bool debuggingEnabled;

/// The value used for the HTTP User-Agent: request header.
/// A Boolean value indicating whether horizontal swipe gestures will trigger back-forward list navigations.
///
/// This only works on iOS.
///
/// By default `gestureNavigationEnabled` is false.
final bool gestureNavigationEnabled;

///
/// When null the platform's webview default is used for the User-Agent header.
///
Expand Down Expand Up @@ -383,6 +391,7 @@ WebSettings _webSettingsFromWidget(WebView widget) {
javascriptMode: widget.javascriptMode,
hasNavigationDelegate: widget.navigationDelegate != null,
debuggingEnabled: widget.debuggingEnabled,
gestureNavigationEnabled: widget.gestureNavigationEnabled,
userAgent: WebSetting<String>.of(widget.userAgent),
);
}
Expand Down
2 changes: 1 addition & 1 deletion packages/webview_flutter/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: webview_flutter
description: A Flutter plugin that provides a WebView widget on Android and iOS.
version: 0.3.18+1
version: 0.3.19
homepage: https://github.com/flutter/plugins/tree/master/packages/webview_flutter

environment:
Expand Down
4 changes: 4 additions & 0 deletions packages/webview_flutter/test/webview_flutter_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -822,6 +822,7 @@ void main() {
await tester.pumpWidget(
const WebView(
initialUrl: 'https://youtube.com',
gestureNavigationEnabled: true,
),
);

Expand All @@ -837,6 +838,7 @@ void main() {
hasNavigationDelegate: false,
debuggingEnabled: false,
userAgent: WebSetting<String>.of(null),
gestureNavigationEnabled: true,
),
// TODO(iskakaushik): Remove this when collection literals makes it to stable.
// ignore: prefer_collection_literals
Expand Down Expand Up @@ -1193,6 +1195,8 @@ class MatchesWebSettings extends Matcher {
_webSettings.hasNavigationDelegate ==
webSettings.hasNavigationDelegate &&
_webSettings.debuggingEnabled == webSettings.debuggingEnabled &&
_webSettings.gestureNavigationEnabled ==
webSettings.gestureNavigationEnabled &&
_webSettings.userAgent == webSettings.userAgent;
}
}
Expand Down