Skip to content

Commit

Permalink
Add closeButtonPosition option to CustomTabsOption
Browse files Browse the repository at this point in the history
  • Loading branch information
droibit committed Aug 31, 2023
1 parent d0395a8 commit 03e3ae1
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ class CustomTabsFactory {
private static final String KEY_OPTIONS_DEFAULT_SHARE_MENU_ITEM = "enableDefaultShare";
private static final String KEY_OPTIONS_ENABLE_INSTANT_APPS = "enableInstantApps";
private static final String KEY_OPTIONS_ANIMATIONS = "animations";
private static final String KEY_CLOSE_BUTTON_POSITION = "closeButtonPosition";
private static final String KEY_HEADERS = "headers";
private static final String KEY_ANIMATION_START_ENTER = "startEnter";
private static final String KEY_ANIMATION_START_EXIT = "startExit";
Expand Down Expand Up @@ -74,6 +75,11 @@ CustomTabsIntent createIntent(@NonNull Map<String, Object> options) {
applyAnimations(builder, ((Map<String, String>) options.get(KEY_OPTIONS_ANIMATIONS)));
}

if (options.containsKey(KEY_CLOSE_BUTTON_POSITION)) {
final int position = (int) options.get(KEY_CLOSE_BUTTON_POSITION);
builder.setCloseButtonPosition(position);
}

final CustomTabsIntent customTabsIntent = builder.build();
onPostBuild(customTabsIntent.intent, options);
return customTabsIntent;
Expand Down
1 change: 1 addition & 0 deletions flutter_custom_tabs/lib/flutter_custom_tabs.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
export 'package:flutter_custom_tabs_platform_interface/flutter_custom_tabs_platform_interface.dart'
show
CustomTabsOption,
CustomTabsCloseButtonPosition,
SafariViewControllerOption,
SafariViewControllerDismissButtonStyle;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ class CustomTabsOption {
this.enableDefaultShare,
this.showPageTitle,
this.enableInstantApps,
this.closeButtonPosition,
this.animation,
this.extraCustomTabs,
this.headers,
Expand All @@ -36,6 +37,9 @@ class CustomTabsOption {
/// If enabled, allow custom tab to use [Instant Apps](https://developer.android.com/topic/instant-apps/index.html).
final bool? enableInstantApps;

/// The position of the close button of Custom Tabs.
final CustomTabsCloseButtonPosition? closeButtonPosition;

/// Enter and exit animation.
final CustomTabsAnimation? animation;

Expand Down Expand Up @@ -69,6 +73,9 @@ class CustomTabsOption {
if (extraCustomTabs != null) {
dest['extraCustomTabs'] = extraCustomTabs;
}
if (closeButtonPosition != null) {
dest['closeButtonPosition'] = closeButtonPosition!.rawValue;
}
if (headers != null) {
dest['headers'] = headers;
}
Expand Down Expand Up @@ -124,3 +131,19 @@ class CustomTabsAnimation {
return dest;
}
}

/// The position of the close button of Custom Tabs.
enum CustomTabsCloseButtonPosition { start, end }

extension CustomTabsCloseButtonPositionRawValue
on CustomTabsCloseButtonPosition {
@visibleForTesting
int get rawValue {
switch (this) {
case CustomTabsCloseButtonPosition.start:
return 1;
case CustomTabsCloseButtonPosition.end:
return 2;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,8 @@ class SafariViewControllerOption {
/// Dismiss button style on the navigation bar of SafariViewController.
enum SafariViewControllerDismissButtonStyle { done, close, cancel }

extension RawValueCompatible on SafariViewControllerDismissButtonStyle {
extension SafariViewControllerDismissButtonStyleRawValue
on SafariViewControllerDismissButtonStyle {
@visibleForTesting
int get rawValue {
switch (this) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ void main() {
enableDefaultShare: false,
showPageTitle: true,
enableInstantApps: false,
closeButtonPosition: CustomTabsCloseButtonPosition.end,
animation: CustomTabsAnimation(
startEnter: '_startEnter',
startExit: '_startExit',
Expand All @@ -35,6 +36,7 @@ void main() {
'enableDefaultShare': false,
'showPageTitle': true,
'enableInstantApps': false,
'closeButtonPosition': 2,
'animations': <String, String>{
'startEnter': '_startEnter',
'startExit': '_startExit',
Expand All @@ -47,4 +49,9 @@ void main() {
],
});
});

test('CustomTabsCloseButtonPosition.rawValue return associated value', () {
expect(CustomTabsCloseButtonPosition.start.rawValue, 1);
expect(CustomTabsCloseButtonPosition.end.rawValue, 2);
});
}

0 comments on commit 03e3ae1

Please sign in to comment.