Xamarin.forms: SwitchRenderer - IF and ELSE IF evaluating the same condition

Created on 9 Jan 2018  路  4Comments  路  Source: xamarin/Xamarin.Forms

Description

IF and ELSE IF seems evaluating the same condition in class SwitchRenderer.

Steps to Reproduce

In file:
Xamarin.Forms/Xamarin.Forms.Platform.Android/Renderers/SwitchRenderer.cs

At line 26 inside method:
public override SizeRequest GetDesiredSize(int widthConstraint, int heightConstraint)

It seems that Lines 33 and 36 are evaluating the same condition:
widthConstraint <= 0

if (widthConstraint <= 0)
    width = (int)Context.GetThemeAttributeDp(global::Android.Resource.Attribute.SwitchMinWidth);
else if (widthConstraint <= 0)
    width = 100;

Since widthConstraint is not a function (that could return different values when called)
but a local variable, it will have the same value in both cases. Am I missing something?

What is the original intention behind this?
Should the second condition be changed?

Android bug

Most helpful comment

This will be a fun dig into git blame to see where that went wrong and why...

All 4 comments

The same in
Xamarin.Forms/Xamarin.Forms.Platform.Android/AppCompat/SwitchRenderer.cs
in method at line 28
public override SizeRequest GetDesiredSize(int widthConstraint, int heightConstraint)
at lines 35 and 37

if (widthConstraint <= 0)
    width = (int)Context.GetThemeAttributeDp(global::Android.Resource.Attribute.SwitchMinWidth);
else if (widthConstraint <= 0)
    width = 100;

This will be a fun dig into git blame to see where that went wrong and why...

Committed before epoch.

Thank you everyone

Was this page helpful?
0 / 5 - 0 ratings