fullscreen: fixed loading builder for small images

This commit is contained in:
Thibault Deckers 2020-04-29 15:15:45 +09:00
parent ea8f2d4e66
commit 8dfcdfe052

View file

@ -56,19 +56,26 @@ class ImageView extends StatelessWidget {
// if the hero tag wraps the whole `PhotoView` and the `loadingBuilder` is not provided, // if the hero tag wraps the whole `PhotoView` and the `loadingBuilder` is not provided,
// there's a black frame between the hero animation and the final image, even when it's cached. // there's a black frame between the hero animation and the final image, even when it's cached.
final thumbnailLoadingBuilder = (context) => Center( final thumbnailProvider = ThumbnailProvider(
child: AspectRatio( entry: entry,
// enforce original aspect ratio, as some thumbnails aspect ratios slightly differ extent: Constants.thumbnailCacheExtent,
aspectRatio: entry.displayAspectRatio, );
child: Image( // this loading builder shows a transition image until the final image is ready
image: ThumbnailProvider( // if the image is already in the cache it will show the final image, otherwise the thumbnail
entry: entry, // in any case, we should use `Center` + `AspectRatio` + `Fill` so that the transition image
extent: Constants.thumbnailCacheExtent, // appears as the final image with `PhotoViewComputedScale.contained` for `initialScale`
), final loadingBuilder = (BuildContext context, ImageProvider imageProvider) {
fit: BoxFit.fill, return Center(
), child: AspectRatio(
// enforce original aspect ratio, as some thumbnails aspect ratios slightly differ
aspectRatio: entry.displayAspectRatio,
child: Image(
image: imageProvider,
fit: BoxFit.fill,
), ),
); ),
);
};
Widget child; Widget child;
if (entry.isSvg) { if (entry.isSvg) {
@ -79,7 +86,7 @@ class ImageView extends StatelessWidget {
mimeType: entry.mimeType, mimeType: entry.mimeType,
colorFilter: Constants.svgColorFilter, colorFilter: Constants.svgColorFilter,
), ),
placeholderBuilder: thumbnailLoadingBuilder, placeholderBuilder: (context) => loadingBuilder(context, thumbnailProvider),
), ),
backgroundDecoration: backgroundDecoration, backgroundDecoration: backgroundDecoration,
scaleStateChangedCallback: onScaleChanged, scaleStateChangedCallback: onScaleChanged,
@ -98,11 +105,10 @@ class ImageView extends StatelessWidget {
imageProvider: uriImage, imageProvider: uriImage,
// when the full image is ready, we use it in the `loadingBuilder` // when the full image is ready, we use it in the `loadingBuilder`
// we still provide a `loadingBuilder` in that case to avoid a black frame after hero animation // we still provide a `loadingBuilder` in that case to avoid a black frame after hero animation
loadingBuilder: (context, event) => imageCache.statusForKey(uriImage).keepAlive loadingBuilder: (context, event) => loadingBuilder(
? Image( context,
image: uriImage, imageCache.statusForKey(uriImage).keepAlive ? uriImage : thumbnailProvider,
) ),
: thumbnailLoadingBuilder(context),
loadFailedChild: EmptyContent( loadFailedChild: EmptyContent(
icon: OMIcons.errorOutline, icon: OMIcons.errorOutline,
text: 'Oops!', text: 'Oops!',