roubachof / Sharpnado.CollectionView

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

[Xamarin.Forms] Attached Effect working only with Reflection #85

Closed AlleSchonWeg closed 1 year ago

AlleSchonWeg commented 1 year ago

Platform (please complete the following information):

Describe the bug I'm trying to add an ios-effect to collection view:

    <sh:CollectionView ...>
                <sh:CollectionView.Effects>
                    <effect:AlwaysBounceEffect />
                </sh:CollectionView.Effects>
   </sh:CollectionView>

but in the effect the Container.Control property is null:

        protected override void OnAttached() {
        var ctrl = this.Control != null ? this.Control : this.Container; //Container contains the Renderer
            if(ctrl == null) {
                return;
            }

            if(ctrl is CollectionViewRenderer cViewRenderer) {
                //ctrl.Container.Control is null!
                //Workaround is using reflection to get the UICollectionView
                var field = typeof(CollectionViewRenderer).GetField("_collectionView", BindingFlags.NonPublic | BindingFlags.Instance);
                if(field == null) {
                    return;
                }
                ((UICollectionView)field).AlwaysBounceVertical = true;
            }
        }

It shoulld be easy to access the native control. UICollectionView in this case.

To Reproduce Steps to reproduce the behavior:

  1. Go to '...'
  2. Click on '....'
  3. Scroll down to '....'
  4. See error

Exceptions (if applicable) Copy paste the exception and the stack trace

Unhandled Exception:
System.InvalidOperationException: exception message
  at Namespace.Call
  at ....

Screenshots (if applicable) If applicable, add screenshots to help explain your problem.

roubachof commented 1 year ago

should be fixed in next version