Base carousel view processors setting views to hidden, displays as blank views.
See original GitHub issueFirstly, this is a question rather than an issue (Also possibly a mad rambling as I have been working on this issue for about a week). I have been using this control as a CarouselView
in my current project.
We are using it to display a grid of items that can be resized, e.g, if we have 20 items in a 4x4 grid page we have 2 pages, one with 16 and the other with 4. We can then resize the grid to 5x5 where we just have one page in the carousel. These pages have some Skia components and a text label.
Anyway, I have noticed that if the user quickly swipes to the end of the carousel with a large data set then swipes back or changes the ItemSource after swiping, some pages can be hidden but have the right data bound to them. I checked on iOS using reveal to see the data is there but the view is hidden. I thought this might be the time taken to layout the view or some race condition with setting the view to visible. I have fixed this issue by stopping the processor from hiding the pages, e.g., using a custom CarouselView
and passing in my custom processors which don’t set the IsVisible
flag on any of the views like here.
I was just wondering if there is any reason to hide the views in the processors?
If anyone else has a similar issue this is what my processors look like:
public class CustomCarouselBackViewProcessor : BaseCarouselBackViewProcessor
{
public override void HandleInitView(IEnumerable<View> views, CardsView cardsView, AnimationDirection animationDirection)
{
var view = views.FirstOrDefault();
if (view != null)
{
view.TranslationX = Sign((int)animationDirection) * cardsView.Width;
}
}
public override void HandlePanChanged(IEnumerable<View> views, CardsView cardsView, double xPos, AnimationDirection animationDirection, IEnumerable<View> inactiveViews)
{
if (animationDirection == AnimationDirection.Null)
{
return;
}
var value = Sign((int)animationDirection) * cardsView.Width + xPos;
if (Abs(value) > cardsView.Width || (animationDirection == AnimationDirection.Prev && value > 0) || (animationDirection == AnimationDirection.Next && value < 0))
{
return;
}
var view = views.FirstOrDefault();
if (view != null)
{
view.TranslationX = value;
}
}
}
public class CustomCarouselFrontViewProcessor : BaseCarouselFrontViewProcessor
{
public override void HandlePanChanged(IEnumerable<View> views, CardsView cardsView, double xPos, AnimationDirection animationDirection, IEnumerable<View> inactiveViews)
{
var view = views.FirstOrDefault();
var inactiveView = inactiveViews.FirstOrDefault();
if (Abs(xPos) > cardsView.Width || (animationDirection == AnimationDirection.Prev && xPos < 0) || (animationDirection == AnimationDirection.Next && xPos > 0))
{
return;
}
if (animationDirection == AnimationDirection.Null)
{
xPos = Sign(xPos) * Min(Abs(xPos / 4), NoItemMaxPanDistance);
}
if (view != null)
{
view.TranslationX = xPos;
}
}
}
then just subclass CarouselView
with a custom one:
public class CustomCarouselView : CarouselView
{
public CustomCarouselView() : base(new CustomCarouselFrontViewProcessor(), new CustomCarouselBackViewProcessor())
{
}
}
Essentially just removing all the IsVisible
calls
Issue Analytics
- State:
- Created 5 years ago
- Comments:5 (5 by maintainers)
Top GitHub Comments
Ah, we are only in Landscape for this project. Didn’t think about the orientation change. I will try to create a sample this week and add it to the samples, it is quite hard to recreate this issue.
Probably, we can add a property for determining possibility to change IsVisible… really, don’t know