Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ Bug ] Custom Section Headers don't render correctly on iOS. #118

Open
1 of 2 tasks
Jakar510 opened this issue Jul 13, 2020 · 1 comment
Open
1 of 2 tasks

[ Bug ] Custom Section Headers don't render correctly on iOS. #118

Jakar510 opened this issue Jul 13, 2020 · 1 comment

Comments

@Jakar510
Copy link

Jakar510 commented Jul 13, 2020

Description

Custom Section Headers don't render correctly. Note that this doesn't happen every time, but most of the time.
On iOS it usually will render as a pixel or two wide striped lines. On Android, works fine.

	public class SectionHeader : Grid
	{
		public bool IsExpanded { get; set; }
		protected Label _Label { get; set; }
		protected Image _Icon { get; set; }
		public ImageSource Collapsed { get; set; }
		public ImageSource Expanded { get; set; }


		public SectionHeader( Action command ) : this(new Command(command)) { }
		public SectionHeader( ICommand command ) => Init(command);
		~SectionHeader()
		{
			ClearGesture(this);
			ClearGesture(_Label);
			ClearGesture(_Icon);
		}
		protected void Init( ICommand command )
		{
			CreateView();
			AddGesture(_Label, command);
			AddGesture(this, command);
			AddGesture(_Icon, command);
		}
		protected virtual void CreateView()
		{
			MinimumHeightRequest = 30;
			//HeightRequest = 40;
			HorizontalOptions = LayoutOptions.FillAndExpand;
			VerticalOptions = LayoutOptions.FillAndExpand;


			ColumnDefinitions = new ColumnDefinitionCollection()
			{
				new ColumnDefinition() { Width = new GridLength(0.1, GridUnitType.Star) },
				new ColumnDefinition() { Width = GridLength.Star },
				new ColumnDefinition() { Width = new GridLength(0.1, GridUnitType.Star) },
			};

			SetDynamicResource(BackgroundColorProperty, "HeaderBackgroundColor");


			_Label = new Label()
			{
				Padding = new Thickness(0, 10, 0, 10),
				VerticalTextAlignment = TextAlignment.Center,
				HorizontalTextAlignment = TextAlignment.Center,
				HorizontalOptions = LayoutOptions.FillAndExpand,
				VerticalOptions = LayoutOptions.FillAndExpand,

			};
			_Label.SetDynamicResource(Label.FontSizeProperty, "HeaderFontSize");
			_Label.SetDynamicResource(Label.TextColorProperty, "HeaderTextColor");
			_Label.SetDynamicResource(Label.BackgroundColorProperty, "HeaderBackgroundColor");
			SetColumn(_Label, 1);


			_Icon = new Image()
			{
				Aspect = Aspect.AspectFit,
				HorizontalOptions = LayoutOptions.FillAndExpand,
				VerticalOptions = LayoutOptions.FillAndExpand,
			};
			SetColumn(_Icon, 0);
			_Icon.SetDynamicResource(Image.BackgroundColorProperty, "HeaderBackgroundColor");


			Children.Add(_Label);
			Children.Add(_Icon);
		}


		protected static void AddGesture( View view, ICommand command )
		{
			if ( view is null )
				throw new ArgumentNullException(nameof(view));

			if ( command is null )
				throw new ArgumentNullException(nameof(command));

			var tap = new TapGestureRecognizer
			{
				NumberOfTapsRequired = 1,
				Command = command
			};

			view.GestureRecognizers.Add(tap);
		}
		protected static void ClearGesture( View view )
		{
			if ( view is null )
				throw new ArgumentNullException(nameof(view));

			view.GestureRecognizers.Clear();
		}

		public void Toggle()
		{
			bool check = !IsExpanded;
			IsExpanded = check;

			_Icon.Source = IsExpanded ? Collapsed :  Expanded;
		}
		public void SetText( string text ) => _Label.Text = text;
	}

Steps to Reproduce

  1. Create a few sections with the above SectionHeader class as the header.
  2. Show the view.

Expected Behavior

Show the header.

Actual Behavior

On iOS it usually will render as a pixel or two wide striped lines. On Android, works fine.

Platforms

  • Android
  • iOS

Basic Information

  • AiForms.SettingsView 1.2.14-pre
  • Xamarin.Forms 4.7.0.1080
  • Android Support Libray Version: Xamarin.AndroidX.AppCompat 1.1.0.1
  • Affected Devices:

Screenshots

Reproduction Link

Workaround

@Jakar510
Copy link
Author

Any update?

Jakar510 added a commit to Jakar510/Jakar.SettingsView that referenced this issue Mar 12, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant