fix(Image): Fix bundled assets for Images (#926)
Recent change to introduce caching for network images also broke image requests from local bundle. Fixes #925
This commit is contained in:
Родитель
b1a21e50f4
Коммит
0d02861c61
|
@ -24,6 +24,16 @@ namespace ReactNative.Modules.Image
|
|||
return uri.StartsWith("data:");
|
||||
}
|
||||
|
||||
public static bool IsHttpUri(string uri)
|
||||
{
|
||||
if (uri == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(uri));
|
||||
}
|
||||
|
||||
return uri.StartsWith("http:") || uri.StartsWith("https:");
|
||||
}
|
||||
|
||||
public static async Task<IRandomAccessStream> GetStreamAsync(string uri)
|
||||
{
|
||||
if (uri == null)
|
||||
|
@ -55,7 +65,16 @@ namespace ReactNative.Modules.Image
|
|||
.Merge(image.GetFailedObservable(), Scheduler.Default)
|
||||
.StartWith(new ImageStatusEventData(ImageLoadStatus.OnLoadStart));
|
||||
}
|
||||
|
||||
|
||||
public static IObservable<ImageStatusEventData> GetUriLoadObservable(this BitmapImage image)
|
||||
{
|
||||
return Observable.Merge(
|
||||
Scheduler.Default,
|
||||
image.GetDownloadingObservable(),
|
||||
image.GetOpenedObservable(),
|
||||
image.GetFailedObservable());
|
||||
}
|
||||
|
||||
private static IObservable<ImageStatusEventData> GetOpenedObservable(this BitmapImage image)
|
||||
{
|
||||
return Observable.FromEventPattern<RoutedEventHandler, RoutedEventArgs>(
|
||||
|
@ -92,5 +111,14 @@ namespace ReactNative.Modules.Image
|
|||
throw new InvalidOperationException(pattern.EventArgs.ErrorMessage);
|
||||
});
|
||||
}
|
||||
|
||||
private static IObservable<ImageStatusEventData> GetDownloadingObservable(this BitmapImage image)
|
||||
{
|
||||
return Observable.FromEventPattern<DownloadProgressEventHandler, DownloadProgressEventArgs>(
|
||||
h => image.DownloadProgress += h,
|
||||
h => image.DownloadProgress -= h)
|
||||
.Take(1)
|
||||
.Select(_ => new ImageStatusEventData(ImageLoadStatus.OnLoadStart));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -302,7 +302,7 @@ namespace ReactNative.Views.Image
|
|||
|
||||
imageBrush.ImageSource = image;
|
||||
}
|
||||
else
|
||||
else if (BitmapImageHelpers.IsHttpUri(source))
|
||||
{
|
||||
OnImageStatusUpdate(view, ImageLoadStatus.OnLoadStart, default(ImageMetadata));
|
||||
try
|
||||
|
@ -318,6 +318,15 @@ namespace ReactNative.Views.Image
|
|||
OnImageFailed(view);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
var image = new BitmapImage();
|
||||
disposable.Disposable = image.GetUriLoadObservable().Subscribe(
|
||||
status => OnImageStatusUpdate(view, status.LoadStatus, status.Metadata),
|
||||
_ => OnImageFailed(view));
|
||||
image.UriSource = new Uri(source);
|
||||
imageBrush.ImageSource = image;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
|
Загрузка…
Ссылка в новой задаче