Skip to content

Commit

Permalink
Merge pull request #769 from enisn/chips
Browse files Browse the repository at this point in the history
SelfDestruct logic for Chips
  • Loading branch information
enisn authored Sep 22, 2024
2 parents 99ece7e + a61a387 commit 8bee15b
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 deletions.
34 changes: 34 additions & 0 deletions src/UraniumUI.Material/Controls/Chip.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,17 @@ public Chip()
{
DestroyCommand?.Execute(this);
DestroyClicked?.Invoke(this, new EventArgs());
if (SelfDestruct)
{
if(this.Parent is Layout layout)
{
layout.Remove(this);
}
if (this.Parent is ContentView cv)
{
cv.Content = null;
}
}
});
}

Expand Down Expand Up @@ -100,5 +111,28 @@ public Chip()
chip.label.TextColor = (Color)newValue;
}
});

public bool SelfDestruct { get => (bool)GetValue(SelfDestructProperty); set => SetValue(SelfDestructProperty, value); }

public static readonly BindableProperty SelfDestructProperty = BindableProperty.Create(
nameof(SelfDestruct),
typeof(bool),
typeof(Chip),
defaultValue: true);

public bool IsDestroyVisible { get => (bool)GetValue(IsDestroyVisibleProperty); set => SetValue(IsDestroyVisibleProperty, value); }

public static readonly BindableProperty IsDestroyVisibleProperty = BindableProperty.Create(
nameof(IsDestroyVisible),
typeof(bool),
typeof(Chip),
defaultValue: true,
propertyChanged: (bindable, oldValue, newValue) =>
{
if (bindable is Chip chip)
{
chip.closeButton.IsVisible = (bool)newValue;
}
});
}
}
1 change: 1 addition & 0 deletions src/UraniumUI.Material/Controls/MultiplePickerField.cs
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ protected FlexLayout CreateLayout()
{
var chip = new Chip();
chip.SetBinding(Chip.TextProperty, new Binding("."));
chip.SelfDestruct = false;
chip.DestroyCommand = _destroyChipCommand;
return chip;
}));
Expand Down

0 comments on commit 8bee15b

Please sign in to comment.