Forum Xamarin.Forms

How to bypass the Android PageRenderer OnLayout override?

JohnHardmanJohnHardman GBUniversity admin

Ok, I know this is really bad practice, but I want to try this whilst waiting for an update to XF itself.

The XF Android PageRenderer currently contains:

        protected override void OnLayout(bool changed, int l, int t, int r, int b)
        {
            base.OnLayout(changed, l, t, r, b);
            OrderedTraversalController.UpdateTraversalOrder();
        }

Unfortunately, OrderedTraversalController.UpdateTraversalOrder is not virtual and I want to replace it as it doesn't do what I want (this is already the subject of an enhancement request).

My thinking is that I create a custom page renderer that overrides OnLayout. That override then does nasty stuff using reflection to call base.base.OnLayout(changed, l, t, r, b), bypassing the PageRenderer OnLayout in order to avoid calling OrderedTraversalController.UpdateTraversalOrder();

It's fragile and it's nasty, but it will do as a temporary workaround until XF is updated.

So, the question is, how would the reflection code in the OnLayout in the custom page renderer be written in order to make that call to base.base.OnLayout(changed, l, t, r, b) ? Any help gratefully received :-)

Answers

  • jezhjezh Member, Xamarin Team Xamurai

    Sorry, I don't quite follow you. Since you want to call function base.base.OnLayout(changed, l, t, r, b), why do you want to bypass the Android PageRenderer OnLayout ? This sounds inconsistent.
    Can you explain it in detail?


    Xamarin forums are migrating to a new home on Microsoft Q&A!
    We invite you to post new questions in the Xamarin forums’ new home on Microsoft Q&A!
    For more information, please refer to this sticky post.

  • JohnHardmanJohnHardman GBUniversity admin

    @jezh said:
    Sorry, I don't quite follow you. Since you want to call function base.base.OnLayout(changed, l, t, r, b), why do you want to bypass the Android PageRenderer OnLayout ? This sounds inconsistent.
    Can you explain it in detail?

    Because I don't want

    OrderedTraversalController.UpdateTraversalOrder();
    

    to be called (which base.OnLayout would do, but base.base.OnLayout doesn't)

  • jezhjezh Member, Xamarin Team Xamurai

    For this, you can download the source code of xamarin form and change the source sode of PageRenderer , then build it yourself.

    In class PageRenderer, you can change the code of method IOrderedTraversalController.UpdateTraversalOrder() to what you want.

    Hope it can help you.

Sign In or Register to comment.