Skip to content

Commit

Permalink
Added SetCommandsWithDisposing to BindableViewHolder
Browse files Browse the repository at this point in the history
  • Loading branch information
Pavel Leonenko committed Jul 4, 2024
1 parent 9e39d79 commit 2b09c9b
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions Softeq.XToolkit.Bindings.Droid/Bindable/BindableViewHolder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using AndroidX.RecyclerView.Widget;
using Softeq.XToolkit.Bindings.Abstract;
using Softeq.XToolkit.Bindings.Extensions;
using Softeq.XToolkit.Common.Extensions;
using Softeq.XToolkit.Common.Weak;

#nullable disable
Expand All @@ -16,6 +17,8 @@ namespace Softeq.XToolkit.Bindings.Droid.Bindable
public abstract class BindableViewHolder<TViewModel>
: RecyclerView.ViewHolder, IBindableViewHolder
{
private readonly List<IDisposable> _commandsSubscriptions = new();

private IDisposable _itemViewClickSubscription;

protected BindableViewHolder(View itemView) : base(itemView)
Expand Down Expand Up @@ -63,11 +66,21 @@ protected virtual void OnItemViewClick(object sender, EventArgs e)

public virtual void DoAttachBindings()
{
var commandsSubscriptions = SetCommandsWithDisposing();
_commandsSubscriptions.AddRange(commandsSubscriptions);
}

public virtual void DoDetachBindings()
{
this.DetachBindings();

_commandsSubscriptions.Apply(x => x.Dispose());
_commandsSubscriptions.Clear();
}

protected virtual IEnumerable<IDisposable> SetCommandsWithDisposing()
{
return [];
}
}
}

0 comments on commit 2b09c9b

Please sign in to comment.