unoplatform / uno

Open-source platform for building cross-platform native Mobile, Web, Desktop and Embedded apps quickly. Create rich, C#/XAML, single-codebase apps from any IDE. Hot Reload included! 90m+ NuGet Downloads!!
https://platform.uno
Apache License 2.0
8.9k stars 720 forks source link

`ColorPicker` not working #6834

Open mterwoord opened 3 years ago

mterwoord commented 3 years ago

Describe the bug

I'm trying to use the toolkit's ColorPicker. On some platforms it works partially, but on some, not at all.

Steps to Reproduce

Steps to reproduce the behavior:

  1. Use following xaml:

    <Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="Auto"/>
        </Grid.RowDefinitions>
    
        <TextBlock Grid.Row="0" Text="Hello, World!" />
    
        <controls:ColorPicker Grid.Row="1"/>
    </Grid>

    Expected behavior

    image

Screenshots

Things go wrong on: Gtk: image (Clicking the normally colored areas does work)

Wpf: image (Clicking the normally colored areas does work)

Android: image (Nothing visible at all)

Environment

NuGet Package(s):

Package Version(s):

Device form factor:
- [x] Windows
- [?] macOS
- [?] iOS
- [x] Android
- [x] WebAssembly
- [x] WebAssembly renderers for Xamarin.Forms

Visual Studio
- [ ] 2017 (version: )
- [x] 2019 (version: )
- [ ] 2019 Preview (version: )

Additional context

Add any other context about the problem here.

jeromelaban commented 3 years ago

The color map in the middle is implemented using WriteableBitmap, and it may be that the particular use of the WCT does not match some of the behaviors of WinUI/UWP, as used here:

https://github.com/unoplatform/Uno.WindowsCommunityToolkit/blob/a4ea7cfde453852aff9343135dbeeff1a4f18016/Microsoft.Toolkit.Uwp.UI.Controls.Input/ColorPicker/ColorPickerRenderingHelpers.cs#L513

robloo commented 3 years ago

I authored both the new WCT ColorPicker you are using above -- and did the port of the ColorPicker from WinUI to Uno Platform. Initially, the intention was to enable the exact scenario you are trying now. However, there are a number of showstoppers various places. This is known not to work.

ColorPicker (the WinUI Microsoft.UI.Xaml one) should work fine now on Android, iOS and WASM. It very likely does not work at all on GTK and WPF (all Skia backends). ColorPicker was never tested there and these platforms only partially implement some of the features ColorPicker uses. For example, to get things to work on WASM, brush change handling had to be properly implemented (#6766) as it previously was only done for Android/iOS. That's an unexpected gotcha as the original authors of ImageBrush on newer platforms only did a basic implementation and left a lot of scenarios unsupported.

Now for the WCT ColorPicker, it is doing things in XAML that are unsupported by Uno. Additionally, UniformGrid isn't working with Uno from what I see. UniformGrid is now used for both the tab strip and the color palette. It will take quite some time I expect to go through each of these features and enable them.

That said some issues like the palette tab selection pictured above have already been fixed: https://github.com/CommunityToolkit/WindowsCommunityToolkit/pull/4134. I'm not sure when the Uno Platform will re-sync code with upstream changes.

My biggest issue here is that Uno builds everything in the WCT toolkit. However, MOST things don't actually work. This aligns with the Uno strategy of breadth of features instead of depth. In practice it generally means its not a good idea to expect a WCT toolkit feature to work.

If you are willing to put in the work testing and tweaking code to get this scenario to work I'll certainly support. It involves a lot of secondary controls though. Otherwise, at least as a step 1, I suggest you use the WinUI version of the control and get it working on Skia backends. We should be able to do that much quicker.

mterwoord commented 3 years ago

I'm coming from xamarin forms with this project. There I made my own color picker using skia, so i ended up porting that one.. Thanks for following up though!

jeromelaban commented 1 year ago

Update on this topic, with recent builds of the uno and toolkit: https://playground.platform.uno/#235c3a4d

The color bars are appearing empty, but get drawn when interacted with.

There are also some performance update (https://github.com/unoplatform/uno/issues/10772) that could be interesting, to improve rendering of WriteableBitmap.