Skip to content
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 support for setting show title on Chrome Custom Tabs #6097

Merged
merged 40 commits into from
Jun 3, 2024
Merged
Show file tree
Hide file tree
Changes from 38 commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
e41ea0e
add android show title customization functionality
Alex-Usmanov Oct 17, 2023
fb67692
Pass the parameter
Alex-Usmanov Oct 17, 2023
21cd06f
Dependency overrides
Alex-Usmanov Oct 17, 2023
276c08b
Add tests for native side
Alex-Usmanov Oct 17, 2023
1897451
Cover dart side with tests
Alex-Usmanov Oct 17, 2023
5cd1709
Format
Alex-Usmanov Oct 17, 2023
bc943c5
Reduce code repetition
Alex-Usmanov Oct 17, 2023
d6306ba
Revert todo change
Alex-Usmanov Oct 18, 2023
f59475b
Wrap browser customization values in another configuration object
Alex-Usmanov Oct 20, 2023
157343b
Remove deps overrides
Alex-Usmanov Oct 20, 2023
ae20b08
Revert more deps overrides
Alex-Usmanov Oct 20, 2023
214b0a9
Revert web as well
Alex-Usmanov Oct 20, 2023
cd7dfc9
Revert go_router
Alex-Usmanov Oct 20, 2023
d205c7c
Merge branch 'main' into main
Alex-Usmanov Oct 20, 2023
5eef662
Merge remote-tracking branch 'upstream/main'
Alex-Usmanov Oct 27, 2023
c86ff6e
Format files
Alex-Usmanov Oct 27, 2023
92b2197
Fix tests
Alex-Usmanov Oct 27, 2023
425617e
Add browseroptions to launchUrlString & add more tests
Alex-Usmanov Oct 30, 2023
ece2b78
Fix docstrings
Alex-Usmanov Dec 7, 2023
3ddd644
Revert test format change
Alex-Usmanov Dec 7, 2023
cd361d0
Fix tests
Alex-Usmanov Dec 8, 2023
f0017b7
Version bumps and changelogs
Alex-Usmanov Dec 8, 2023
6105671
Merge remote-tracking branch 'upstream/main'
Alex-Usmanov Dec 8, 2023
a50be0f
Return path-based dependencies
Alex-Usmanov Dec 8, 2023
ef9c154
Add licences
Alex-Usmanov Dec 11, 2023
f4b08cb
Merge remote-tracking branch 'upstream/main'
Alex-Usmanov Dec 11, 2023
80d439b
Fix documentation & changelog
Alex-Usmanov Dec 26, 2023
992d38e
Merge remote-tracking branch 'upstream/main'
Alex-Usmanov Dec 26, 2023
193c076
Add backticks to SFSafariViewController in platform interface changelog
Alex-Usmanov Jan 4, 2024
b399c9b
Merge remote-tracking branch 'upstream/main'
Alex-Usmanov Jan 4, 2024
1ad83a2
More merging
Alex-Usmanov Jan 4, 2024
298a705
Merge remote-tracking branch 'upstream/main' into show-title
Alex-Usmanov Feb 12, 2024
70f5eb0
Merge remote-tracking branch 'upstream/main' into show-title
Alex-Usmanov Mar 31, 2024
8f67ab9
Remove dependency overrides
Alex-Usmanov Mar 31, 2024
c203ae0
Revert changelog
Alex-Usmanov Apr 1, 2024
5ae7bc9
Merge branch 'main' into show-title
Alex-Usmanov Apr 7, 2024
e646958
Merge remote-tracking branch 'upstream/main' into show-title
Alex-Usmanov May 10, 2024
7d92695
Merge remote-tracking branch 'upstream/main' into show-title
Alex-Usmanov May 21, 2024
90360b0
Fix missing classname in type_conversion.dart
Alex-Usmanov Jun 3, 2024
647a8ce
Merge remote-tracking branch 'upstream/main' into show-title
Alex-Usmanov Jun 3, 2024
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: 3 additions & 1 deletion packages/url_launcher/url_launcher/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
## NEXT
## 6.3.0

* Adds `BrowserConfiguration` parameter, to configure in-app browser views, such as Android Custom Tabs or SFSafariViewController.
* Adds `showTitle` to `BrowserConfiguration`, to allow showing webpage titles in in-app browser views.
* Updates minimum supported SDK version to Flutter 3.16/Dart 3.2.

## 6.2.6
Expand Down
17 changes: 17 additions & 0 deletions packages/url_launcher/url_launcher/example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,16 @@ class _MyHomePageState extends State<MyHomePage> {
}
}

Future<void> _launchInAppWithBrowserOptions(Uri url) async {
if (!await launchUrl(
url,
mode: LaunchMode.inAppBrowserView,
browserConfiguration: const BrowserConfiguration(showTitle: true),
)) {
throw Exception('Could not launch $url');
}
}

