Skip to content

Commit

Permalink
Migrate from enableUrlBarHiding to urlBarHidingEnabled in `Custom…
Browse files Browse the repository at this point in the history
…TabsOptions`
  • Loading branch information
droibit committed Sep 12, 2023
1 parent 0aa8c26 commit 118cb3c
Show file tree
Hide file tree
Showing 8 changed files with 23 additions and 22 deletions.
2 changes: 1 addition & 1 deletion flutter_custom_tabs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ class MyApp extends StatelessWidget {
customTabsOptions: CustomTabsOptions(
toolbarColor: Theme.of(context).primaryColor,
enableDefaultShare: true,
enableUrlBarHiding: true,
urlBarHidingEnabled: true,
showPageTitle: true,
animation: CustomTabsAnimation.slideIn(),
// or user defined animation.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.github.droibit.flutter.plugins.customtabs;

import android.annotation.SuppressLint;
import android.content.Context;
import android.content.Intent;
import android.graphics.Color;
Expand All @@ -22,7 +23,7 @@
@RestrictTo(RestrictTo.Scope.LIBRARY)
class CustomTabsFactory {
private static final String KEY_OPTIONS_TOOLBAR_COLOR = "toolbarColor";
private static final String KEY_OPTIONS_ENABLE_URL_BAR_HIDING = "enableUrlBarHiding";
private static final String KEY_OPTIONS_URL_BAR_HIDING_ENABLED = "urlBarHidingEnabled";
private static final String KEY_OPTIONS_SHOW_PAGE_TITLE = "showPageTitle";
private static final String KEY_OPTIONS_DEFAULT_SHARE_MENU_ITEM = "enableDefaultShare";
private static final String KEY_OPTIONS_ENABLE_INSTANT_APPS = "enableInstantApps";
Expand Down Expand Up @@ -53,9 +54,8 @@ CustomTabsIntent createIntent(@NonNull Map<String, Object> options) {
builder.setToolbarColor(Color.parseColor(colorString));
}

if (options.containsKey(KEY_OPTIONS_ENABLE_URL_BAR_HIDING) &&
((Boolean) options.get(KEY_OPTIONS_ENABLE_URL_BAR_HIDING))) {
builder.enableUrlBarHiding();
if (options.containsKey(KEY_OPTIONS_URL_BAR_HIDING_ENABLED)) {
builder.setUrlBarHidingEnabled(((Boolean) options.get(KEY_OPTIONS_URL_BAR_HIDING_ENABLED)));
}

if (options.containsKey(KEY_OPTIONS_DEFAULT_SHARE_MENU_ITEM) &&
Expand Down Expand Up @@ -100,26 +100,27 @@ private void applyAnimations(@NonNull CustomTabsIntent.Builder builder,
@NonNull Map<String, String> animations) {
final int startEnterAnimationId =
animations.containsKey(KEY_ANIMATION_START_ENTER) ? resolveAnimationIdentifierIfNeeded(
animations.get(KEY_ANIMATION_START_ENTER)) : -1;
animations.get(KEY_ANIMATION_START_ENTER)) : 0;
final int startExitAnimationId =
animations.containsKey(KEY_ANIMATION_START_EXIT) ? resolveAnimationIdentifierIfNeeded(
animations.get(KEY_ANIMATION_START_EXIT)) : -1;
animations.get(KEY_ANIMATION_START_EXIT)) : 0;
final int endEnterAnimationId =
animations.containsKey(KEY_ANIMATION_END_ENTER) ? resolveAnimationIdentifierIfNeeded(
animations.get(KEY_ANIMATION_END_ENTER)) : -1;
animations.get(KEY_ANIMATION_END_ENTER)) : 0;
final int endExitAnimationId =
animations.containsKey(KEY_ANIMATION_END_EXIT) ? resolveAnimationIdentifierIfNeeded(
animations.get(KEY_ANIMATION_END_EXIT)) : -1;
animations.get(KEY_ANIMATION_END_EXIT)) : 0;

if (startEnterAnimationId != -1 && startExitAnimationId != -1) {
if (startEnterAnimationId != 0 && startExitAnimationId != 0) {
builder.setStartAnimations(context, startEnterAnimationId, startExitAnimationId);
}

if (endEnterAnimationId != -1 && endExitAnimationId != -1) {
if (endEnterAnimationId != 0 && endExitAnimationId != 0) {
builder.setExitAnimations(context, endEnterAnimationId, endExitAnimationId);
}
}

@SuppressLint("DiscouragedApi")
@AnimRes
private int resolveAnimationIdentifierIfNeeded(@NonNull String identifier) {
if (animationIdentifierPattern.matcher(identifier).find()) {
Expand Down
2 changes: 1 addition & 1 deletion flutter_custom_tabs/example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ class MyApp extends StatelessWidget {
customTabsOptions: CustomTabsOptions(
toolbarColor: theme.primaryColor,
enableDefaultShare: true,
enableUrlBarHiding: true,
urlBarHidingEnabled: true,
showPageTitle: true,
animation: CustomTabsSystemAnimation.slideIn(),
extraCustomTabs: const <String>[
Expand Down
2 changes: 1 addition & 1 deletion flutter_custom_tabs/lib/src/launcher.dart
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import 'package:flutter_custom_tabs_platform_interface/flutter_custom_tabs_platf
/// 'https://flutter.io',
/// customTabsOptions: CustomTabsOptions(
/// toolbarColor: Theme.of(context).primaryColor,
/// enableUrlBarHiding: true,
/// urlBarHidingEnabled: true,
/// showPageTitle: true,
/// animation: CustomTabsAnimation.slideIn(),
/// extraCustomTabs: <String>[
Expand Down
2 changes: 1 addition & 1 deletion flutter_custom_tabs/test/launcher_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ void main() {

const customTabsOptions = CustomTabsOptions(
toolbarColor: Color(0xFFFFEBEE),
enableUrlBarHiding: true,
urlBarHidingEnabled: true,
enableDefaultShare: false,
showPageTitle: true,
enableInstantApps: false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import 'package:meta/meta.dart';
class CustomTabsOptions {
const CustomTabsOptions({
this.toolbarColor,
this.enableUrlBarHiding,
this.urlBarHidingEnabled,
this.enableDefaultShare,
this.showPageTitle,
this.enableInstantApps,
Expand All @@ -26,7 +26,7 @@ class CustomTabsOptions {
final Color? toolbarColor;

/// If enabled, hides the toolbar when the user scrolls down the page.
final bool? enableUrlBarHiding;
final bool? urlBarHidingEnabled;

/// If enabled, default sharing menu is added.
final bool? enableDefaultShare;
Expand Down Expand Up @@ -55,8 +55,8 @@ class CustomTabsOptions {
if (toolbarColor != null) {
dest['toolbarColor'] = '#${toolbarColor!.value.toRadixString(16)}';
}
if (enableUrlBarHiding != null) {
dest['enableUrlBarHiding'] = enableUrlBarHiding;
if (urlBarHidingEnabled != null) {
dest['urlBarHidingEnabled'] = urlBarHidingEnabled;
}
if (enableDefaultShare != null) {
dest['enableDefaultShare'] = enableDefaultShare;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ void main() {
test('toMap() with full option', () {
const options = CustomTabsOptions(
toolbarColor: Color(0xFFFFEBEE),
enableUrlBarHiding: true,
urlBarHidingEnabled: true,
enableDefaultShare: false,
showPageTitle: true,
enableInstantApps: false,
Expand All @@ -32,7 +32,7 @@ void main() {

expect(options.toMap(), <String, dynamic>{
'toolbarColor': '#ffffebee',
'enableUrlBarHiding': true,
'urlBarHidingEnabled': true,
'enableDefaultShare': false,
'showPageTitle': true,
'enableInstantApps': false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ void main() {
await customTabs.launch(
'http://example.com/',
customTabsOptions: const CustomTabsOptions(
enableUrlBarHiding: true,
urlBarHidingEnabled: true,
),
safariVCOptions: const SafariViewControllerOptions(
barCollapsingEnabled: false,
Expand All @@ -50,7 +50,7 @@ void main() {
isMethodCall('launch', arguments: <String, dynamic>{
'url': 'http://example.com/',
'customTabsOptions': const <String, dynamic>{
'enableUrlBarHiding': true,
'urlBarHidingEnabled': true,
},
'safariVCOptions': const <String, dynamic>{
'barCollapsingEnabled': false
Expand Down

0 comments on commit 118cb3c

Please sign in to comment.