NobsterTheLobster / Xamarin.Forms.GridView

GridView for xamarin forms
MIT License
60 stars 10 forks source link

[Android]Crash in Xamarin.Forms 3.5 #35

Open devinZhou102 opened 5 years ago

devinZhou102 commented 5 years ago

in Xamarin.Forms 3.5 IElementController(4235) has removed IPlatform,

in GridViewRenderer , the property "Platform" is used here,so leads crash.

private static PropertyInfo _platform; public static PropertyInfo PlatformProperty { get { return _platform ?? ( _platform = typeof(Element).GetProperty("Platform", BindingFlags.NonPublic | BindingFlags.Instance) ?? typeof(Element).GetProperty("Platform", BindingFlags.Public | BindingFlags.Instance)); } }

NobsterTheLobster commented 5 years ago

Looks like they reversed it because it was breaking a few other things as well. I've tested the solution on 3.5.0.169047 without any issue.

The whole point of this dependency is that I remember very early on when trying to get this grid view working is that the elements in the grid did not appear correctly. I luckily found a fix someone had posted in the old x-labs repo and that fix was to reset the platform property after the binding context had changed.

// reflection method of setting isplatformenabled property // We are going to re-set the Platform here because in some cases (headers mostly) its possible this is unset and // when the binding context gets updated the measure passes will all fail. By applying this here the Update call // further down will result in correct layouts. var p = PlatformProperty.GetValue(Element); PlatformProperty.SetValue(gridViewCell, p);

In a later version there was some breaking changes between xamarin forms versions and I had to support two slightly different routes for resolving this property. So interesting this was not the first time there has been problems relating to this property.

public static PropertyInfo PlatformProperty { get { return _platform ?? ( _platform = typeof(Element).GetProperty("Platform", BindingFlags.NonPublic | BindingFlags.Instance) ?? typeof(Element).GetProperty("Platform", BindingFlags.Public | BindingFlags.Instance)); } }

I will investigate if I get a chance whether this code is still necessary and/or whether I achieve what I need via PlatformServices