Bug 59690 - OnMeasure() in custom view renderer of Android View always returns MeasuredHeight/MeasuredWidth zero
Summary: OnMeasure() in custom view renderer of Android View always returns MeasuredHe...
Status: RESOLVED NORESPONSE
Alias: None
Product: Forms
Classification: Xamarin
Component: Android ()
Version: 2.3.4
Hardware: PC Windows
: --- normal
Target Milestone: ---
Assignee: Bugzilla
URL:
Depends on:
Blocks:
 
Reported: 2017-09-22 12:51 UTC by productxf
Modified: 2017-12-04 16:28 UTC (History)
3 users (show)

Tags:
Is this bug a regression?: ---
Last known good build:


Attachments
Like this bottom to top slider but should wrap the content. (48.95 KB, image/gif)
2017-09-22 12:51 UTC, productxf
Details


Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.


Please create a new report on Developer Community or GitHub with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:
Status:
RESOLVED NORESPONSE

Description productxf 2017-09-22 12:51:31 UTC
Created attachment 24889 [details]
Like this bottom to top slider but should wrap the content.

Hi Xamarin Team,

I am using Xamarin.Forms 2.3.4.231. I have a Content page with custom view using renderer to display the content. I am trying to achieve the SlideDrawer(BottomToTop/LeftToRight) behavior of which BottomToTop slider is more common in native Android & iOS. 

I can wrap the content of menu to content size if content is less than half of screen size and if content is more then set height to half of screen size, of course for better look & feel.

Currently I did worked only on Android in custom renderer of Android view to override OnMeasure() to measure the child height dynamically so I can set the SlideDrawer height but to my surprise MeasuredHeight/MeasuredWidth always return zero after applying the different constrains. Note the same thing is working in Xamarin.Android  & Native Android(Java) project that I have created. 

If I am not setting the HeightRequest & WidthRequest, it should layout the children as per parent constraints which are by default Fill for VerticalOptions & HorizontalOptions, to confirm that I have checked the Layout tree in Layout Inspector tool of Android Studio which shows "layout_width" & "layout_height" as "wrap_content". But even after subsequent calls to OnMeasure() not only MeasureHeight/MeasureWidth but MinimumWidth/MinimumHeight are zero. As per Native Android & Xamarin.Android it should return actual measured height/width of the children.

XF puts renderer for every native view like ButtonRenderer on top of Button & when I do GetChildAt() in OnMeasure() ButtonRenderer is return as Android.Views.View which returns zero for MeasuredHeight/MeasuredWidth.

My main page extends the ContentPage and view extends the ContentView.

protected override void OnMeasure(int widthMeasureSpec, int heightMeasureSpec)
{
    int mWidth = 0, mHt = 0;
    for (int i = 0; i < ChildCount; i++)
     {
        Android.Views.View child = GetChildAt(i);
        MeasureChild(child, MeasureSpec.MakeMeasureSpec(0, MeasureSpecMode.Unspecified),
                             MeasureSpec.MakeMeasureSpec(0, MeasureSpecMode.Unspecified)); //Unspecified to know child's actual height/width
       //want to use MeasureChildWithMargins() to actually get the margins also
       mHt = Math.Max(mHt, child.MeasuredHeight) ;
       mWidth = mWidth + child.MeasuredWidth;

     }
     base.OnMeasure(widthMeasureSpec, heightMeasureSpec);// calling it later to do normal measure pass
}

Guys can you please check the issue as it should expect to behave as per native Android / Xamarin.Android.


Thanks.
Comment 1 Paul DiPietro [MSFT] 2017-09-25 16:14:00 UTC
Do you experience the same behavior on 2.4.0-pre3 and can you provide a reproduction to better illustrate the issue?
Comment 2 Paul DiPietro [MSFT] 2017-12-04 16:28:36 UTC
This issue will be closed as no reproduction has been provided nor have any further comments been made. Please reopen this with a reproduction project if the issue still occurs as of the latest 2.5.0 stable release of Forms.

Guidelines for creating reproductions are available at:
https://github.com/xamarin/Xamarin.Forms/wiki/Submitting-Bug-Reports