Skip to content

Commit

Permalink
[url_launcher] Add InAppBrowserConfiguration parameter (#5758)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
Alex-Usmanov authored Jan 4, 2024
1 parent 31fc7b5 commit 7beab0d
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 2.3.0
* Adds `InAppBrowserConfiguration` parameter to `LaunchOptions`, to configure in-app browser views, such as Android Custom Tabs or `SFSafariViewController`.
* Adds `showTitle` parameter to `InAppBrowserConfiguration` in order to control web-page title visibility.

## 2.2.1

* Updates minimum supported SDK version to Flutter 3.10/Dart 3.0.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,26 @@ class InAppWebViewConfiguration {
final Map<String, String> headers;
}

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

/// Whether or not to show the webpage title.
///
/// May not be supported on all platforms.
final bool showTitle;
}

/// Options for [launchUrl].
@immutable
class LaunchOptions {
/// Creates a new parameter object with the given options.
const LaunchOptions({
this.mode = PreferredLaunchMode.platformDefault,
this.webViewConfiguration = const InAppWebViewConfiguration(),
this.browserConfiguration = const InAppBrowserConfiguration(),
this.webOnlyWindowName,
});

Expand All @@ -66,6 +79,9 @@ class LaunchOptions {
/// Configuration for the web view in [PreferredLaunchMode.inAppWebView] mode.
final InAppWebViewConfiguration webViewConfiguration;

/// Configuration for the browser view in [PreferredLaunchMode.inAppBrowserView] mode.
final InAppBrowserConfiguration browserConfiguration;

/// A web-platform-specific option to set the link target.
///
/// Default behaviour when unset should be to open the url in a new tab.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ repository: https://github.com/flutter/packages/tree/main/packages/url_launcher/
issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+url_launcher%22
# NOTE: We strongly prefer non-breaking changes, even at the expense of a
# less-clean API. See https://flutter.dev/go/platform-interface-breaking-changes
version: 2.2.1
version: 2.3.0

environment:
sdk: ">=3.0.0 <4.0.0"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// Copyright 2013 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

import 'package:flutter_test/flutter_test.dart';
import 'package:url_launcher_platform_interface/url_launcher_platform_interface.dart';

void main() {
test('InAppBrowserConfiguration defaults to showTitle false', () {
expect(const InAppBrowserConfiguration().showTitle, false);
});

test('InAppBrowserConfiguration showTitle can be set to true', () {
expect(const InAppBrowserConfiguration(showTitle: true).showTitle, true);
});
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// Copyright 2013 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

import 'package:flutter_test/flutter_test.dart';
import 'package:url_launcher_platform_interface/url_launcher_platform_interface.dart';

void main() {
test('LaunchOptions have default InAppBrowserConfiguration when not passed',
() {
expect(
const LaunchOptions().browserConfiguration,
const InAppBrowserConfiguration(),
);
});

test('passing non-default InAppBrowserConfiguration to LaunchOptions works',
() {
const InAppBrowserConfiguration browserConfiguration =
InAppBrowserConfiguration(showTitle: true);

const LaunchOptions launchOptions = LaunchOptions(
browserConfiguration: browserConfiguration,
);

expect(launchOptions.browserConfiguration, browserConfiguration);
});
}

0 comments on commit 7beab0d

Please sign in to comment.