Skip to content

Commit

Permalink
Tried to fix rendering issues
Browse files Browse the repository at this point in the history
  • Loading branch information
AndreiMisiukevich committed Jul 20, 2018
1 parent 72c32f9 commit 38a147b
Showing 1 changed file with 34 additions and 26 deletions.
60 changes: 34 additions & 26 deletions PanCardView/CardsView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ public class CardsView : AbsoluteLayout
view.SetCurrentView();
});

public static readonly BindableProperty SelectedItemProperty = BindableProperty.Create(nameof(SelectedItem), typeof(object), typeof(CardsView), null, BindingMode.TwoWay, propertyChanged: (bindable, oldValue, newValue) => {
public static readonly BindableProperty SelectedItemProperty = BindableProperty.Create(nameof(SelectedItem), typeof(object), typeof(CardsView), null, BindingMode.TwoWay, propertyChanged: (bindable, oldValue, newValue) =>
{
var view = bindable.AsCardsView();
view.SelectedIndex = view.ItemsSource?.IndexOf(newValue) ?? -1;
});
Expand Down Expand Up @@ -113,6 +114,7 @@ public class CardsView : AbsoluteLayout

private readonly object _childLocker = new object();
private readonly object _viewsInUseLocker = new object();
private readonly object _setCurrentViewLocker = new object();

private readonly Dictionary<object, List<View>> _viewsPool = new Dictionary<object, List<View>>();
private readonly Dictionary<Guid, IEnumerable<View>> _viewsGestureCounter = new Dictionary<Guid, IEnumerable<View>>();
Expand Down Expand Up @@ -424,31 +426,34 @@ protected virtual void SetupLayout(params View[] views)

protected virtual async void SetCurrentView()
{
if (await TryAutoNavigate())
if (!_hasRenderer || Parent == null || await TryAutoNavigate())
{
return;
}

if (ItemsSource != null)
lock (_setCurrentViewLocker)
{
var oldView = CurrentView;
CurrentView = GetViews(AnimationDirection.Current, FrontViewProcessor, SelectedIndex).FirstOrDefault();
var newView = CurrentView;

if (CurrentView == null && SelectedIndex >= 0)
{
ShouldIgnoreSetCurrentView = true;
SelectedIndex = -1;
}
else if (SelectedIndex != OldIndex)
if (ItemsSource != null)
{
var isNextSelected = SelectedIndex > OldIndex;
FireItemDisappearing(InteractionType.User, isNextSelected, oldView.GetItem());
FireItemAppearing(InteractionType.User, isNextSelected, newView.GetItem());
var oldView = CurrentView;
CurrentView = GetViews(AnimationDirection.Current, FrontViewProcessor, SelectedIndex).FirstOrDefault();
var newView = CurrentView;

if (CurrentView == null && SelectedIndex >= 0)
{
ShouldIgnoreSetCurrentView = true;
SelectedIndex = -1;
}
else if (SelectedIndex != OldIndex)
{
var isNextSelected = SelectedIndex > OldIndex;
FireItemDisappearing(InteractionType.User, isNextSelected, oldView.GetItem());
FireItemAppearing(InteractionType.User, isNextSelected, newView.GetItem());
}

SetupBackViews();
}
}

SetupBackViews();
}

protected virtual void SetSelectedItem()
Expand Down Expand Up @@ -497,11 +502,6 @@ protected virtual async void AdjustSlideShow(bool isForceStop = false)

protected virtual async Task<bool> TryAutoNavigate()
{
if (!_hasRenderer || Parent == null)
{
return false;
}

if (CurrentView == null)
{
return false;
Expand Down Expand Up @@ -604,13 +604,21 @@ protected override void OnPropertyChanged([CallerMemberName] string propertyName
if (propertyName == "Renderer")
{
_hasRenderer = !_hasRenderer;
if (!_hasRenderer)
if (_hasRenderer)
{
AdjustSlideShow(true);
SetCurrentView();
return;
}
AdjustSlideShow(true);
}
}

protected override void OnParentSet()
{
base.OnParentSet();
SetCurrentView();
}

private void StartAutoNavigation(View oldView, Guid animationId, AnimationDirection animationDirection)
{
if (oldView != null)
Expand Down Expand Up @@ -1232,7 +1240,7 @@ private void RemoveChildren(View[] views)
}
}

private bool CheckIsProcessingView(View view)
private bool CheckIsProcessingView(View view)
=> view == CurrentView || NextViews.Contains(view) || PrevViews.Contains(view);

private bool CheckIndexValid(int index)
Expand Down

0 comments on commit 38a147b

Please sign in to comment.