roubachof / Sharpnado.CollectionView

A performant list view supporting: grid, horizontal and vertical layout, drag and drop, and reveal animations.
The Unlicense
242 stars 30 forks source link

[HorizontalListView] Current index reset to zero when a ViewCell Entry get focus #10

Open bnORISHA opened 5 years ago

bnORISHA commented 5 years ago

I am using HorizontalListView as a carousel. There is an Entry in it. But when I set HorizontalTextAlignment of the Entry to Center, current index of HorizontalListView is reset to zero. When I don't set HorizontalTextAlignment it works well. I have the same problem when I use a custom renderer of Entry and I set Gravity to Center.

XAML : `<renderedViews:HorizontalListView x:Name="FruitList" ColumnCount="1" HorizontalOptions="FillAndExpand" ItemSpacing="0" ListLayout="Linear" ScrollSpeed="Slowest" SnapStyle="Center" VerticalOptions="FillAndExpand">

`
roubachof commented 5 years ago

I took your xaml and copy pasted it in the silly app ListView.xaml page, and CurrentIndex is well bound. It changes when you scroll the list. Sorry.

roubachof commented 5 years ago

Sorry, I did reproduce it :) But your description was unaccurate: you have to get focus of the entry to make it happen.

roubachof commented 5 years ago

Here what happens:

  1. put an Entry in a CellView
  2. Scroll few items
  3. CurrentIndex is updated accordingly
  4. Tap on the Entry, it takes focus
  5. Then the recyclerview scrolls automatically to the first item

Spent last 2 hours trying to figure out why... Any help appreciated :)

bnORISHA commented 5 years ago

Sorry I forgot about focus... I tried to update to Xamarin.Forms 4.0.0.497661. Same problem. It's weird. The problems occurs only when I set HorizontalTextAlignment to "Center" or "End". It's good with "Start".

bnORISHA commented 5 years ago

I've seen something in AndroidHorizontalListViewRenderer.OnControlScrollChangedListener.cs. private void UpdateCurrentIndex(AndroidHorizontalListViewRenderer nativeView, CancellationToken token) on lines 151 & 152.

int firstItemIndex = nativeView.LinearLayoutManager.FindFirstVisibleItemPosition();
int lastItemIndex = nativeView.LinearLayoutManager.FindLastVisibleItemPosition();

Why not FindFirstCompletelyVisibleItemPosition() & FindLastCompletelyVisibleItemPosition() ?

roubachof commented 5 years ago

When you set SnapStyle to Center you want to get the index of the item in the middle of the screen. If you use FindFirstCompletelyVisibleItemPosition and FindLastVisibleItemPosition some cases won't work.

meierhoeferjannis commented 2 years ago

Hi, im currently having the same problem that the HorizontaList automatically scrolls to the beginning when a User taps on a Control that takes input from the user ( e.g. Entry or Picker). The Cursor stays in the Control the User tapped but the List now displays the first item. This behaviour only occurs when the HorizontalTextAlignment Property is set on the Control the User taps and the List's layout is linear or Carousel. When HorizontalTextAlignment is not set, the HorizontalList just works fine with linear and Carousel layout. I also tried the CarouselView of Xamarin.Forms instead of the HorizontalList but the same behaviour occured when the HorizontalTextAlignment property was set. Maybe this Issue is not directly caused by the HorizontalListView Library. Is it possible that something in Xamarin.Forms is not working as excpected, which causes this weird behaviour?

Xamarin Forms Version: 5.0.0.2012 Sharpnado.Forms.HorizontalListView Version: 1.8.2 Thanks for any help in advance and all the people who created this awesome Library :)

shawyunz commented 2 years ago

"HorizontalTextAlignment" of the entry matters, what a bug!