Skip to content
This repository has been archived by the owner on May 1, 2024. It is now read-only.

Fix badge view default text "0" #1959

Merged
merged 1 commit into from
Apr 2, 2023

Conversation

FedericoNembrini
Copy link
Contributor

Description of Bug

BadgeView default Text value is never set.

The Text property has a default value of 0, but it is never set to the actual label. This prevents the BadgeView from being displayed if it is bound to a property with a value of 0 and AutoHide is set to false.

Issues Fixed

Before

After

PR Checklist

  • Has a linked Issue, and the Issue has been approved
  • Has tests (if omitted, state reason in description)
  • Has samples (if omitted, state reason in description)
  • Rebased on top of main at time of PR
  • Changes adhere to coding standard
  • Updated documentation

@FedericoNembrini
Copy link
Contributor Author

@microsoft-github-policy-service agree

Copy link
Contributor

@bijington bijington 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 to me. I haven't had a chance to test with AutoHide set to true, did you manage to test and make sure that functionality still works?

@FedericoNembrini
Copy link
Contributor Author

AutoHide default value is set to true

/// <summary>
/// Backing BindableProperty for the <see cref="AutoHide"/> property.
/// </summary>
public static BindableProperty AutoHideProperty =
BindableProperty.Create(nameof(AutoHide), typeof(bool), typeof(BadgeView), defaultValue: true,
propertyChanged: OnAutoHideChanged);

And BadgeIndicatorContainer visibility is set to false

static Grid CreateIndicatorContainerElement() => new Grid
{
HorizontalOptions = LayoutOptions.Start,
VerticalOptions = LayoutOptions.Start,
IsVisible = false
};

In my test case, the second label is wrapped in a BadgeView and AutoHide is true. When the binded text is changed it is always called UpdateVisibilityAsync.

static async void OnTextChanged(BindableObject bindable, object oldValue, object newValue)
{
if (bindable is BadgeView badgeView)
{
badgeView.UpdateLayout();
await badgeView.UpdateVisibilityAsync();
}
}

As a result, the default behaviour of AutoHide remains unchanged

@bijington bijington merged commit 89a363e into xamarin:main Apr 2, 2023
@bijington
Copy link
Contributor

@FedericoNembrini Thank you for this submission!

@FedericoNembrini FedericoNembrini deleted the badge-view-default-text branch April 2, 2023 14:21
MFinkBK pushed a commit to MFinkBK/XamarinCommunityToolkit that referenced this pull request Apr 11, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Bug] The initial value of property couldn't display correctly on xct:BadgeView when using data binding.
2 participants