Pratik
Pratik

Reputation: 213

How to turn off bouncing effect in Xamarin.Forms CollectionView on ios

I'm trying to turn off bouncing effect of CollectionView on iOS in my Xamarin.Forms project using a custom renderer. I was able to achieve this in ListView using this:

if (e.NewElement != null)
{
   var listView = Control as UITableView;
   Control.Bounces = false;
}

But the Bounces property is not available in CollectionView control. Is there any other way to do this?

Upvotes: 2

Views: 1068

Answers (1)

Gerald Versluis
Gerald Versluis

Reputation: 34013

Create a custom renderer like below. The CollectionView wraps the native UICollectionView which still is a UIScrollView and has the Bounces property.

It's just in a different place!

using System;
using CollectionViewBounceSample.iOS;
using Xamarin.Forms;
using Xamarin.Forms.Platform.iOS;

[assembly: ExportRenderer(typeof(CollectionView), typeof(NoBounceRenderer))]
namespace CollectionViewBounceSample.iOS
{
    public class NoBounceRenderer : CollectionViewRenderer
    {
        public NoBounceRenderer()
        {
            
        }

        protected override void OnElementChanged(ElementChangedEventArgs<GroupableItemsView> e)
        {
            base.OnElementChanged(e);

            if (e.NewElement != null)
                Controller.CollectionView.Bounces = false;
        }
    }
}

That should do the trick. Full sample is here: https://github.com/jfversluis/CollectionViewBounceSample

Upvotes: 6

Related Questions