Open kaushalyacs opened 6 years ago
Reproduces as described on android macOS emulator.
Found a workaround for this. Rather than overriding DispatchDraw(Canvas canvas) set the background with:
var orientation = GradientDrawable.Orientation.TopBottom; var gradient = new GradientDrawable(orientation, new[] { StartColor.ToAndroid().ToArgb(), EndColor.ToAndroid().ToArgb() }); ViewHelper.SetBackground(this, gradient)
Found a workaround for this. Rather than overriding DispatchDraw(Canvas canvas) set the background with:
var orientation = GradientDrawable.Orientation.TopBottom; var gradient = new GradientDrawable(orientation, new[] { StartColor.ToAndroid().ToArgb(), EndColor.ToAndroid().ToArgb() }); ViewHelper.SetBackground(this, gradient)
@kaushalyacs thanks for solution But i can't use ViewHelper. Plz help me!
@dungbk55 I recently found this issue was totally changing some of my pages and how they rendered on real devices, not just emulators. It is definitely a Android 9.0 issue.
Instead of ViewHelper, try this: ViewCompat.SetBackground(this, gradient); I set the gradient up inside the OnElementChanged method and it worked great
@dungbk55 I recently found this issue was totally changing some of my pages and how they rendered on real devices, not just emulators. It is definitely a Android 9.0 issue.
Instead of ViewHelper, try this: ViewCompat.SetBackground(this, gradient); I set the gradient up inside the OnElementChanged method and it worked great
Totally agree!! š„³ Hearing somebody had crash issues on old devices, I inserted a check to implement this workaround on new android P devices only
protected override void DispatchDraw(Canvas canvas)
{
base.DispatchDraw(canvas);
var boxView = (GradientBoxView)this.Element;
// from Android 9 this is the workaround
// https://github.com/xamarin/Xamarin.Forms/issues/3912
if (Android.OS.Build.VERSION.SdkInt > Android.OS.BuildVersionCodes.O)
{
var orientation = GradientDrawable.Orientation.TopBottom;
var gradient2 = new GradientDrawable(orientation, new[] { boxView.GradientStartColor.ToAndroid().ToArgb(), boxView.GradientEndColor.ToAndroid().ToArgb() });
ViewCompat.SetBackground(this, gradient2);
return;
}
var gradient = new Android.Graphics.LinearGradient(0, 0, 0, Height,
boxView.GradientStartColor.ToAndroid(),
boxView.GradientEndColor.ToAndroid(),
Shader.TileMode.Mirror);
var paint = new Android.Graphics.Paint()
{
Dither = true
};
paint.SetShader(gradient);
canvas.DrawPaint(paint);
base.DispatchDraw(canvas);
}
Anyway @pauldipietro I hope this issue will be fixed in next Xamarin Android releases. Hi! Lewix
Thanks for this. I was getting a gradient bleed only on P in release mode (not mac vs windows related). This work-around fixed it for me :)
Description
Gradient view doesn't rendered properly on Mac OS Android 9 emulator (Older version of emulators work fine). But same project works as expected on Android 9 emulator on Windows.
Steps to Reproduce
I have attached a demo project.
Expected Behavior
Gradient view should be rendered only within the specified area of the view.
Actual Behavior
Gradient view rendered in entire screen as an input transparent view. User can interact with elements out side the Gradient view which are invisible. Only elements inside Gradient view are visible.
Basic Information
Screenshots
Expected output (Windows emulator)
Unexpected output (Mac OS emulator)
Reproduction Link
GradientViewDemo.zip