async void ImageLoadingFinished(CachedImage element) { await ImageService.Instance.Config.MainThreadDispatcher.PostAsync(() => { if (element != null && !_isDisposed) { ((IVisualElementController)element).NativeSizeChanged(); element.SetIsLoading(false); } }); }
private async void ImageLoadingSizeChanged(CachedImage element, bool isLoading) { if (element != null && !_isDisposed) { await ImageService.Instance.Config.MainThreadDispatcher.PostAsync(() => { if (!isLoading || !_isSizeSet) { ((IVisualElementController)element).NativeSizeChanged(); _isSizeSet = true; } if (!isLoading) { element.SetIsLoading(isLoading); } }); } }
private async void ImageLoadingSizeChanged(CachedImage element, bool isLoading) { if (element == null || _isDisposed) { return; } await ImageService.Instance.Config.MainThreadDispatcher.PostAsync(() => { if (element == null || _isDisposed) { return; } ((IVisualElementController)element).NativeSizeChanged(); if (!isLoading) { element.SetIsLoading(isLoading); } }).ConfigureAwait(false); }
private void UpdateBitmap(CachedImageView imageView, CachedImage image, CachedImage previousImage) { lock (_updateBitmapLock) { CancelIfNeeded(); if (image == null || imageView == null || imageView.Handle == IntPtr.Zero || _isDisposed) { return; } var ffSource = ImageSourceBinding.GetImageSourceBinding(image.Source, image); if (ffSource == null) { if (_lastImageSource == null) { return; } _lastImageSource = null; imageView.SetImageResource(Android.Resource.Color.Transparent); return; } if (previousImage != null && !ffSource.Equals(_lastImageSource)) { _lastImageSource = null; imageView.SkipInvalidate(); Control.SetImageResource(Android.Resource.Color.Transparent); } image.SetIsLoading(true); var placeholderSource = ImageSourceBinding.GetImageSourceBinding(image.LoadingPlaceholder, image); var errorPlaceholderSource = ImageSourceBinding.GetImageSourceBinding(image.ErrorPlaceholder, image); image.SetupOnBeforeImageLoading(out var imageLoader, ffSource, placeholderSource, errorPlaceholderSource); if (imageLoader != null) { var finishAction = imageLoader.OnFinish; var sucessAction = imageLoader.OnSuccess; imageLoader.Finish((work) => { finishAction?.Invoke(work); ImageLoadingSizeChanged(image, false); }); imageLoader.Success((imageInformation, loadingResult) => { sucessAction?.Invoke(imageInformation, loadingResult); _lastImageSource = ffSource; }); imageLoader.LoadingPlaceholderSet(() => ImageLoadingSizeChanged(image, true)); if (!_isDisposed) { _currentTask = imageLoader.Into(imageView); } } } }