dotnet / maui

.NET MAUI is the .NET Multi-platform App UI, a framework for building native device applications spanning mobile, tablet, and desktop.
https://dot.net/maui
MIT License
22.2k stars 1.75k forks source link

Canvas background on iOS isn't transparent #9740

Closed WebGoose closed 2 years ago

WebGoose commented 2 years ago

Description

Canvas background on iOS is not transparent and can't be set to transparent. It defaults to solid white and hides other controls beneath it.

In the sample app attached I layer 2 graphics views on top of each other in a grid to create a gauge control (the colour fills the circle based on a value. )

On Android this is working just fine, the canvas is transparent and you can see both graphics views. On iOS the canvas is solid white so you only see the top layer.

Trying to draw a transparent rectangle to fill the canvas doesn't work either, just defaults to white.

Android: image

iOS: image

MauiProgram.zip

I am on VS Preview 17.4.0 Preview 1

Steps to Reproduce

Create any graphics view in iOS. The canvas is solid white.

See attached sample for my use case.

Version with bug

6.0.486 (current)

Last version that worked well

Unknown/Other

Affected platforms

iOS

Affected platform versions

iOS 15..3.1

Did you find any workaround?

No.

Relevant log output

No response

mattleibow commented 2 years ago

This is because by default iOS views are opaque and there is a white background.

A workaround is to add this code somewhere before creating any views. I just added it to the top of the MauiProgram.CreateMauiApp():

#if IOS || MACCATALYST
Microsoft.Maui.Handlers.GraphicsViewHandler.Mapper.AppendToMapping("MakeTransparent", (handler, view) =>
{
    handler.PlatformView.Opaque = false;
    handler.PlatformView.BackgroundColor = null;
});
#endif
ghost commented 2 years ago

We've moved this issue to the Backlog milestone. This means that it is not going to be worked on for the coming release. We will reassess the backlog following the current release and consider this item at that time. To learn more about our issue management process and to have better expectation regarding different types of issues you can read our Triage Process.

WebGoose commented 2 years ago

Thanks @mattleibow , I didn't realise this was actually the view and not the canvas. I can just set the view's BackgroundColor prop to Transparent.

mattleibow commented 2 years ago

Ah, no need for the handler code? OK, lol, that is better then hehe.