KEMBAR78
[Core] Implement BackgroundImageSource in PageHandler by jsuarezruiz · Pull Request #3396 · dotnet/maui · GitHub
Skip to content

Conversation

@jsuarezruiz
Copy link
Contributor

@jsuarezruiz jsuarezruiz commented Nov 15, 2021

Description of Change

Implement BackgroundImageSource in PageHandler.

PR Checklist

  • Targets the correct branch
  • Tests are passing (or failures are unrelated)

Does this PR touch anything that might affect accessibility?

  • No

@jsuarezruiz jsuarezruiz added the legacy-area-controls Label, Button, CheckBox, Slider, Stepper, Switch, Picker, Entry, Editor label Nov 15, 2021
{ /// <summary>
/// Represents a .NET MAUI Page.
/// </summary>
public interface IPage : IContentView
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we want to create an IPage for this. Can we follow the same route as we do for things like ITitledElement? I feel like the interface for the background image needs to be more interesting then just having the IImageSource as well. Perhaps we use something like

interface IViewBackgroundImagePart : IImageSourcePart because then that makes it more compatible with other ImageLoading structures

You can then just instantiate a

		public ImageSourcePartLoader SourceLoader =>
			_imageSourcePartLoader ??= new ImageSourcePartLoader(this, () => VirtualView, OnSetImageSource);

And use that to handle all the loading behavior.

At that point the mapper could possibly even just be on ViewHandler and thus a generalized BackgroundImage for native views is born

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed IPage and implemented IViewBackgroundImagePart. Also added a ContentPage Gallery sample where easily test this scenario.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@PureWeen Could you review the PR again?. Thnx!

@jsuarezruiz jsuarezruiz self-assigned this Jan 31, 2022
@Eilon Eilon added the area-controls-pages Page types label Feb 11, 2022
@rmarinho rmarinho requested a review from PureWeen February 18, 2022 12:54
@Redth Redth added this to the 6.0.300-rc.1 milestone Mar 15, 2022
@Redth Redth assigned PureWeen and unassigned jfversluis and jsuarezruiz Mar 15, 2022
{
}

public static void MapBackgroundImageSource(IPageHandler handler, IContentView page)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we move all of this up into ViewHandler?

The extension methods all seem to work against UIView/Android.View/Panel

WinUI is the only one that has kind of a specific type but could probably just use pattern matching to look through the types that accept a background.

This way anyone could annotate any view with IViewBackgroundImagePart and then in controls we will only implement IViewBackgroundImagePart at the page level

@mattleibow
Copy link
Member

I think we have the potential to make a big improvement it IView supports a background image. Not sure how this will work with IImage having both an image and a background image. This is not really possible with interfaces because it will be the same interface type.

SHould IImage support both a background image and an image. I am thinking it is 2 separate concepts, like a centered image that is animating, nd then a background gradient? This is probably the same with IImageButton.

Maybe background should be a brush/paint actually? In fact, this is already a thing. I am wondering if Page.BackgroundImage should translate into Page.Background => new ImagePaint(BackgroundImage) at a controls level, and then our implementation just works?

@Redth Redth assigned hartez and unassigned PureWeen Mar 21, 2022
Copy link
Member

@mattleibow mattleibow left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be on IView.

@PureWeen PureWeen requested a review from mattleibow March 23, 2022 16:25
@PureWeen PureWeen modified the milestones: 6.0.300-rc.1, 6.0.300-rc.2 Mar 24, 2022
@Redth Redth modified the milestones: 6.0.300-rc.2, 6.0.300-rc.3 Apr 20, 2022
@mattleibow
Copy link
Member

I have an idea to actually use ImageBrush and Background instead of exposing new properties. Maybe under the hood we split it up since maui graphics doesn't use image sources.

So we can do what we do with Background/BackgroundColor and basically have this:

IImageSource IImageSourcePart.Source
{
	get
	{
		if (Background is ImageBrush imageBrush && !imageBrush.IsEmpty)
			return imageBrush.ImageSource;
		return BackgroundImageSource;
	}
}
namespace Microsoft.Maui.Controls
{
	[System.ComponentModel.TypeConverter(typeof(BrushTypeConverter))]
	public class ImageBrush : Brush
	{
		public ImageBrush()
		{
		}

		public ImageBrush(ImageSource imageSource)
		{
			ImageSource = imageSource;
		}

		public override bool IsEmpty =>
			ImageSource?.IsEmpty ?? true;

		public static readonly BindableProperty ImageSourceProperty = BindableProperty.Create(
			nameof(ImageSource), typeof(ImageSource), typeof(ImageBrush), default(ImageSource));

		public virtual ImageSource ImageSource
		{
			get => (ImageSource)GetValue(ImageSourceProperty);
			set => SetValue(ImageSourceProperty, value);
		}

		public override bool Equals(object obj) =>
			obj is ImageBrush dest && ImageSource == dest.ImageSource;

		public override int GetHashCode() =>
			-1234567890 + ImageSource.GetHashCode();
	}
}

@mattleibow mattleibow assigned mattleibow and unassigned hartez Apr 22, 2022
Copy link
Member

@mattleibow mattleibow left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ImageBrush is for net7

@mattleibow mattleibow dismissed PureWeen’s stale review April 29, 2022 20:16

Things have happened and changes were made!

@mattleibow mattleibow merged commit f894684 into main Apr 30, 2022
@mattleibow mattleibow deleted the fix-2966 branch April 30, 2022 08:56
mattleibow added a commit that referenced this pull request May 4, 2022
Enhances #3396 and fixes the issue where windows did not support initial backgrounds anymore
@mattleibow
Copy link
Member

Opened a PR (#6819) to move us closer to one property (#6821)

@github-actions github-actions bot locked and limited conversation to collaborators Dec 21, 2023
@Eilon Eilon removed the legacy-area-controls Label, Button, CheckBox, Slider, Stepper, Switch, Picker, Entry, Editor label May 10, 2024
@samhouts samhouts added the fixed-in-6.0.300-rc.3 Look for this fix in 6.0.300-rc.3! label Aug 2, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

area-controls-pages Page types fixed-in-6.0.300-rc.3 Look for this fix in 6.0.300-rc.3!

Projects

No open projects
Status: Done

Development

Successfully merging this pull request may close these issues.

Can't get BackgroundImage of ContentPage [Bug] Unable to set image as ContentPage BackgroundImageSource

9 participants