Xamarin.Forms.GridView icon indicating copy to clipboard operation
Xamarin.Forms.GridView copied to clipboard

The grid items are not measured each time on iOS

Open MatthieuNarcisi opened this issue 7 years ago • 4 comments

Let me start by saying that you saved my life with this project so keep up the good work !

Now, the problem I faced what that I have a page that I recycle (do not judge me) and reuse when the user wants to navigate to it again. The issue is that the SizeChanged event is not called on the GridView when the user navigates to it the second time (might be a XF bug).

So the first time the user displays the page, the items are the right size (I have them being 100x100). But when I go back on forth on the page, the items get their standard size (seems to be about 10x10). So maybe the sizing of the item should not be only done in SizeChanged, but also on the OnElementChanged method.

What I did as a workaround which seems to work is this (in the end of OnElementChanged method) :

//Scroll to first item.
ScrollToInitialIndex();

this.ElementSizeChanged(this.Element, new EventArgs());

//Set the native control.
SetNativeControl(_gridCollectionView);

So the items are now rightly sized even if I navigated back on forth on the page. Maybe there is a better way.

MatthieuNarcisi avatar May 18 '17 12:05 MatthieuNarcisi

Yeah I think I did have the layout code firing on element changed as well initially but I think I took it out for efficiency reasons i.e. I didn't want the layout code firing twice in succession. Does this happen sometimes with your current fix?

NobsterTheLobster avatar May 18 '17 14:05 NobsterTheLobster

I have to admin that I did not tested it yet. I was kind of in a hurry to publish a version. I will give it a try and see if the layout happen twice sometime (it may well be the case I admit).

MatthieuNarcisi avatar May 18 '17 14:05 MatthieuNarcisi

Not really an issue I suppose if its not hurting performance. Great that you were able to code a solution. That's the beauty of open-source. If I get a chance to tomorrow I'll play around with your change and incorporate it or something similar into the repo.

NobsterTheLobster avatar May 18 '17 14:05 NobsterTheLobster

Yeah, that is great, I had the chance to fiddle with the code and find what was going wrong. I did not dare to make a PR because, I thought that calling an event signature directly was not really they way to go so maybe you had a better idea.

MatthieuNarcisi avatar May 18 '17 15:05 MatthieuNarcisi