Skip to content

Commit

Permalink
Delete all toMap methods for options since they are no longer used
Browse files Browse the repository at this point in the history
  • Loading branch information
droibit committed Nov 28, 2023
1 parent 585e480 commit 807e6bd
Show file tree
Hide file tree
Showing 17 changed files with 45 additions and 186 deletions.
6 changes: 2 additions & 4 deletions flutter_custom_tabs/test/launcher_lite_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,11 @@ void main() {
}
});

test('launchUrl() launch with complete options', () async {
test('launchUrl() launch with options', () async {
final url = Uri.parse('http://example.com/');
const prefersDeepLink = true;
const options = LaunchOptions(
barColor: Color(0xFFFFFFFF),
onBarColor: Color(0xFFFFFFFE),
appBarFixed: true,
appBarFixed: false,
);
mock.setLaunchExpectations(
url: url.toString(),
Expand Down
20 changes: 1 addition & 19 deletions flutter_custom_tabs/test/launcher_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -55,32 +55,14 @@ void main() {
}
});

test('launchUrl() launch with basic options', () async {
test('launchUrl() launch with options', () async {
final url = Uri.parse('http://example.com/');
const prefersDeepLink = true;
const customTabsOptions = CustomTabsOptions(
colorSchemes: CustomTabsColorSchemes(
defaultPrams: CustomTabsColorSchemeParams(
toolbarColor: Color(0xFFFFEBEE),
),
),
urlBarHidingEnabled: true,
shareState: CustomTabsShareState.off,
showTitle: true,
instantAppsEnabled: false,
animations: CustomTabsAnimations(
startEnter: '_startEnter',
startExit: '_startExit',
endEnter: '_endEnter',
endExit: '_endExit',
),
);
const safariVCOptions = SafariViewControllerOptions(
preferredBarTintColor: Color(0xFFFFEBEE),
preferredControlTintColor: Color(0xFFFFFFFF),
barCollapsingEnabled: true,
entersReaderIfAvailable: false,
dismissButtonStyle: SafariViewControllerDismissButtonStyle.close,
);
mock.setLaunchExpectations(
url: url.toString(),
Expand Down
28 changes: 22 additions & 6 deletions flutter_custom_tabs/test/mocks/mock_custom_tabs_platform.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import 'package:flutter_custom_tabs/flutter_custom_tabs.dart';
import 'package:flutter_custom_tabs_platform_interface/flutter_custom_tabs_platform_interface.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:plugin_platform_interface/plugin_platform_interface.dart';
Expand All @@ -7,17 +8,17 @@ class MockCustomTabsPlatform extends Fake
implements CustomTabsPlatform {
String? url;
bool? prefersDeepLink;
PlatformOptions? customTabsOptions;
PlatformOptions? safariVCOptions;
CustomTabsOptions? customTabsOptions;
SafariViewControllerOptions? safariVCOptions;

bool launchUrlCalled = false;
bool closeAllIfPossibleCalled = false;

void setLaunchExpectations({
required String url,
bool? prefersDeepLink,
PlatformOptions? customTabsOptions,
PlatformOptions? safariVCOptions,
CustomTabsOptions? customTabsOptions,
SafariViewControllerOptions? safariVCOptions,
}) {
this.url = url;
this.prefersDeepLink = prefersDeepLink;
Expand All @@ -34,8 +35,23 @@ class MockCustomTabsPlatform extends Fake
}) async {
expect(urlString, url);
expect(prefersDeepLink, this.prefersDeepLink);
expect(customTabsOptions?.toMap(), this.customTabsOptions?.toMap());
expect(safariVCOptions?.toMap(), this.safariVCOptions?.toMap());

if (customTabsOptions is CustomTabsOptions) {
expect(
customTabsOptions.urlBarHidingEnabled,
this.customTabsOptions!.urlBarHidingEnabled,
);
} else {
expect(customTabsOptions, isNull);
}
if (safariVCOptions is SafariViewControllerOptions) {
expect(
safariVCOptions.barCollapsingEnabled,
this.safariVCOptions!.barCollapsingEnabled,
);
} else {
expect(safariVCOptions, isNull);
}
launchUrlCalled = true;
}

Expand Down
9 changes: 7 additions & 2 deletions flutter_custom_tabs_android/lib/src/message_converters.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import 'dart:math';

import 'package:flutter/painting.dart';

import 'types/types.dart';
Expand Down Expand Up @@ -78,11 +80,14 @@ extension CustomTabsColorSchemeParamsConverter on CustomTabsColorSchemeParams {
extension PartialCustomTabsConfigurationConverter
on PartialCustomTabsConfiguration {
PartialCustomTabsConfigurationMessage toMessage() {
return PartialCustomTabsConfigurationMessage(
final message = PartialCustomTabsConfigurationMessage(
initialHeight: initialHeight,
activityHeightResizeBehavior: activityHeightResizeBehavior.rawValue,
cornerRadius: cornerRadius,
);
if (cornerRadius != null) {
message.cornerRadius = min(cornerRadius!, 16);
}
return message;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,20 +31,6 @@ class CustomTabsAnimations {

/// Resource ID of the exit "exit" animation for the custom tab.
final String? endExit;

@internal
Map<String, String> toMap() {
final dest = <String, String>{};
if (startEnter != null && startExit != null) {
dest['startEnter'] = startEnter!;
dest['startExit'] = startExit!;
}
if (endEnter != null && endExit != null) {
dest['endEnter'] = endEnter!;
dest['endExit'] = endExit!;
}
return dest;
}
}

/// Build-in enter and exit animations for Custom Tabs.
Expand Down
10 changes: 0 additions & 10 deletions flutter_custom_tabs_android/lib/src/types/custom_tabs_browser.dart
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,4 @@ class CustomTabsBrowserConfiguration {

/// Extra HTTP request headers.
final Map<String, String>? headers;

@internal
Map<String, dynamic> toMap() {
return <String, dynamic>{
if (prefersDefaultBrowser != null)
'prefersDefaultBrowser': prefersDefaultBrowser!,
if (fallbackCustomTabs != null) 'fallbackCustomTabs': fallbackCustomTabs,
if (headers != null) 'headers': headers,
};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,6 @@ class CustomTabsCloseButton {

/// The position of the close button on the custom tab.
final CustomTabsCloseButtonPosition? position;

@internal
Map<String, dynamic> toMap() {
return <String, dynamic>{
if (icon != null) 'icon': icon,
if (position != null) 'position': position!.rawValue,
};
}
}

/// The position of the close button on the custom tab.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,17 +40,6 @@ class CustomTabsColorSchemes {
/// If there is no [CustomTabsColorSchemeParams] for the current scheme,
/// or a particular field of it is null, Custom Tabs will fall back to the defaults provided via [defaultPrams].
final CustomTabsColorSchemeParams? defaultPrams;

@internal
Map<String, dynamic> toMap() {
return <String, dynamic>{
if (colorScheme != null) 'colorScheme': colorScheme!.rawValue,
if (lightParams != null) 'lightColorSchemeParams': lightParams!.toMap(),
if (darkParams != null) 'darkColorSchemeParams': darkParams!.toMap(),
if (defaultPrams != null)
'defaultColorSchemeParams': defaultPrams!.toMap()
};
}
}

/// Desired color scheme on a custom tab.
Expand Down Expand Up @@ -92,19 +81,6 @@ class CustomTabsColorSchemeParams {

/// Navigation bar divider color.
final Color? navigationBarDividerColor;

@internal
Map<String, String> toMap() {
return <String, String>{
if (toolbarColor != null)
'toolbarColor': '#${toolbarColor!.value.toRadixString(16)}',
if (navigationBarColor != null)
'navigationBarColor': '#${navigationBarColor!.value.toRadixString(16)}',
if (navigationBarDividerColor != null)
'navigationBarDividerColor':
'#${navigationBarDividerColor!.value.toRadixString(16)}',
};
}
}

extension BrightnessToColorScheme on Brightness {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,6 @@ class CustomTabsOptions implements PlatformOptions {

/// The configuration for Partial Custom Tabs.
final PartialCustomTabsConfiguration? partial;

/// Converts the [CustomTabsOptions] instance into a [Map] instance for serialization.
@override
Map<String, dynamic> toMap() => {};
}

/// The share state that should be applied to the custom tab.
Expand Down
12 changes: 0 additions & 12 deletions flutter_custom_tabs_android/lib/src/types/partial_custom_tabs.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import 'dart:math';

import 'package:meta/meta.dart';

/// The configuration for [Partial Custom Tabs](https://developer.chrome.com/docs/android/custom-tabs/guide-partial-custom-tabs/).
Expand All @@ -24,16 +22,6 @@ class PartialCustomTabsConfiguration {
///
/// *The maximum corner radius is 16dp(lp).
final int? cornerRadius;

@internal
Map<String, dynamic> toMap() {
final dest = <String, dynamic>{
'initialHeightDp': initialHeight,
'activityHeightResizeBehavior': activityHeightResizeBehavior.rawValue,
if (cornerRadius != null) 'cornerRadiusDp': min(cornerRadius!, 16)
};
return dest;
}
}

/// Desired height behavior for the custom tab.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ void main() {
expect(CustomTabsPlatform.instance, isA<CustomTabsPluginAndroid>());
});

test('launch() invoke method "launch" with CustomTabsOptions', () async {
test('launch() invoke method "launch" with valid options', () async {
const url = 'http://example.com/';
const prefersDeepLink = true;
const options = CustomTabsOptions(
Expand All @@ -41,18 +41,14 @@ void main() {
test('launch() invoke method "launch" with invalid options', () async {
const url = 'http://example.com/';
const prefersDeepLink = true;
const options = _Options(
urlBarHidingEnabled: true,
);
api.setLaunchExpectations(
url: url,
prefersDeepLink: prefersDeepLink,
options: options,
);

await customTabs.launch(
'http://example.com/',
prefersDeepLink: false,
url,
prefersDeepLink: prefersDeepLink,
customTabsOptions: const _Options(
urlBarHidingEnabled: true,
),
Expand Down Expand Up @@ -113,10 +109,4 @@ class _Options implements PlatformOptions {
const _Options({
this.urlBarHidingEnabled,
});

@override
Map<String, dynamic> toMap() => {
if (urlBarHidingEnabled != null)
'urlBarHidingEnabled': urlBarHidingEnabled,
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -60,28 +60,6 @@ class SafariViewControllerOptions implements PlatformOptions {

/// The page sheet configuration.
final SheetPresentationControllerConfiguration? pageSheet;

/// Converts the [SafariViewControllerOptions] instance into a [Map] instance for serialization.
@override
Map<String, dynamic> toMap() {
return <String, dynamic>{
if (preferredBarTintColor != null)
'preferredBarTintColor':
'#${preferredBarTintColor!.value.toRadixString(16)}',
if (preferredControlTintColor != null)
'preferredControlTintColor':
'#${preferredControlTintColor!.value.toRadixString(16)}',
if (barCollapsingEnabled != null)
'barCollapsingEnabled': barCollapsingEnabled,
if (entersReaderIfAvailable != null)
'entersReaderIfAvailable': entersReaderIfAvailable,
if (modalPresentationStyle != null)
'modalPresentationStyle': modalPresentationStyle!.rawValue,
if (dismissButtonStyle != null)
'dismissButtonStyle': dismissButtonStyle!.rawValue,
if (pageSheet != null) 'pageSheet': pageSheet!.toMap(),
};
}
}

/// Dismiss button style on the navigation bar of [SFSafariViewController](https://developer.apple.com/documentation/safariservices/sfsafariviewcontroller).
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,26 +35,6 @@ class SheetPresentationControllerConfiguration {

/// The corner radius that the sheet attempts to present with.
final double? preferredCornerRadius;

@internal
Map<String, dynamic> toMap() {
return <String, dynamic>{
'detents': detents.map((e) => e.rawValue).toList(),
if (largestUndimmedDetentIdentifier != null)
'largestUndimmedDetentIdentifier':
largestUndimmedDetentIdentifier!.rawValue,
if (prefersScrollingExpandsWhenScrolledToEdge != null)
'prefersScrollingExpandsWhenScrolledToEdge':
prefersScrollingExpandsWhenScrolledToEdge,
if (prefersGrabberVisible != null)
'prefersGrabberVisible': prefersGrabberVisible,
if (prefersEdgeAttachedInCompactHeight != null)
'prefersEdgeAttachedInCompactHeight':
prefersEdgeAttachedInCompactHeight,
if (preferredCornerRadius != null)
'preferredCornerRadius': preferredCornerRadius,
};
}
}

/// An object that represents a height where a sheet naturally rests.
Expand Down
Loading

0 comments on commit 807e6bd

Please sign in to comment.