KEMBAR78
Merge the BackgroundImageSource into Background by mattleibow · Pull Request #6819 · dotnet/maui · GitHub
Skip to content

Conversation

@mattleibow
Copy link
Member

@mattleibow mattleibow commented May 4, 2022

Description of Change

This PR moves the bits towards a single, unified Background property like all the other XAML flavours. Currently, the new types are internal until we can figure out the best way - maybe just make it public later and add XamlC?

Issues Fixed

Fixes an issue where windows did not set the page background color as the background image would unset things.

Enhances #3396 and fixes the issue where windows did not support initial backgrounds anymore
@mattleibow mattleibow added t/bug Something isn't working t/enhancement ☀️ New feature or request legacy-area-controls Label, Button, CheckBox, Slider, Stepper, Switch, Picker, Entry, Editor area-controls-pages Page types labels May 4, 2022
@mattleibow mattleibow added this to the 6.0.300 milestone May 4, 2022
@mattleibow mattleibow requested a review from jsuarezruiz May 4, 2022 16:14
@mattleibow mattleibow self-assigned this May 4, 2022
namespace Microsoft.Maui.Controls
{
[ContentProperty(nameof(ImageSource))]
class ImageBrush : Brush
Copy link
Member Author

Choose a reason for hiding this comment

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

This is internal for now, but after a few tests and some additional tweaks in other places, this will work for all things.

Comment on lines -149 to -161
public static void MapBackgroundImageSource(IViewHandler handler, IView view)
{
if (view is not IViewBackgroundImagePart viewBackgroundImagePart)
return;

if (handler.PlatformView is not PlatformView platformView)
return;

var provider = handler.GetRequiredService<IImageSourceServiceProvider>();

platformView.UpdateBackgroundImageSourceAsync(viewBackgroundImagePart, provider)
.FireAndForget(handler);
}
Copy link
Member Author

Choose a reason for hiding this comment

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

Moved all these into the common file.

Comment on lines +203 to +209
if (view.Background is ImageSourcePaint image)
{
var provider = handler.GetRequiredService<IImageSourceServiceProvider>();

platformView.UpdateBackgroundImageSourceAsync(image.ImageSource, provider)
.FireAndForget(handler);
}
Copy link
Member Author

Choose a reason for hiding this comment

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

This if block here is not so great, but still is good enough. Since this logic lives here and not in the extension method, none of the controls that re-define the background mapping - such as image, label, entry - get this enhanced background support.

To fully realize this new feature, we will need to move this logic into the UpdateBackground method and make it async and all that. Also, we probably need to consolidate the several UpdateBackground methods and variants scattered about.


namespace Microsoft.Maui
{
class ImageSourcePaint : Paint
Copy link
Member Author

Choose a reason for hiding this comment

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

This can't really be moved into Maui.Graphics as it wraps a Maui UI type. This is fine here - either public or internal - as it is not actually used by Maui.Graphics at all.

There is the ImagePaint still, but that represents an image already loaded into memory. The pixel bits. This new type represents the potential image and something must load it.

}

public static async Task UpdateBackgroundImageSourceAsync(this AView platformView, IViewBackgroundImagePart viewBackgroundImagePart, IImageSourceServiceProvider? provider)
public static async Task UpdateBackgroundImageSourceAsync(this AView platformView, IImageSource? imageSource, IImageSourceServiceProvider? provider)
Copy link
Member Author

Choose a reason for hiding this comment

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

This is technically a breaking change, but I don't think it is used in RC3 by anyone and will be quickly replaced by RC4/GA.

@Redth Redth requested a review from PureWeen May 4, 2022 17:15
@rachelkang rachelkang self-requested a review May 4, 2022 18:57
Copy link
Member

@rachelkang rachelkang left a comment

Choose a reason for hiding this comment

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

Page BackgroundColor appears to be propagating properly again!

LGTM

@mattleibow mattleibow merged commit 21a4caf into main May 4, 2022
@mattleibow mattleibow deleted the dev/merge-backgrounds branch May 4, 2022 20:23
Copy link
Contributor

@StephaneDelcroix StephaneDelcroix left a comment

Choose a reason for hiding this comment

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

👍

  • I'm not seeing the TypeConverter changes. am I still low on coffee, or is this missing ?

@mattleibow
Copy link
Member Author

No type converters yet. I also kept everything internal. I tried making it public, but xamlc was not so happy. So, all internal for rc3 but we can add this in when there is more that 10 mins to launch.

@github-actions github-actions bot locked and limited conversation to collaborators Dec 22, 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.312 Look for this fix in 6.0.312! 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.312 Look for this fix in 6.0.312! t/bug Something isn't working t/enhancement ☀️ New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants