roubachof/Sharpnado.CollectionView

[Xamarin.Forms] Attached Effect working only with Reflection

AlleSchonWeg opened this issue · 1 comments

Platform (please complete the following information):

  • OS: [iOS]
  • Device: [iPhone6/iPhoneSimulator]
  • Sdk vervion: [iOS 16/]
  • Xamarin.Forms: [3.4.0.1029999]

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.

should be fixed in next version