Bug 57605 - CAGradientLayer - Gradient not working when in-call status bar is active
Summary: CAGradientLayer - Gradient not working when in-call status bar is active
Status: RESOLVED ANSWERED
Alias: None
Product: iOS
Classification: Xamarin
Component: Xamarin.iOS.dll ()
Version: XI 10.3 (iOS 10.2)
Hardware: Macintosh Mac OS
: --- normal
Target Milestone: Untriaged
Assignee: Bugzilla
URL:
Depends on:
Blocks:
 
Reported: 2017-06-19 20:32 UTC by Eduardo Appolinario
Modified: 2017-06-19 22:03 UTC (History)
3 users (show)

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


Attachments
Demo projects (Xamarin & Swift) and Printscreens (95.98 KB, application/zip)
2017-06-19 20:32 UTC, Eduardo Appolinario
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 ANSWERED

Description Eduardo Appolinario 2017-06-19 20:32:38 UTC
Created attachment 22981 [details]
Demo projects (Xamarin & Swift) and Printscreens

If you run the application without the in-call status bar showing, the gradient will work fine. When you kill the application, activate the in-call status bar and re-open the application, the gradient wont be working. It will consider just the second color.

It happens only when using Xamarin, I did the code in both, Xamarin & Native(Swift) and it only happens on Xamarin.

Please find attached the source code that can be used for testing this problem.
Comment 1 Alex Soto [MSFT] 2017-06-19 22:03:20 UTC
Hello, your code is not a 1:1 match between C# and Swift :) you have a small bug in the C# one

Bad:
> gradient.StartPoint = new CGPoint (0.2, view.Frame.Top);
Good:
> gradient.StartPoint = new CGPoint (0.2, view.Frame.X);

Also never add code inside the .ctor (IntPtr) this is used by our Xamarin.iOS runtime, if you need to add initialization logic to your storyboards use the appropiate constructor or ViewDidLoad method as you did in your swift sample 

Full code:

namespace testGradient {
	public partial class ViewController : UIViewController {

		protected ViewController (IntPtr handle) : base (handle)
		{
			// Note: this .ctor should not contain any initialization logic.
		}

		private void AddGradientViewLayer (UIView view)
		{
			var gradient = new CAGradientLayer ();
			gradient.Frame = view.Bounds;
			gradient.StartPoint = new CGPoint (0.2, view.Frame.X);
			gradient.NeedsDisplayOnBoundsChange = true;
			gradient.MasksToBounds = true;
			gradient.Colors = new CGColor[] { UIColor.Red.CGColor, UIColor.Orange.CGColor };
			view.Layer.InsertSublayer(gradient, 0);
		}

		public override void ViewDidLoad ()
		{
			base.ViewDidLoad ();
			AddGradientViewLayer (View);
		}
	}
}