Skip to content

Commit e197d1a

Browse files
Merge pull request #19 from TheEightBot/develop
Updated activatable list view
2 parents 530b5e8 + 0163340 commit e197d1a

File tree

6 files changed

+16
-75
lines changed

6 files changed

+16
-75
lines changed
Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,23 @@
11
using System.Collections.Concurrent;
22

3-
namespace Stellar.Maui;
3+
namespace Stellar.Maui.Views;
44

55
public class ActivatableListView : ListView
66
{
77
private readonly ConcurrentDictionary<Cell, IDisposable> _cellActivators = new();
88

99
private Action<CompositeDisposable, Cell, int> _cellActivatedAction;
1010

11+
public ActivatableListView()
12+
: this(ListViewCachingStrategy.RecycleElement)
13+
{
14+
}
15+
16+
public ActivatableListView(ListViewCachingStrategy cachingStrategy = ListViewCachingStrategy.RecycleElement)
17+
: base(cachingStrategy)
18+
{
19+
}
20+
1121
public IDisposable SetCellActivationAction(Action<CompositeDisposable, Cell, int> cellActivatedAction)
1222
{
1323
_cellActivatedAction = cellActivatedAction;

Stellar.Maui/Views/ContentViewBase.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
using System.ComponentModel;
22

3-
namespace Stellar.Maui.Pages;
3+
namespace Stellar.Maui.Views;
44

55
public abstract class ContentViewBase<TViewModel> : ReactiveContentView<TViewModel>, IStellarView<TViewModel>
66
where TViewModel : class

Stellar.Maui/Views/GridBase.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System.ComponentModel;
2+
using ReactiveUI.Maui.Views;
23

34
namespace Stellar.Maui.Views;
45

Stellar.Maui/Views/ReactiveGrid.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
namespace ReactiveUI.Maui;
1+
namespace ReactiveUI.Maui.Views;
22

33
/// <summary>
44
/// This is an <see cref="Grid"/> that is also an <see cref="IViewFor{T}"/>.
Lines changed: 1 addition & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,9 @@
11
using System.Collections.Concurrent;
2-
using System.Runtime.CompilerServices;
3-
using Microsoft.Maui.Controls;
42

53
namespace Stellar.Maui.Views;
64

7-
public class ReactiveListView : ListView
5+
public class ReactiveListView : ActivatableListView
86
{
9-
private readonly ConcurrentDictionary<Cell, IDisposable> _cellActivators = new ConcurrentDictionary<Cell, IDisposable>();
10-
11-
private Action<CompositeDisposable, Cell, int>? _cellActivatedAction;
12-
137
public ReactiveListView(Type cellType, ListViewCachingStrategy cachingStrategy = ListViewCachingStrategy.RecycleElement)
148
: this(cachingStrategy)
159
{
@@ -26,68 +20,4 @@ public ReactiveListView(ListViewCachingStrategy cachingStrategy = ListViewCachin
2620
: base(cachingStrategy)
2721
{
2822
}
29-
30-
public IDisposable SetCellActivationAction(Action<CompositeDisposable, Cell, int> cellActivatedAction)
31-
{
32-
_cellActivatedAction = cellActivatedAction;
33-
34-
return Disposable.Create(
35-
() =>
36-
{
37-
_cellActivatedAction = null;
38-
39-
foreach (var cellItem in _cellActivators)
40-
{
41-
cellItem.Value?.Dispose();
42-
}
43-
44-
_cellActivators.Clear();
45-
});
46-
}
47-
48-
protected override void SetupContent(Cell content, int index)
49-
{
50-
base.SetupContent(content, index);
51-
52-
if (_cellActivatedAction is not null && !_cellActivators.ContainsKey(content))
53-
{
54-
var disposable = new CompositeDisposable();
55-
_cellActivatedAction(disposable, content, index);
56-
_cellActivators.AddOrUpdate(content, disposable, (_, _) => disposable);
57-
}
58-
}
59-
60-
protected override void UnhookContent(Cell content)
61-
{
62-
if (_cellActivators.ContainsKey(content) && _cellActivators.TryRemove(content, out var disposable))
63-
{
64-
disposable?.Dispose();
65-
}
66-
67-
base.UnhookContent(content);
68-
}
69-
70-
protected override void OnHandlerChanging(HandlerChangingEventArgs args)
71-
{
72-
if (args.NewHandler is null || _cellActivators.IsEmpty)
73-
{
74-
return;
75-
}
76-
77-
foreach (var key in _cellActivators.Keys.ToArray())
78-
{
79-
if (_cellActivators.TryRemove(key, out var disposable))
80-
{
81-
disposable?.Dispose();
82-
}
83-
}
84-
}
85-
}
86-
87-
public static class ReactiveListViewExtensions
88-
{
89-
public static IDisposable WhenCellActivated(this ReactiveListView reactiveList, Action<CompositeDisposable, Cell, int> whenCellActivated)
90-
{
91-
return reactiveList.SetCellActivationAction(whenCellActivated);
92-
}
9323
}

Stellar.Maui/Views/StackLayoutBase.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ protected override void OnPropertyChanged(string? propertyName = null)
5959
}
6060
}
6161

62-
public abstract class StackLayoutBase<TViewModel, TDataModel> : ReactiveGrid<TViewModel>, IStellarView<TViewModel>
62+
public abstract class StackLayoutBase<TViewModel, TDataModel> : ReactiveStackLayout<TViewModel>, IStellarView<TViewModel>
6363
where TViewModel : class
6464
{
6565
[EditorBrowsable(EditorBrowsableState.Never)]

0 commit comments

Comments
 (0)