Skip to content

Commit

Permalink
Merge pull request #41 from DominicGenetec/main
Browse files Browse the repository at this point in the history
Added a flag to prevent clearing the ViewPool when parent size changed
  • Loading branch information
AndreiMisiukevich authored Dec 6, 2024
2 parents 60e6531 + edb7ea3 commit 882f18a
Showing 1 changed file with 18 additions and 12 deletions.
30 changes: 18 additions & 12 deletions PanCardView/Common/CardsView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,9 @@ public class CardsView : Grid

public static readonly BindableProperty ItemTemplateProperty = BindableProperty.Create(nameof(ItemTemplate), typeof(DataTemplate), typeof(CardsView), propertyChanged: (bindable, oldValue, newValue) =>
{
bindable.AsCardsView().ForceRedrawViews();
var cardView = bindable.AsCardsView();
cardView.OnItemTemplateChanged();
cardView.ForceRedrawViews();
});

public static readonly BindableProperty BackViewsDepthProperty = BindableProperty.Create(nameof(BackViewsDepth), typeof(int), typeof(CardsView), defaultValueCreator: b => b.AsCardsView().DefaultBackViewsDepth, propertyChanged: (bindable, oldValue, newValue) =>
Expand Down Expand Up @@ -806,17 +808,6 @@ await Task.WhenAll(

protected virtual async void OnSizeChanged()
{
if (CurrentView != null && ItemTemplate != null)
{
var currentViewPair = _viewsPool.FirstOrDefault(p => p.Value.Contains(CurrentView));
if (!currentViewPair.Equals(default(KeyValuePair<object, List<View>>)))
{
currentViewPair.Value.Clear();
currentViewPair.Value.Add(CurrentView);
_viewsPool.Clear();
_viewsPool.Add(currentViewPair.Key, currentViewPair.Value);
}
}
await Task.Delay(1);// Workaround for https://github.com/AndreiMisiukevich/CardView/issues/194
ForceRedrawViews();
RemoveUnprocessingChildren();
Expand Down Expand Up @@ -1766,6 +1757,21 @@ private void SetItemsSource(IEnumerable oldCollection)
OnObservableCollectionChanged(oldCollection, new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Reset));
}

private void OnItemTemplateChanged()
{
if (CurrentView != null)
{
var currentViewPair = _viewsPool.FirstOrDefault(p => p.Value.Contains(CurrentView));
if (!currentViewPair.Equals(default(KeyValuePair<object, List<View>>)))
{
currentViewPair.Value.Clear();
currentViewPair.Value.Add(CurrentView);
_viewsPool.Clear();
_viewsPool.Add(currentViewPair.Key, currentViewPair.Value);
}
}
}

private void SetNewIndex()
{
if (ItemsCount <= 0)
Expand Down

0 comments on commit 882f18a

Please sign in to comment.