Bug 44821 - FrameRenderer calling OnDraw() repeatedly
Summary: FrameRenderer calling OnDraw() repeatedly
Status: RESOLVED INVALID
Alias: None
Product: Forms
Classification: Xamarin
Component: Android ()
Version: 2.3.2
Hardware: PC Mac OS
: --- normal
Target Milestone: ---
Assignee: Bugzilla
URL:
Depends on:
Blocks:
 
Reported: 2016-09-28 12:00 UTC by Adam Hartley [MSFT]
Modified: 2016-10-27 19:35 UTC (History)
6 users (show)

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


Attachments
Sample (335.90 KB, application/zip)
2016-09-28 12:00 UTC, Adam Hartley [MSFT]
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 INVALID

Description Adam Hartley [MSFT] 2016-09-28 12:00:31 UTC
Created attachment 17782 [details]
Sample

## Steps to reproduce

1. Download and build attached sample
2. Run on a device / emulator - I tested this with emulators for API 22, 23 and 24 (Intel Atom x86 ABI)
3. Observe Application Output for "OnDraw called" being written to output

## Expected result

OnDraw should not be called multiple times

## Actual result

OnDraw is called repeatedly 

## Notes

=== Xamarin Studio Enterprise ===

Version 6.1.1 (build 15)
Installation UUID: ad66a985-3d32-4bb5-935b-a2e10c4f0de0
Runtime:
	Mono 4.6.1 (mono-4.6.0-branch-c8sr0/abb06f1) (64-bit)
	GTK+ 2.24.23 (Raleigh theme)

	Package version: 406010003

=== NuGet ===

Version: 3.4.3.0

=== Xamarin.Profiler ===

Not Installed

=== Xamarin.Android ===

Version: 7.0.1.2 (Visual Studio Enterprise)
Android SDK: /Users/Adam/Library/Developer/Xamarin/android-sdk-macosx
	Supported Android versions:
		5.0 (API level 21)
		5.1 (API level 22)
		6.0 (API level 23)
		7.0 (API level 24)

SDK Tools Version: 25.2.2
SDK Platform Tools Version: 24.0.3
SDK Build Tools Version: 24.0.1

Java SDK: /usr
java version "1.8.0_101"
Java(TM) SE Runtime Environment (build 1.8.0_101-b13)
Java HotSpot(TM) 64-Bit Server VM (build 25.101-b13, mixed mode)

Android Designer EPL code available here:
https://github.com/xamarin/AndroidDesigner.EPL

=== Xamarin Android Player ===

Not Installed

=== Apple Developer Tools ===

Xcode 8.0 (11246)
Build 8A218a

=== Xamarin.Mac ===

Version: 2.10.0.103 (Visual Studio Enterprise)

=== Xamarin.iOS ===

Version: 10.0.1.8 (Visual Studio Enterprise)
Hash: 3983064
Branch: cycle8-sr0-xi
Build date: 2016-09-23 15:34:54-0400

=== Build Information ===

Release ID: 601010015
Git revision: fa52f02641726146e2589ed86ec4097fbe101888
Build date: 2016-09-22 08:03:02-04
Xamarin addins: 75d65712af93d54dc39ae4c42b21dfa574859fd6
Build lane: monodevelop-lion-cycle8-sr0

=== Operating System ===

Mac OS X 10.12.0
Darwin AdamsRetinaMBP 16.0.0 Darwin Kernel Version 16.0.0
    Mon Aug 29 17:56:20 PDT 2016
    root:xnu-3789.1.32~3/RELEASE_X86_64 x86_64
Comment 1 E.Z. Hart [MSFT] 2016-10-04 21:18:33 UTC
Your problem is that `SetBackgroundResource()` queues up another call to `Draw()` (and ultimately `OnDraw()`), so you're queueing them up infinitely in a loop.

What you're trying to accomplish doesn't require an override of `OnDraw()`; you can just do something like this:

internal class RoundedCornersFrameRenderer : FrameRenderer
{
    protected override void OnElementPropertyChanged(object sender, PropertyChangedEventArgs e)
    {
        base.OnElementPropertyChanged(sender, e);

        if (e.PropertyName == RoundedCornersFrame.CornersTypeProperty.PropertyName)
        {
            UpdateCorners();
        }
    }

    protected override void OnElementChanged(ElementChangedEventArgs<Frame> e)
    {
        base.OnElementChanged(e);
        UpdateCorners();
    }

    void UpdateCorners()
    {
        var cornersType = (RoundedCornersFrame.ECornersType)Element.GetValue(RoundedCornersFrame.CornersTypeProperty);
        switch (cornersType)
        {
            case RoundedCornersFrame.ECornersType.All:
                SetBackgroundResource(Resource.Drawable.rounded_all_shape);
                break;
            case RoundedCornersFrame.ECornersType.Bottom:
                SetBackgroundResource(Resource.Drawable.rounded_bottom_shape);
                break;
            case RoundedCornersFrame.ECornersType.Top:
                SetBackgroundResource(Resource.Drawable.rounded_top_shape);
                break;
            case RoundedCornersFrame.ECornersType.Left:
                SetBackgroundResource(Resource.Drawable.rounded_left_shape);
                break;
            case RoundedCornersFrame.ECornersType.Right:
                SetBackgroundResource(Resource.Drawable.rounded_right_shape);
                break;
            default:
                throw new ArgumentOutOfRangeException();
        }
    }
}
Comment 2 Glebov Aleksandr 2016-10-06 12:20:11 UTC
This suggestion is not so right. Ok, we fixed continous onDraw calling, but we got 2 problems:
1. Some of the corners are not round, but they should be (looks like sizing problem). This issue introduced on android after code replacement.
2. As I mentioned on original issue: horizontal blue lines shown randomly (this issue was before and reproducing now)

It's looks like something in layout engine done in the wrong time or something else.
I've got similar layouting issues on iOS (reported issue to their support team)
Comment 3 E.Z. Hart [MSFT] 2016-10-10 20:16:43 UTC
(In reply to Glebov Aleksandr from comment #2)
> This suggestion is not so right. Ok, we fixed continous onDraw calling, but
> we got 2 problems:
> 1. Some of the corners are not round, but they should be (looks like sizing
> problem). This issue introduced on android after code replacement.
> 2. As I mentioned on original issue: horizontal blue lines shown randomly
> (this issue was before and reproducing now)

Glebov,

After updating the sample to fix the continuous OnDraw problem, I'm definitely seeing the blue line issue you mentioned.

However, all of the corners are rounded when I run the sample; can you upload a screenshot where some of the corners aren't rounded?
Comment 4 Glebov Aleksandr 2016-10-18 12:56:06 UTC
Hi!

It's strange, but i can't to reproduce this... only blue lines and wrong sized boxes if text is wrapped (i've reported this issue:) )

Thanks
Comment 5 Jason Smith [MSFT] 2016-10-27 19:35:54 UTC
The original bug this report spoke is not valid. We are closing this issue to avoid confusion, please open a new report if you have a different bug.