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
21.99k stars 1.72k forks source link

IconImageSource in SwipeViewItem not working on IOS #14058

Open pschubert777 opened 1 year ago

pschubert777 commented 1 year ago

Description

When using a swipe item in IOS, the IconImageSource does not display the Icon for the SwipeItem in the IOS Simulator. I tested it also with Android and it works there, but not IOS.

To set the images in the Maui Project, I added them to the Resources > Images folder and set the Build Action to MauiImages

IOS - IPhone SE 3rd Gen IOS 16.2

https://user-images.githubusercontent.com/44069136/226203500-ebe6c287-ab98-4b5e-829b-6ac85da13563.mov

Android - Pixel 5 - API 31

https://user-images.githubusercontent.com/44069136/226203492-a514213d-f71a-4272-b3ff-cc3abed44756.mov

Steps to Reproduce

  1. Create a File > New Maui Project
  2. Add the check.svg and the delete.svg to the Resource > Images
  3. Create an Observable collection in the MainPage.xaml.cs
  4. Create a CollectionView and set the ItemSource to the Observable collection in the MainPage.xaml
  5. In the DataTemplate, add the following code for the SwipeView
  6. Once the code is added, for the SwipeItem in SwipeView.Left set the IconImageSource to delete (for the delete.svg) and in the SwipeView.Right, set the IconImageSource to check (for check.svg)
### Link to public reproduction project repository https://github.com/pschubert777/NewMauiTodo ### Version with bug 7.0 (current) ### Last version that worked well Unknown/Other ### Affected platforms iOS ### Affected platform versions IOS 16.2/15.4 ### Did you find any workaround? No ### Relevant log output _No response_
ghost commented 1 year ago

We've added this issue to our backlog, and we will work to address it as time and resources allow. If you have any additional information or questions about this issue, please leave a comment. For additional info about issue management, please read our Triage Process.

varyamereon commented 1 year ago

Experiencing this too on iOS.

angelru commented 1 year ago

some news?

angelru commented 1 year ago

I solved it by creating a DataTemplateSelector, but the MAUI team should fix it.

public class IssueiOSTemplateSelector : DataTemplateSelector
{
    public DataTemplate AndroidTemplate { get; set; }
    public DataTemplate IoSTemplate { get; set; }

    protected override DataTemplate OnSelectTemplate(object item, BindableObject container)
    {
        if (IsAndroid())
        {
            return AndroidTemplate;
        }

        return IoSTemplate;
    }
    private static bool IsAndroid() => DeviceInfo.Current.Platform == DevicePlatform.Android;
}
Zhanglirong-Winnie commented 1 year ago

Verified this issue with Visual Studio Enterprise 17.7.0 Preview 1.0. Can repro on iOS platform with sample project. NewMauiTodo-main.zip 14058

edgiardina commented 1 year ago

The following log information appears when you try to use an image in an iOS SwipeView

2023-07-25 20:04:45.324819-0400 IfpaMaui[20938:6611044] [Graphics] Invalid size provided to UIGraphicsBeginImageContext(): size={0, 0}, scale=3.000000

angelru commented 1 year ago

When is this going to be fixed?

angelru commented 7 months ago

I solved it by creating a DataTemplateSelector, but the MAUI team should fix it.

public class IssueiOSTemplateSelector : DataTemplateSelector
{
    public DataTemplate AndroidTemplate { get; set; }
    public DataTemplate IoSTemplate { get; set; }

    protected override DataTemplate OnSelectTemplate(object item, BindableObject container)
    {
        if (IsAndroid())
        {
            return AndroidTemplate;
        }

        return IoSTemplate;
    }
    private static bool IsAndroid() => DeviceInfo.Current.Platform == DevicePlatform.Android;
}

Almost 1 year since this issue was reported and I am still using the solution I provided.

angelru commented 1 month ago

any news?