AndreiMisiukevich / CardView

CardsView | CarouselView | CoverflowView | CubeView for Xamarin.Forms
MIT License
712 stars 114 forks source link

Selected Index change while IsCyclical false #170

Closed Snirdude closed 5 years ago

Snirdude commented 5 years ago

Hello,

I seem to be having trouble with changing SelectedIndex while IsCyclical is false. I tried with a very simple example of CoverFlowView, put in 3 squares with colors, swiped to the most right and then clicked a button which changes the SelectedIndex to 0.

this is the xaml:

<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             xmlns:local="clr-namespace:SnirMobileTest"
             xmlns:panCardView="clr-namespace:PanCardView;assembly=PanCardView"
             x:Class="SnirMobileTest.MainPage">

  <StackLayout>
    <panCardView:CoverFlowView x:Name="MainCarousel"
                               PositionShiftValue="60"
                               IsCyclical="False">
      <panCardView:CoverFlowView.ItemTemplate>
        <DataTemplate>
          <ContentView Padding="40">
            <Frame 
              VerticalOptions="Center"
              HorizontalOptions="Fill"
              HeightRequest="290"
              Padding="0" 
              HasShadow="false"
              IsClippedToBounds="true"
              CornerRadius="10"
              BackgroundColor="{Binding Color}">

            </Frame>
          </ContentView>
        </DataTemplate>
      </panCardView:CoverFlowView.ItemTemplate>
    </panCardView:CoverFlowView>
    <Button x:Name="LeftButton" Text="Left" />
    <Button x:Name="RightButton" Text="Right" />
  </StackLayout>

</ContentPage>

this is my cs:

public MainPage()
    {
      InitializeComponent();
      MainCarousel.ItemsSource = new List<TestObject>()
        {
          new TestObject
          {
            Color = Color.Red
          },
          new TestObject
          {
            Color = Color.Beige
          },
          new TestObject
          {
            Color = Color.Blue
          }
        };

      MainCarousel.ItemSwiped += OnMainCarouselOnItemSwiped;
      LeftButton.Clicked += OnLeftButtonOnClicked;
      RightButton.Clicked += OnRightButtonOnClicked;
    }

private void OnRightButtonOnClicked(object sender, EventArgs e)
    {
      MainCarousel.SelectedIndex = 0;
    }

    private void OnLeftButtonOnClicked(object sender, EventArgs e)
    {
      MainCarousel.SelectedIndex = 2;
    }

thanks

AndreiMisiukevich commented 5 years ago

@Snirdude Hi I will check this case. What is the actual behavior?

Snirdude commented 5 years ago

@AndreiMisiukevich Hey, When changing to index 0, it looks like it returns to the second item in the item source, but in fact it is the first. You can see the edges of other items when you shouldn't because it's not cyclical and I picked the first item. More little things like these.

Not exclusive to index 0, I think it is because of the IsCyclical false.

AndreiMisiukevich commented 5 years ago

@Snirdude thx. Need to debug this case. But can't promise ideal solution. In such cases i will change cards without animation, i guess. Need to think..

Snirdude commented 5 years ago

@AndreiMisiukevich Alright thanks.

marioduck commented 5 years ago

I'm having the same issue, and I think it's regardless of whatever IsCyclical is set to.

So here's the behavior I have observed:

I have 10 elements in my cover flow. If I'm at index 1, for example, and set index to 6, it will slide only one card to the right and display the element I have at index 2, even though, internally, SelectedIndex is set to 6, which in turn means that if I swipe left one position, it will display the element I have at index 5 (because internally SelectedIndex was 6)

Brosten commented 5 years ago

I'm having the same issue. SelectedIndex doesn't work with any number over 1 (the second image). This problem was introduced in version 2.0.1. It worked fine in 2.0.0. Until fixed I'll stay in 2.0.0.

Btw, thanks for a great Control! Except for this, it works like a charm!

AndreiMisiukevich commented 5 years ago

@Brosten thanks for info :) Do you mean CoverFlowView, correct?

Brosten commented 5 years ago

@AndreiMisiukevich Oh, sorry for being unclear. I'm using the CarouselView.

AndreiMisiukevich commented 5 years ago

@Brosten seems, it's another issue) Could you please create separate jira task and attach small sample? I will be grateful

Brosten commented 5 years ago

@AndreiMisiukevich Sure! Just one thing… I'm not familiar with jira… I shouldn't add it as a regular github-issue, or? (I'm pretty new to github as well…)

AndreiMisiukevich commented 5 years ago

@AndreiMisiukevich Sure! Just one thing… I'm not familiar with jira… I shouldn't add it as a regular github-issue, or? (I'm pretty new to github as well…)

ohhh) sorry, github issue for sure :)

AndreiMisiukevich commented 5 years ago

Check 2.0.4 version please