microspaze / FFImageLoading.Maui

FFImageLoading.Maui - Fast & Furious Image Loading for .NET MAUI
MIT License
82 stars 12 forks source link

Targeting core .NET SDK is not supported #6

Open rafalka opened 6 months ago

rafalka commented 6 months ago

Description

First of all: thank you for great job with porting this lib to MAUI.

Unfortunately this port has serious architecture issue: Not all classes are exported when targeting core (ie net7.0 instead ofnet7.0-android) .NET SDK breaks compilation of project which uses them.

This issue blocks any possibility of unit testing of MAUI app.

Steps to Reproduce

  1. Open samples/Sample/Sample.csproj
  2. Add net7.0 to TargetFrameworks
  3. Try to compile

Expected Behavior

Project will compile

Actual Behavior

Several compilation errors related with missing CornersTransformation, GrayscaleTransformation, ....

Basic Information

Screenshots

N/A

Reproduction Link / Code

N/A

microspaze commented 5 months ago

@rafalka I'm sorry I have no idea why do you need the Sample project to support net7.0 or net8.0. The Sample project is a consumer project which must target to a specific OS platform. The FFImageLoading.Maui project is referenced by the FFImageLoading.Tests project which is only for unit-testing. So I add net7.0 and net8.0 support for FFImageLoading.Maui project, but it also has some tricky walkaround not fully support. If you have some specific reason for this need, you can tell me here.

rafalka commented 5 months ago

Hi @microspaze, This issue is not about a sample project but about missing support for non-platform .NET SDKs. Sample project was just an example how to reproduce this issue.

In real life you want to create a unit tests for your MAUI app, so this app need to compiled as a library and must support the core .NET. Unfortunately using FFImageLoading breaks that due to missing some symbols which are only available in platform specific runtimes.

michal-ziolkowski-dev commented 5 months ago

We have the same problem, to support that we can add some compile condition to exclude Image in test configuration, or add suport by adding this library into platform lib implementation. It's not best solutions and i after that we create many redundant code

rafalka commented 5 months ago

@michal-ziolkowski-dev: Alternatively you can create stubs form missing classes/methods which will be compiled only on dotnet core:

namespace FFImageLoading
{
    public class ImageService
    {
        public IConfiguration Configuration => null;

        public void InvalidateMemoryCache() { }
        public Task InvalidateCacheAsync(CacheType all = CacheType.All) => Task.CompletedTask;

        public Task InvalidateCacheEntryAsync(string source, CacheType all = CacheType.All, bool ignore = false) => Task.CompletedTask;

        public Work.TaskParameter LoadUrl(string toString) => null;
    }

}

namespace FFImageLoading.Work
{
    public static class TaskParameterExtensions
    {
        public static TaskParameter Preload(this TaskParameter parameter, ImageService _) => parameter;
    }
}

namespace FFImageLoading.Transformations
{
    public class CornersTransformation : ITransformation
    {
        public double TopLeftCornerSize { get; set; }
        public double TopRightCornerSize { get; set; }
        public double BottomLeftCornerSize { get; set; }
        public double BottomRightCornerSize { get; set; }
        public double CropWidthRatio { get; set; }
        public double CropHeightRatio { get; set; }
        public CornerTransformType CornersTransformType { get; set; }

        public CornersTransformation(double cornersSize, CornerTransformType cornersTransformType)
        {
        }

        public CornersTransformation()
        {
            throw new NotImplementedException();
        }

        public IBitmap Transform(IBitmap sourceBitmap, string path, ImageSourceType sourceType, bool isPlaceholder, string key)
        {
            throw new NotImplementedException();
        }

        public string Key { get; }
    }

    public class CircleTransformation : ITransformation
    {

        public double BorderSize { get; set; }

        public string BorderHexColor { get; set; }
        public IBitmap Transform(IBitmap sourceBitmap, string path, ImageSourceType sourceType, bool isPlaceholder, string key)
        {
            throw new NotImplementedException();
        }

        public string Key { get; }
    }
}
michal-ziolkowski-dev commented 5 months ago

@rafalka works for me on the lates version 1.0.8