0

Our Xamarin forms app uses FlowListView to display a matrix of videos, using custom renderers.

In Android app, when changing the size of the matrix view, each view element / cell, regardless of the size, does FlowItemDisappearing and then FlowItemAppearing consistently. It works perfect.

iOS app's behaviour is different, only some elements in the matrix view do disappearing and appearing. How can I change this behaviour to the same one like Android app?

In my iOS app, I compared the events in OnElementChanged in the renderer with the events in FlowItemDisappearing and FlowItemAppearing, and found discrepancies between them. For example, after changing matrix size from 3x3 to 1 and then from 1 to 3x3, the following is observed: In OnElementChanged: 3x3-1: deleted first row, added new element 1, OK

1-3x3: recreated the elements 6-9 in 3rd row. The problems: 1. shouldn't need to update 3rd row; 2. the handles of element 2 and 3 were not updated, remaining 0.

3x3-1: deleted the elements in 2nd row. The video plays OK in single view. But the problem is now the handles for elements 2-6 become 0. It will be a problem for next transition 1-9.

In FlowListItem appearing / disappearing events:

3x3-1: disappearing view index 0-2 and appearing 0 (new element 1), correct

1-3x3: -(3-5), +(0-2), -(6,8), +(3-5), +(6-8), this says new elements in row 1, recreated elements in row 2 and 3. The problem: it doesn't match the events in OnElementChanged. It appears OnElementChanged missed events.

3x3-1: -(0-2), +(0) new element 1, correct

My problem is the handles of the sub views will go out of sync at the end. If each view element / cell in the new matrix disappears and then appears, there will be no problem at all. Every tile will be refreshed.

enter image description here

Hong Wang
  • 65
  • 10
  • Hi, you could share some code and screenshot to explain this problem, it will be helpful to find the solution. – Junior Jiang Oct 14 '20 at 03:27
  • @Junior Jiang - MSFT Please find the code and screenshot at https://stackoverflow.com/questions/63107557/xamarin-forms-ios-uiview-renderer-intermittent-onelementchanged-in-some-cases – Hong Wang Oct 16 '20 at 04:10

2 Answers2

0

Without knowing the code for your ViewRenderer, but you could try to override the ViewDidLayoutSubviews method of UIViewController.

This method is called after this UIViewController’s View has laid out its subviews (which happens when the Bounds property is modified).

Sample code as fllows:

public override void ViewDidLayoutSubviews()
{
    base.ViewDidLayoutSubviews();

    // update View
}

=============================Update=============================

Sorry for confusing the ViewRenderer and PageRenderer. A ViewRenderer is not a subclass of UIViewController, so they will not be able to override the ViewDidLayoutSubViews method in a ViewRenderer subclass, only in a class that directly or indirectly inherits from UIViewController. ViewRenderer indirectly inherits from UIView, which has a virtual LayoutSubviews method which they could try instead.

Therefore, you could have a try with following code:

public override void LayoutSubviews()
{
    base.LayoutSubviews();
 // update View
}
Junior Jiang
  • 12,430
  • 1
  • 10
  • 30
  • It seems I cannot do the following in ViewRenderer:[Foundation.Export("viewDidLayoutSubviews")] public override void ViewDidLayoutSubviews() { base.ViewDidLayoutSubviews(); // update View } The error message VideoRender.cs(30,30): Error CS0115: 'VideoRender.ViewDidLayoutSubviews()': no suitable method found to override (CS0115) – Hong Wang Oct 16 '20 at 04:43
  • @HongWang Hi, you are using `[Foundation.Export("viewDidLayoutSubviews")]` in ViewRender, why not using `override void ViewDidLayoutSubviews()` to do. – Junior Jiang Oct 16 '20 at 05:35
  • Hi, Initially I just used your code without the export attribute, the same error occurred "no suitable method found to override". What could be missing? VS IntelliSense shows this.ViewDidLayoutSubviews is available. – Hong Wang Oct 16 '20 at 05:44
  • @HongWang Okey, you only type `override` the list of methods will show in Visual Studio. You could share the error screenshot here with my shared code. – Junior Jiang Oct 16 '20 at 05:48
  • screenshot is uploaded in the question at the top of this page. – Hong Wang Oct 16 '20 at 06:38
  • @HongWang It's strange. Whether the version of Xamarin Forms and VS for Mac is the latest version? – Junior Jiang Oct 16 '20 at 06:54
  • My VS for mac is 8.7.7 (build 10) and Xamarin Forms is 4.8.0.1269 – Hong Wang Oct 16 '20 at 07:24
  • @HongWang It's strange, if you clean the project, whehter the error can disappear. – Junior Jiang Oct 16 '20 at 07:41
  • @HongWang If I have the sample project, I will check that in my local site. – Junior Jiang Oct 16 '20 at 07:50
  • I did a clean and rebuild. It still has the same error. Thanks anyway. As mentioned in https://stackoverflow.com/questions/63107557/xamarin-forms-ios-uiview-renderer-intermittent-onelementchanged-in-some-cases, we have got a workaround: using 4 separate lists of play window handles (one for each matrix size). But it's always helpful to know more about the behaviour and more methods to deal with the issue. – Hong Wang Oct 16 '20 at 09:52
  • @HongWang Okey, that's great! You could update this as the solution in answer, then we can continue to wait for other people to share more solutions. – Junior Jiang Oct 16 '20 at 10:07
  • @HongWang Hi, sorry for confusing the **ViewRenderer** and **PageRenderer**, I have updated the answer. You could have a look and try it when you have time – Junior Jiang Oct 20 '20 at 07:14
0

At the end, we used a workaround. It appears that using 4 separate lists of play window handles (one for each matrix size) can overcome the handle management issue. A single view is specially handled by clearing the handles in the list because the handle will always be removed and re-created.

Hong Wang
  • 65
  • 10