It seems ListView elements won't invoke the ItemSelected and ItemTapped callbacks, and sometime they just do it the first time the item is tapped.
To reproduce the issue change the class BuildCard in CarouselSampleListView.cs as follows:
private object BuildCard(Color color)
{
var list = new ListView
{
BackgroundColor = color,
ItemTemplate = new DataTemplate(() =>
{
var label = new Label
{
TextColor = Color.White
};
label.SetBinding(Label.TextProperty, nameof(ListItemModel.Text));
var content = new ContentView();
content.Content = label;
var tapGesture = new TapGestureRecognizer();
tapGesture.SetBinding(TapGestureRecognizer.CommandProperty, nameof(ListItemModel.Command));
//content.GestureRecognizers.Add(tapGesture); <-- comment this to disable the gesture recognizer
return new ViewCell
{
View = content
};
})
};
list.SetBinding(ItemsView<Cell>.ItemsSourceProperty, nameof(ListCardModel.Items));
// add these callbacks
list.ItemSelected += (sender, e) =>
{
var listView = (ListView)sender;
if (listView.SelectedItem == null)
{
return;
}
Application.Current.MainPage.DisplayAlert("Selected", null, "Ok");
listView.SelectedItem = null;
};
list.ItemTapped += (sender, e) =>
{
Application.Current.MainPage.DisplayAlert("Tapped", null, "Ok");
};
return new ContentView
{
Margin = new Thickness(30, 20),
Content = list
};
}
I'm using Android version 5.0.1 running on an Acer Iconia B1-770 with the version of XF and CardView in the master branch
I think, this can be XF bug, it would be better to make research.
Probably, do you want to debug this case?
There is no a lot of Android specific code
I see. I'll try to find out is this is XF related and report back.
Is this related to the Command bindings not being fired do we think?
If so the issue isn't within the ViewCell's, it must be within the ListView within Forms.
@thedjnova I didn't want to use Command and gesture recognizers like in the sample, although that seems to be the recommended way, because the ripple effect is not being triggered on Android.
You could just override your page/cards OnPropertyChanged and check for SelectedItem or SelectedIndex changes?
Pretty much the same thing just the more verbose version.
Doesn't resolve the issue but would get you up and running until we get it nailed.
@thedjnova Thanks for your suggestion, I'll give it a try.
Hmmm... it doesn't seen to work either, except for the first time a cell is tapped. This is how I've set the callback:
list.PropertyChanged += (sender, e) =>
{
if (e.PropertyName == nameof(list.SelectedItem) && list.SelectedItem != null)
{
Application.Current.MainPage.DisplayAlert("Tapped", null, "Ok");
list.SelectedItem = null;
}
};
I'll try subclassing ListView to override those properties.
This seems to solve the issue in this line of code:
public virtual Task HandlePanReset(IEnumerable<View> views, CardsView cardsView, AnimationDirection animationDirection, IEnumerable<View> inactiveViews)
{
var view = views.FirstOrDefault();
if (view != null)
{
var tcs = new TaskCompletionSource<bool>();
var animTimePercent = 1 - (cardsView.Width - Abs(view.TranslationX)) / cardsView.Width;
var animLength = (uint)(AnimationLength * animTimePercent) * 3 / 2;
if (animLength > 0) { // <-- check if an animation is really needed
new Animation(v => view.TranslationX = v, view.TranslationX, 0)
.Commit(view, nameof(HandlePanApply), 16, animLength, AnimEasing, (v, t) => tcs.SetResult(true));
return tcs.Task;
}
}
return Task.FromResult(true);
}
For some reason an animation of zero length seems to be causing the problem, although I'm not entirely sure.
Wow, fantastic.
I will adjust this fix. Really too strange issue)
will be available in next release =)