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 #5166

Closed
wants to merge 0 commits into from

Conversation

Alex-Usmanov
Copy link
Contributor

@Alex-Usmanov Alex-Usmanov commented Oct 18, 2023

  • Added showTitle option to platform interface & app-facing api
  • Made use of that parameter on android platform in order to set show title on Chrome Custom Tabs, when it is being used
  • Made android implementation use both legacy & new api (instead of passthrough from new to legacy), in order to allow use of the aforementioned parameter
  • Added a button to the example to test this parameter
  • Added tests

Screenshot_20231018-095928
(Notice title at the top of the page "CyLog Software - HTTP ...")

flutter/flutter#136784

Pre-launch Checklist

  • I read the Contributor Guide and followed the process outlined there for submitting PRs.
  • I read the Tree Hygiene wiki page, which explains my responsibilities.
  • I read and followed the relevant style guides and ran the auto-formatter. (Unlike the flutter/flutter repo, the flutter/packages repo does use dart format.)
  • I signed the CLA.
  • The title of the PR starts with the name of the package surrounded by square brackets, e.g. [shared_preferences]
  • I listed at least one issue that this PR fixes in the description above.
  • I updated pubspec.yaml with an appropriate new version according to the pub versioning philosophy, or this PR is exempt from version changes.
  • I updated CHANGELOG.md to add a description of the change, following repository CHANGELOG style.
  • I updated/added relevant documentation (doc comments with ///).
  • I added new tests to check the change I am making, or this PR is test-exempt.
  • All existing and new tests are passing.

If you need help, consider asking for advice on the #hackers-new channel on Discord.

@@ -62,17 +62,42 @@ class UrlLauncherAndroid extends UrlLauncherPlatform {
required Map<String, String> headers,
String? webOnlyWindowName,
}) async {
final WebViewOptions webViewOptions = WebViewOptions(
Copy link
Contributor Author

@Alex-Usmanov Alex-Usmanov Oct 18, 2023

Choose a reason for hiding this comment

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

There is a fair share of code duplication here, but it could only be resolved after flutter/flutter#66721 unfortunately (could not make it a passthrough because there is no way to pass the useWebView parameter to launchUrl).

Did my best to reduce it

@ditman
Copy link
Member

ditman commented Oct 19, 2023

This cannot be implemented on the web, since the browser controls how tabs/windows are displayed.

(Feel free to @ me if I can be of any help with the rest of the PR!)

@ditman ditman removed their request for review October 19, 2023 05:25
Copy link
Contributor

Choose a reason for hiding this comment

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

All the packages where the only change is dependency_overrides can be reverted.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Did not think of that, done ✅

@Alex-Usmanov
Copy link
Contributor Author

  • Added a configuration object for in app browser
  • Removed unnecessary dependency overrides

*Will update docs once #5155 lands

Copy link
Contributor

@stuartmorgan stuartmorgan left a comment

Choose a reason for hiding this comment

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

Generally looks good, just small comments. Thanks for your patience!

/// Creates a new InAppBrowserConfiguration with given settings.
const InAppBrowserConfiguration({this.showTitle = false});

/// Whether or not to show the webpage title when using Chrome Custom Tabs.
Copy link
Contributor

Choose a reason for hiding this comment

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

Please remove "when using Chrome Custom Tabs."

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done


/// Whether or not to show the webpage title when using Chrome Custom Tabs.
///
/// Only works on Android.
Copy link
Contributor

Choose a reason for hiding this comment

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

"May not be supported on all platforms."

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

Copy link
Contributor

Choose a reason for hiding this comment

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

The changes in this file will need a simple test (e.g., testing the default InAppBrowserConfiguration behavior).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done. Did not quite think of a lot of testcases, you can find those in packages/url_launcher/url_launcher_platform_interface/test/in_app_browser_configuration_test.dart and packages/url_launcher/url_launcher_platform_interface/test/launch_options_test.dart

Copy link
Contributor

Choose a reason for hiding this comment

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

This package will need a version bump and changelog.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

Copy link
Contributor

Choose a reason for hiding this comment

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

This will need a version change.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

private static boolean openCustomTab(
@NonNull Context context, @NonNull Uri uri, @NonNull Bundle headersBundle) {
CustomTabsIntent customTabsIntent = new CustomTabsIntent.Builder().build();
@VisibleForTesting
Copy link
Contributor

Choose a reason for hiding this comment

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

Why was this made public for testing? Testing should be done via public interface whenever possible to make tests easier to maintain and less likely to miss important behavior.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Reverted this change as well

@@ -169,7 +179,8 @@ private static boolean containsRestrictedHeader(Map<String, String> headersMap)
return false;
}

private static @NonNull Bundle extractBundle(Map<String, String> headersMap) {
@VisibleForTesting
Copy link
Contributor

Choose a reason for hiding this comment

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

Same question here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

String url = "https://flutter.dev";
HashMap<String, String> headers = new HashMap<>();
String headerKey = "Content-Type";
headers.put(headerKey, "text/plain");
Copy link
Contributor

Choose a reason for hiding this comment

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

Headers don't seem relevant to this test, so shouldn't need to be set up.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, you are right. Removed this

String url = "https://flutter.dev";
HashMap<String, String> headers = new HashMap<>();
String headerKey = "Content-Type";
headers.put(headerKey, "text/plain");
Copy link
Contributor

Choose a reason for hiding this comment

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

Same.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done


/// Whether or not to show the webpage title when using Chrome Custom Tabs.
///
/// Only works on Android.
Copy link
Contributor

Choose a reason for hiding this comment

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

Same comments here as on the platform interface; platform details shouldn't be documented at this level.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Made this comment platform-independent

@Alex-Usmanov
Copy link
Contributor Author

Thank you for your valuable feedback and your time!
I am pretty sure I've fixed everything regarding the code part of this PR. CI seems to be failing due to specifics of landing PRs. I can split this up in two as soon as we get over the final touches

Copy link
Contributor

@stuartmorgan stuartmorgan left a comment

Choose a reason for hiding this comment

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

This looks good with a few minor nits; please feel free to split out the first sub-PR with just the platform interface changes.

onPressed: () => setState(() {
_launched = _launchInAppWithBrowserOptions(toLaunch);
}),
child: const Text('Launch in app with showTitle'),
Copy link
Contributor

Choose a reason for hiding this comment

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

"[...] with title displayed"


* Implement taking in `BrowserConfiguration` parameter
Copy link
Contributor

Choose a reason for hiding this comment

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

These need to follow the CHANGELOG style guide linked from the PR checklist (verb form, punctuation).


/// Whether or not to show the webpage title.
///
/// May not be supported on all platforms.
Copy link
Contributor

Choose a reason for hiding this comment

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

This file is internal to the Android implementation, so this sentence doesn't make sense here.

@@ -50,13 +50,26 @@ class InAppWebViewConfiguration {
final Map<String, String> headers;
}

/// Additional configuration options for [PreferredLaunchMode.inAppBrowserView]
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: Missing a period.

auto-submit bot pushed a commit that referenced this pull request Jan 4, 2024
This is #5166 portion of platform interface changes. Adds `InAppBrowserConfiguration` parameter, as well as `InAppBrowserConfiguration.showTitle` parameter that configures whether to show or not to show webpage title
@stuartmorgan
Copy link
Contributor

Update from triage: This is blocked on #5759, which is currently in review.

@Alex-Usmanov
Copy link
Contributor Author

I made a terrible mistake with source control and #5166 was automatically closed. The restored version is in #6097.

Once again sorry for the inconvenience 😔

auto-submit bot pushed a commit that referenced this pull request Feb 13, 2024
…ations (#5759)

Platform implementation portion of #5166. Implements `InAppBrowserConfiguration` support on Android, as well as support for `InAppBrowserConfiguration.showTitle` parameter for hiding/showing webpage title in Android Custom Tabs.
arc-yong pushed a commit to Arctuition/packages-arc that referenced this pull request Jun 14, 2024
This is flutter#5166 portion of platform interface changes. Adds `InAppBrowserConfiguration` parameter, as well as `InAppBrowserConfiguration.showTitle` parameter that configures whether to show or not to show webpage title
arc-yong pushed a commit to Arctuition/packages-arc that referenced this pull request Jun 14, 2024
…ations (flutter#5759)

Platform implementation portion of flutter#5166. Implements `InAppBrowserConfiguration` support on Android, as well as support for `InAppBrowserConfiguration.showTitle` parameter for hiding/showing webpage title in Android Custom Tabs.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants