-
Notifications
You must be signed in to change notification settings - Fork 3k
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
[url_launcher] Add an inAppBrowserView
mode
#5155
Changes from 12 commits
7ea59ee
50efebc
d155a01
177207d
49c4594
1334828
f70a5ee
3cbffcd
4704684
8762abe
1f70e21
ed562cd
28f0553
6ceb1fb
1646161
825df8e
e8e2dfc
f89bc12
78bcf3e
d97e911
1104b6e
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 |
---|---|---|
|
@@ -11,25 +11,13 @@ import 'type_conversion.dart'; | |
|
||
/// Passes [url] to the underlying platform for handling. | ||
/// | ||
/// [mode] support varies significantly by platform: | ||
/// - [LaunchMode.platformDefault] is supported on all platforms: | ||
/// - On iOS and Android, this treats web URLs as | ||
/// [LaunchMode.inAppWebView], and all other URLs as | ||
/// [LaunchMode.externalApplication]. | ||
/// - On Windows, macOS, and Linux this behaves like | ||
/// [LaunchMode.externalApplication]. | ||
/// - On web, this uses `webOnlyWindowName` for web URLs, and behaves like | ||
/// [LaunchMode.externalApplication] for any other content. | ||
/// - [LaunchMode.inAppWebView] is currently only supported on iOS and | ||
/// Android. If a non-web URL is passed with this mode, an [ArgumentError] | ||
/// will be thrown. | ||
/// - [LaunchMode.externalApplication] is supported on all platforms. | ||
/// On iOS, this should be used in cases where sharing the cookies of the | ||
/// user's browser is important, such as SSO flows, since Safari View | ||
/// Controller does not share the browser's context. | ||
/// - [LaunchMode.externalNonBrowserApplication] is supported on iOS 10+. | ||
/// This setting is used to require universal links to open in a non-browser | ||
/// application. | ||
/// [mode] support varies significantly by platform. Clients can use | ||
/// [supportsLaunchMode] to query for support, but platforms will fall back to | ||
/// other modes if the requested mode is not supported, so checking is not | ||
/// required. The default behavior of [LaunchMode.platformDefault] is up to each | ||
/// platform, and its behavior for a given platform may change over time as new | ||
/// modes are supported, so clients that want a specific mode should request it | ||
/// rather than rely on any currently observed default behavior. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This makes the documentation federation-friendly and evergreen. If we find that people want docs about specific platform behaviors, we can add it to the platform package READMEs later. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Per-platform docs are the way, agreed! |
||
/// | ||
/// For web, [webOnlyWindowName] specifies a target for the launch. This | ||
/// supports the standard special link target names. For example: | ||
|
@@ -45,7 +33,8 @@ Future<bool> launchUrl( | |
WebViewConfiguration webViewConfiguration = const WebViewConfiguration(), | ||
String? webOnlyWindowName, | ||
}) async { | ||
if (mode == LaunchMode.inAppWebView && | ||
if ((mode == LaunchMode.inAppWebView || | ||
mode == LaunchMode.inAppBrowserView) && | ||
!(url.scheme == 'https' || url.scheme == 'http')) { | ||
throw ArgumentError.value(url, 'url', | ||
'To use an in-app web view, you must provide an http(s) URL.'); | ||
|
@@ -81,8 +70,26 @@ Future<bool> canLaunchUrl(Uri url) async { | |
/// Closes the current in-app web view, if one was previously opened by | ||
/// [launchUrl]. | ||
/// | ||
/// If [launchUrl] was never called with [LaunchMode.inAppWebView], then this | ||
/// call will have no effect. | ||
/// This works only if [supportsCloseForLaunchMode] returns true for the mode | ||
/// that was used by [launchUrl]. | ||
Future<void> closeInAppWebView() async { | ||
return UrlLauncherPlatform.instance.closeWebView(); | ||
} | ||
|
||
/// Returns true if [mode] is supported by the current platform implementation. | ||
/// | ||
/// Calling [launchUrl] with an unsupported mode will fall back to a supported | ||
/// mode, so calling this method is only necessary for cases where the caller | ||
/// needs to know which mode will be used. | ||
Future<bool> supportsLaunchMode(PreferredLaunchMode mode) { | ||
return UrlLauncherPlatform.instance.supportsMode(mode); | ||
} | ||
|
||
/// Returns true if [closeInAppWebView] is supported for [mode] in the current | ||
/// platform implementation. | ||
/// | ||
/// If this returns false, [closeInAppWebView] will not work when launching | ||
/// URLs with [mode]. | ||
Future<bool> supportsCloseForLaunchMode(PreferredLaunchMode mode) { | ||
return UrlLauncherPlatform.instance.supportsMode(mode); | ||
} |
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.
I changed this since on Android we generally want to use Custom Tabs when possible, and it'll automatically fall back to webview when support isn't available.