Skip to content
This repository has been archived by the owner on May 1, 2024. It is now read-only.

[Bug] Color.Defult.MultiplyAlpha(0.30).ToAndroid() is crashing the app #14173

Closed
luismts opened this issue Apr 17, 2021 · 6 comments
Closed

[Bug] Color.Defult.MultiplyAlpha(0.30).ToAndroid() is crashing the app #14173

luismts opened this issue Apr 17, 2021 · 6 comments
Labels
p/Android s/needs-info ❓ A question has been asked that requires an answer before work can continue on this issue. t/bug 🐛

Comments

@luismts
Copy link

luismts commented Apr 17, 2021

Description

Color.Defult.MultiplyAlpha(0.30).ToAndroid() is crashing the app.

Steps to Reproduce

  1. Go to the MainActivity in your Xamarin.Forms Android project.
  2. Go to OnCreate(Bundle savedInstanceState) method.
  3. Add the following code:
var color = Xamarin.Forms.Color.Default;
color.MultiplyAlpha(0.30).ToAndroid();

Expected Behavior

Add a default color modifying the alpha.

Actual Behavior

The app is crashing.

Basic Information

  • Version with issue: 5.0.0.2012
  • Platform Target Frameworks:
    • Android: Android 9 - API 28

Build Logs

Default color is:
R=-1, G=-1, B=-1, A=-1, Hue=-1, Saturation=-1, Luminosity=-1

@rachelkang
Copy link
Contributor

Hi, @luismts - thanks for submitting this issue. I'm confirming that I'm able to repro it
Issue14173.zip

The app crashes with this exception

System.InvalidOperationException: Invalid on Color.Default
  at Xamarin.Forms.Color.MultiplyAlpha (System.Double alpha) [0x00019] in D:\a\1\s\Xamarin.Forms.Core\Color.cs:151
  at Issue14173.Droid.MainActivity.OnCreate (Android.OS.Bundle savedInstanceState) [0x0000f] in /Users/rachelkang/Projects/Issue14173/Issue14173.Android/MainActivity.cs:19
  at Android.App.Activity.n_OnCreate_Landroid_os_Bundle_ (System.IntPtr jnienv, System.IntPtr native__this, System.IntPtr native_savedInstanceState) [0x00010] in /Users/builder/azdo/_work/278/s/xamarin-android/src/Mono.Android/obj/Release/monoandroid10/android-30/mcw/Android.App.Activity.cs:2700
  at at (wrapper dynamic-method) Android.Runtime.DynamicMethodNameCounter.7(intptr,intptr,intptr)

@rachelkang rachelkang added p/Android and removed s/unverified New report that has yet to be verified labels Apr 30, 2021
@rachelkang
Copy link
Contributor

On second thought, after chatting with @mattleibow - something to keep in mind here is that Xamarin.Forms.Color.Default is not an actual color, but just a placeholder. It's determined by the control that consumes it

@rachelkang rachelkang added the s/needs-info ❓ A question has been asked that requires an answer before work can continue on this issue. label Apr 30, 2021
@mattleibow
Copy link
Contributor

One example of this is that a Button has a "Default" color for text, background, border and everything else. There is also a IsDefault property that you can use to quickly test to make sure that if it is a Default color, then you can swap out for whatever you want it to really be.

@luismts
Copy link
Author

luismts commented Apr 30, 2021

So, the expected behavior is correct? And the implementation is what we need to care about it?

I'm reporting this because XF-Material-Library and its latest version are experimenting some issues with this code. I also report the issue in their repo; you can see it here.

@Redth
Copy link
Member

Redth commented May 11, 2021

Yes I believe this is expected. In MAUI we are looking at nullable Color so that the 'default' is instead null and not a 'placeholder'

@luismts
Copy link
Author

luismts commented May 12, 2021

Ok, I'm closing this issue.

Thanks @Redth

@luismts luismts closed this as completed May 12, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
p/Android s/needs-info ❓ A question has been asked that requires an answer before work can continue on this issue. t/bug 🐛
Projects
None yet
Development

No branches or pull requests

4 participants