Future<void> _launchAsInAppWebViewWithCustomHeaders(Uri url) async {
if (!await launchUrl(
url,
Expand Down Expand Up @@ -220,6 +230,13 @@ class _MyHomePageState extends State<MyHomePage> {
child: const Text('Launch in app + close after 5 seconds'),
),
const Padding(padding: EdgeInsets.all(16.0)),
ElevatedButton(
onPressed: () => setState(() {
_launched = _launchInAppWithBrowserOptions(toLaunch);
}),
child: const Text('Launch in app with title displayed'),
),
const Padding(padding: EdgeInsets.all(16.0)),
Link(
uri: Uri.parse(
'https://pub.dev/documentation/url_launcher/latest/link/link-library.html'),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,24 @@ import 'types.dart';

/// Converts an (app-facing) [WebViewConfiguration] to a (platform interface)
/// [InAppWebViewConfiguration].
InAppWebViewConfiguration convertConfiguration(WebViewConfiguration config) {
InAppWebViewConfiguration convertWebViewConfiguration(
WebViewConfiguration config) {
return InAppWebViewConfiguration(
enableJavaScript: config.enableJavaScript,
enableDomStorage: config.enableDomStorage,
headers: config.headers,
);
}

/// Converts an (app-facing) [BrowserConfiguration] to a (platform interface)
/// [InApp].
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[InAppBrowserConfiguration]

InAppBrowserConfiguration convertBrowserConfiguration(
BrowserConfiguration config) {
return InAppBrowserConfiguration(
showTitle: config.showTitle,
);
}

/// Converts an (app-facing) [LaunchMode] to a (platform interface)
/// [PreferredLaunchMode].
PreferredLaunchMode convertLaunchMode(LaunchMode mode) {
Expand Down
12 changes: 12 additions & 0 deletions packages/url_launcher/url_launcher/lib/src/types.dart
Original file line number Diff line number Diff line change
Expand Up @@ -55,3 +55,15 @@ class WebViewConfiguration {
/// Not all browsers support this, so it is not guaranteed to be honored.
final Map<String, String> headers;
}

/// Additional configuration options for [LaunchMode.inAppBrowserView]
@immutable
class BrowserConfiguration {
/// Creates a new InAppBrowserConfiguration with given settings.
const BrowserConfiguration({this.showTitle = false});

/// Whether or not to show the webpage title.
///
/// May not be supported on all platforms.
final bool showTitle;
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ Future<bool> launchUrlString(
String urlString, {
LaunchMode mode = LaunchMode.platformDefault,
WebViewConfiguration webViewConfiguration = const WebViewConfiguration(),
BrowserConfiguration browserConfiguration = const BrowserConfiguration(),
String? webOnlyWindowName,
}) async {
if ((mode == LaunchMode.inAppWebView ||
Expand All @@ -35,7 +36,8 @@ Future<bool> launchUrlString(
urlString,
LaunchOptions(
mode: convertLaunchMode(mode),
webViewConfiguration: convertConfiguration(webViewConfiguration),
webViewConfiguration: convertWebViewConfiguration(webViewConfiguration),
browserConfiguration: convertBrowserConfiguration(browserConfiguration),
webOnlyWindowName: webOnlyWindowName,
),
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ Future<bool> launchUrl(
Uri url, {
LaunchMode mode = LaunchMode.platformDefault,
WebViewConfiguration webViewConfiguration = const WebViewConfiguration(),
BrowserConfiguration browserConfiguration = const BrowserConfiguration(),
String? webOnlyWindowName,
}) async {
if ((mode == LaunchMode.inAppWebView ||
Expand All @@ -52,7 +53,8 @@ Future<bool> launchUrl(
url.toString(),
LaunchOptions(
mode: convertLaunchMode(mode),
webViewConfiguration: convertConfiguration(webViewConfiguration),
webViewConfiguration: convertWebViewConfiguration(webViewConfiguration),
browserConfiguration: convertBrowserConfiguration(browserConfiguration),
webOnlyWindowName: webOnlyWindowName,
),
);
Expand Down
6 changes: 3 additions & 3 deletions packages/url_launcher/url_launcher/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ description: Flutter plugin for launching a URL. Supports
web, phone, SMS, and email schemes.
repository: https://github.com/flutter/packages/tree/main/packages/url_launcher/url_launcher
issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+url_launcher%22
version: 6.2.6
version: 6.3.0

environment:
sdk: ">=3.2.0 <4.0.0"
Expand All @@ -28,13 +28,13 @@ flutter:
dependencies:
flutter:
sdk: flutter
url_launcher_android: ^6.2.0
url_launcher_android: ^6.3.0
url_launcher_ios: ^6.2.4
# Allow either the pure-native or Dart/native hybrid versions of the desktop
# implementations, as both are compatible.
url_launcher_linux: ^3.1.0
url_launcher_macos: ^3.1.0
url_launcher_platform_interface: ^2.2.0
url_launcher_platform_interface: ^2.3.0
url_launcher_web: ^2.2.0
url_launcher_windows: ^3.1.0

Expand Down
2 changes: 2 additions & 0 deletions packages/url_launcher/url_launcher/test/link_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ void main() {
enableDomStorage: true,
headers: <String, String>{},
webOnlyWindowName: null,
showTitle: false,
)
..setResponse(true);
await followLink!();
Expand Down Expand Up @@ -92,6 +93,7 @@ void main() {
enableDomStorage: true,
headers: <String, String>{},
webOnlyWindowName: null,
showTitle: false,
)
..setResponse(true);
await followLink!();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ class MockUrlLauncher extends Fake
bool? enableJavaScript;
bool? enableDomStorage;
bool? universalLinksOnly;
bool? showTitle;
Map<String, String>? headers;
String? webOnlyWindowName;

Expand All @@ -41,6 +42,7 @@ class MockUrlLauncher extends Fake
required bool universalLinksOnly,
required Map<String, String> headers,
required String? webOnlyWindowName,
required bool showTitle,
}) {
this.url = url;
this.launchMode = launchMode;
Expand All @@ -51,6 +53,7 @@ class MockUrlLauncher extends Fake
this.universalLinksOnly = universalLinksOnly;
this.headers = headers;
this.webOnlyWindowName = webOnlyWindowName;
this.showTitle = showTitle;
}

// ignore: use_setters_to_change_properties
Expand Down Expand Up @@ -87,6 +90,7 @@ class MockUrlLauncher extends Fake
expect(universalLinksOnly, this.universalLinksOnly);
expect(headers, this.headers);
expect(webOnlyWindowName, this.webOnlyWindowName);
expect(webOnlyWindowName, this.webOnlyWindowName);
launchCalled = true;
return response!;
}
Expand All @@ -98,6 +102,7 @@ class MockUrlLauncher extends Fake
expect(options.webViewConfiguration.enableJavaScript, enableJavaScript);
expect(options.webViewConfiguration.enableDomStorage, enableDomStorage);
expect(options.webViewConfiguration.headers, headers);
expect(options.browserConfiguration.showTitle, showTitle);
expect(options.webOnlyWindowName, webOnlyWindowName);
launchCalled = true;
return response!;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ void main() {
universalLinksOnly: false,
headers: <String, String>{},
webOnlyWindowName: null,
showTitle: false,
)
..setResponse(true);
expect(await launch('http://flutter.dev/'), isTrue);
Expand All @@ -69,6 +70,7 @@ void main() {
universalLinksOnly: false,
headers: <String, String>{'key': 'value'},
webOnlyWindowName: null,
showTitle: false,
)
..setResponse(true);
expect(
Expand All @@ -90,6 +92,7 @@ void main() {
universalLinksOnly: false,
headers: <String, String>{},
webOnlyWindowName: null,
showTitle: false,
)
..setResponse(true);
expect(await launch('http://flutter.dev/', forceSafariVC: true), isTrue);
Expand All @@ -106,6 +109,7 @@ void main() {
universalLinksOnly: true,
headers: <String, String>{},
webOnlyWindowName: null,
showTitle: false,
)
..setResponse(true);
expect(
Expand All @@ -125,6 +129,7 @@ void main() {
universalLinksOnly: false,
headers: <String, String>{},
webOnlyWindowName: null,
showTitle: false,
)
..setResponse(true);
expect(await launch('http://flutter.dev/', forceWebView: true), isTrue);
Expand All @@ -141,6 +146,7 @@ void main() {
universalLinksOnly: false,
headers: <String, String>{},
webOnlyWindowName: null,
showTitle: false,
)
..setResponse(true);
expect(
Expand All @@ -160,6 +166,7 @@ void main() {
universalLinksOnly: false,
headers: <String, String>{},
webOnlyWindowName: null,
showTitle: false,
)
..setResponse(true);
expect(
Expand All @@ -179,6 +186,7 @@ void main() {
universalLinksOnly: false,
headers: <String, String>{},
webOnlyWindowName: null,
showTitle: false,
)
..setResponse(true);
expect(await launch('http://flutter.dev/', forceSafariVC: false), isTrue);
Expand All @@ -200,6 +208,7 @@ void main() {
universalLinksOnly: false,
headers: <String, String>{},
webOnlyWindowName: null,
showTitle: false,
)
..setResponse(true);
expect(await launch('mailto:[email protected]?subject=Hello'),
Expand Down Expand Up @@ -231,6 +240,7 @@ void main() {
universalLinksOnly: false,
headers: <String, String>{},
webOnlyWindowName: null,
showTitle: false,
)
..setResponse(true);

Expand Down Expand Up @@ -263,6 +273,7 @@ void main() {
universalLinksOnly: false,
headers: <String, String>{},
webOnlyWindowName: null,
showTitle: false,
)
..setResponse(true);

Expand Down Expand Up @@ -296,6 +307,7 @@ void main() {
universalLinksOnly: false,
headers: <String, String>{},
webOnlyWindowName: null,
showTitle: false,
)
..setResponse(true);
expect(
Expand Down
Loading