Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -117,3 +117,4 @@ virtual Microsoft.Maui.Controls.LongPressingEventArgs.GetPosition(Microsoft.Maui
~static readonly Microsoft.Maui.Controls.ToolbarItem.BadgeTextColorProperty -> Microsoft.Maui.Controls.BindableProperty
~static readonly Microsoft.Maui.Controls.ToolbarItem.BadgeTextProperty -> Microsoft.Maui.Controls.BindableProperty
~virtual Microsoft.Maui.Controls.Platform.Compatibility.ShellItemRenderer.UpdateShellSectionBadge(Microsoft.Maui.Controls.ShellSection shellSection, int index) -> void
override Microsoft.Maui.Controls.SwipeItemView.IsEnabledCore.get -> bool
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#nullable enable
#nullable enable

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This hunk introduces a UTF-8 BOM (U+FEFF) before #nullable enable (net-maccatalyst/PublicAPI.Unshipped.txt gets the identical edit), while the other four PublicAPI.Unshipped.txt files have no BOM — an unintended, inconsistent encoding change unrelated to the leak fix. The Roslyn analyzer tolerates it so it's harmless; re-save both files as UTF-8 without a BOM for consistency.

*REMOVED*~override Microsoft.Maui.Controls.Platform.Compatibility.ShellSectionRootRenderer.TraitCollectionDidChange(UIKit.UITraitCollection previousTraitCollection) -> void
*REMOVED*~static Microsoft.Maui.Controls.VisualStateManager.GetVisualStateGroups(Microsoft.Maui.Controls.VisualElement visualElement) -> System.Collections.Generic.IList<Microsoft.Maui.Controls.VisualStateGroup>
Microsoft.Maui.Controls.AppThemeBinding
Expand Down Expand Up @@ -109,3 +109,4 @@ virtual Microsoft.Maui.Controls.LongPressingEventArgs.GetPosition(Microsoft.Maui
~static readonly Microsoft.Maui.Controls.ToolbarItem.BadgeColorProperty -> Microsoft.Maui.Controls.BindableProperty
~static readonly Microsoft.Maui.Controls.ToolbarItem.BadgeTextColorProperty -> Microsoft.Maui.Controls.BindableProperty
~static readonly Microsoft.Maui.Controls.ToolbarItem.BadgeTextProperty -> Microsoft.Maui.Controls.BindableProperty
override Microsoft.Maui.Controls.SwipeItemView.IsEnabledCore.get -> bool
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#nullable enable
#nullable enable
*REMOVED*~override Microsoft.Maui.Controls.Platform.Compatibility.ShellSectionRootRenderer.TraitCollectionDidChange(UIKit.UITraitCollection previousTraitCollection) -> void
*REMOVED*~static Microsoft.Maui.Controls.VisualStateManager.GetVisualStateGroups(Microsoft.Maui.Controls.VisualElement visualElement) -> System.Collections.Generic.IList<Microsoft.Maui.Controls.VisualStateGroup>
Microsoft.Maui.Controls.AppThemeBinding
Expand Down Expand Up @@ -109,3 +109,4 @@ virtual Microsoft.Maui.Controls.LongPressingEventArgs.GetPosition(Microsoft.Maui
~static readonly Microsoft.Maui.Controls.ToolbarItem.BadgeColorProperty -> Microsoft.Maui.Controls.BindableProperty
~static readonly Microsoft.Maui.Controls.ToolbarItem.BadgeTextColorProperty -> Microsoft.Maui.Controls.BindableProperty
~static readonly Microsoft.Maui.Controls.ToolbarItem.BadgeTextProperty -> Microsoft.Maui.Controls.BindableProperty
override Microsoft.Maui.Controls.SwipeItemView.IsEnabledCore.get -> bool
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ Microsoft.Maui.Controls.LongPressingEventArgs.LongPressingEventArgs(Microsoft.Ma
Microsoft.Maui.Controls.LongPressingEventArgs.Status.get -> Microsoft.Maui.GestureStatus
Microsoft.Maui.Controls.Span.InvalidateStyle() -> void
Microsoft.Maui.Controls.StyleableElement.InvalidateStyle() -> void
override Microsoft.Maui.Controls.SwipeItemView.IsEnabledCore.get -> bool
override Microsoft.Maui.Controls.GraphicsView.OnBindingContextChanged() -> void
override Microsoft.Maui.Controls.Shapes.Shape.OnPropertyChanged(string? propertyName = null) -> void
override Microsoft.Maui.Controls.TitleBar.OnBindingContextChanged() -> void
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,3 +99,4 @@ virtual Microsoft.Maui.Controls.LongPressingEventArgs.GetPosition(Microsoft.Maui
~static readonly Microsoft.Maui.Controls.ToolbarItem.BadgeColorProperty -> Microsoft.Maui.Controls.BindableProperty
~static readonly Microsoft.Maui.Controls.ToolbarItem.BadgeTextColorProperty -> Microsoft.Maui.Controls.BindableProperty
~static readonly Microsoft.Maui.Controls.ToolbarItem.BadgeTextProperty -> Microsoft.Maui.Controls.BindableProperty
override Microsoft.Maui.Controls.SwipeItemView.IsEnabledCore.get -> bool

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[major] Public API Surface — This shared SwipeItemView.IsEnabledCore override was added to most public API baselines, but src/Controls/src/Core/PublicAPI/net-tizen/PublicAPI.Unshipped.txt was not updated. Because SwipeItemView is present in the Tizen Controls API and this override is not platform-guarded, the Tizen API validation baseline should include the same entry or API checks may fail for that TFM.

Original file line number Diff line number Diff line change
Expand Up @@ -90,3 +90,4 @@ virtual Microsoft.Maui.Controls.LongPressingEventArgs.GetPosition(Microsoft.Maui
~static readonly Microsoft.Maui.Controls.ToolbarItem.BadgeColorProperty -> Microsoft.Maui.Controls.BindableProperty
~static readonly Microsoft.Maui.Controls.ToolbarItem.BadgeTextColorProperty -> Microsoft.Maui.Controls.BindableProperty
~static readonly Microsoft.Maui.Controls.ToolbarItem.BadgeTextProperty -> Microsoft.Maui.Controls.BindableProperty
override Microsoft.Maui.Controls.SwipeItemView.IsEnabledCore.get -> bool
49 changes: 16 additions & 33 deletions src/Controls/src/Core/SwipeView/SwipeItemView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,29 @@
using System;
using System.ComponentModel;
using System.Windows.Input;
using Microsoft.Maui.Controls.Internals;

namespace Microsoft.Maui.Controls
{
/// <summary>
/// Represents a swipe item that displays custom content in a <see cref="SwipeView"/>.
/// </summary>
[ContentProperty(nameof(Content))]
public partial class SwipeItemView : ContentView, Controls.ISwipeItem, Maui.ISwipeItemView
public partial class SwipeItemView : ContentView, Controls.ISwipeItem, Maui.ISwipeItemView, ICommandElement
{
/// <summary>Bindable property for <see cref="Command"/>.</summary>
public static readonly BindableProperty CommandProperty = BindableProperty.Create(nameof(Command), typeof(ICommand), typeof(SwipeItemView), null,
propertyChanging: (bo, o, n) => ((SwipeItemView)bo).OnCommandChanging(),
propertyChanged: (bo, o, n) => ((SwipeItemView)bo).OnCommandChanged());
propertyChanging: CommandElement.OnCommandChanging,
propertyChanged: CommandElement.OnCommandChanged);

/// <summary>Bindable property for <see cref="CommandParameter"/>.</summary>
public static readonly BindableProperty CommandParameterProperty = BindableProperty.Create(nameof(CommandParameter), typeof(object), typeof(SwipeItemView), null,
propertyChanged: (bo, o, n) => ((SwipeItemView)bo).OnCommandParameterChanged());
propertyChanged: CommandElement.OnCommandParameterChanged);

static SwipeItemView()
{
CommandProperty.DependsOn(CommandParameterProperty);
}

/// <summary>
/// Gets or sets the command invoked when this swipe item is activated. This is a bindable property.
Expand Down Expand Up @@ -52,35 +58,12 @@ public void OnInvoked()
Invoked?.Invoke(this, EventArgs.Empty);
}

void OnCommandChanged()
{
IsEnabled = Command?.CanExecute(CommandParameter) ?? true;

if (Command == null)
return;

Command.CanExecuteChanged += OnCommandCanExecuteChanged;
}

void OnCommandChanging()
{
if (Command == null)
return;

Command.CanExecuteChanged -= OnCommandCanExecuteChanged;
}

void OnCommandParameterChanged()
{
if (Command == null)
return;
protected override bool IsEnabledCore =>
base.IsEnabledCore && CommandElement.GetCanExecute(this, CommandProperty);

IsEnabled = Command.CanExecute(CommandParameter);
}
void ICommandElement.CanExecuteChanged(object sender, EventArgs e) =>
RefreshIsEnabledProperty();

void OnCommandCanExecuteChanged(object sender, EventArgs eventArgs)
{
IsEnabled = Command.CanExecute(CommandParameter);
}
WeakCommandSubscription ICommandElement.CleanupTracker { get; set; }
}
}
}
5 changes: 5 additions & 0 deletions src/Controls/tests/Core.UnitTests/CommandTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,8 @@ public void ExecuteDoesNotRunIfValueTypeAndSetToNull()
[InlineData(typeof(SearchBar), false)]
[InlineData(typeof(SearchHandler), true)]
[InlineData(typeof(SearchHandler), false)]
[InlineData(typeof(SwipeItemView), true)]
[InlineData(typeof(SwipeItemView), false)]
public async Task CommandsSubscribedToCanExecuteCollect(Type controlType, bool useWeakEventHandler)
{
// Create a view model with a Command
Expand Down Expand Up @@ -310,6 +312,9 @@ public async Task CommandsSubscribedToCanExecuteCollect(Type controlType, bool u
sh.Command = command;
sh.ClearPlaceholderCommand = command;
break;
case SwipeItemView siv:
siv.Command = command;
break;
}

// Create a weak reference to the button
Expand Down
35 changes: 35 additions & 0 deletions src/Controls/tests/Core.UnitTests/SwipeViewTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -414,6 +414,41 @@ public void TestSwipeItemView()
Assert.NotEmpty(swipeView.LeftItems);
}

[Fact]
public void SwipeItemViewCommandCanExecuteUpdatesIsEnabled()
{
var expectedParameter = new object();
var canExecute = false;
var command = new Command(
_ => { },
parameter => canExecute && ReferenceEquals(parameter, expectedParameter));
var swipeItemView = new SwipeItemView
{
CommandParameter = expectedParameter,
Command = command
};

Assert.False(swipeItemView.IsEnabled);

canExecute = true;
command.ChangeCanExecute();

Assert.True(swipeItemView.IsEnabled);

swipeItemView.CommandParameter = new object();

Assert.False(swipeItemView.IsEnabled);

swipeItemView.CommandParameter = expectedParameter;

Assert.True(swipeItemView.IsEnabled);

swipeItemView.IsEnabled = false;
command.ChangeCanExecute();

Assert.False(swipeItemView.IsEnabled);
}

[Fact]
public void SwipeItemsRemainInLogicalTreeWhenContentIsSet()
{
Expand Down
Loading