Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revert "Make ImageSourcePartExtensions public" #16893

Merged
merged 1 commit into from
Aug 21, 2023
Merged

Conversation

mattleibow
Copy link
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
34 checks passed
@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
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants