Skip to content

Revert "Make ImageSourcePartExtensions public" - #16893

Merged
PureWeen merged 1 commit into
mainfrom
revert-16633-fix-16367
Aug 21, 2023
Merged

PureWeen merged 1 commit into
mainfrom
revert-16633-fix-16367

Conversation

@mattleibow

Copy link
Copy Markdown
Member

Reverts #16633

This API needs more design as there are some issues, and the correct/current way is:

public static partial class ImageSourceExtensions
{
public static void LoadImage(this IImageSource? source, IMauiContext mauiContext, Action<IImageSourceServiceResult<PlatformImage>?>? finished = null)
{
LoadImageResult(source.GetPlatformImageAsync(mauiContext), finished)
.FireAndForget(mauiContext.Services.CreateLogger<IImageSource>(), nameof(LoadImage));
}
static async Task LoadImageResult(Task<IImageSourceServiceResult<PlatformImage>?> task, Action<IImageSourceServiceResult<PlatformImage>?>? finished = null)
{
var result = await task;
finished?.Invoke(result);
}
public static Task<IImageSourceServiceResult<PlatformImage>?> GetPlatformImageAsync(this IImageSource? imageSource, IMauiContext mauiContext)
{
if (imageSource == null)
return Task.FromResult<IImageSourceServiceResult<PlatformImage>?>(null);
var services = mauiContext.Services;
var provider = services.GetRequiredService<IImageSourceServiceProvider>();
var imageSourceService = provider.GetRequiredImageSourceService(imageSource);
return imageSourceService.GetPlatformImageAsync(imageSource, mauiContext);
}
public static Task<IImageSourceServiceResult<PlatformImage>?> GetPlatformImageAsync(this IImageSourceService imageSourceService, IImageSource? imageSource, IMauiContext mauiContext)
{
if (imageSource == null)
return Task.FromResult<IImageSourceServiceResult<PlatformImage>?>(null);
#if IOS || MACCATALYST
return imageSourceService.GetImageAsync(imageSource);
#elif ANDROID
return imageSourceService.GetDrawableAsync(imageSource, mauiContext.Context!);
#elif WINDOWS
return imageSourceService.GetImageSourceAsync(imageSource);
#elif TIZEN
return imageSourceService.GetImageAsync(imageSource);
#else
throw new NotImplementedException();
#endif
}

@mattleibow
mattleibow requested a review from a team as a code owner August 21, 2023 15:37
@samhouts samhouts added this to the .NET 8 GA milestone Aug 21, 2023
@PureWeen
PureWeen merged commit f6823ff into main Aug 21, 2023
@PureWeen
PureWeen deleted the revert-16633-fix-16367 branch August 21, 2023 20:18
@github-actions github-actions Bot locked and limited conversation to collaborators Dec 5, 2023
@samhouts samhouts added the fixed-in-8.0.0-rc.1.9171 Look for this fix in 8.0.0-rc.1.9171 label Aug 2, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

fixed-in-8.0.0-rc.1.9171 Look for this fix in 8.0.0-rc.1.9171

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants