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(
entry: entry,
extent: Constants.thumbnailCacheExtent,
);
// this loading builder shows a transition image until the final image is ready
// if the image is already in the cache it will show the final image, otherwise the thumbnail
// in any case, we should use `Center` + `AspectRatio` + `Fill` so that the transition image
// appears as the final image with `PhotoViewComputedScale.contained` for `initialScale`
final loadingBuilder = (BuildContext context, ImageProvider imageProvider) {
return Center(
child: AspectRatio( child: AspectRatio(
// enforce original aspect ratio, as some thumbnails aspect ratios slightly differ // enforce original aspect ratio, as some thumbnails aspect ratios slightly differ
aspectRatio: entry.displayAspectRatio, aspectRatio: entry.displayAspectRatio,
child: Image( child: Image(
image: ThumbnailProvider( image: imageProvider,
entry: entry,
extent: Constants.thumbnailCacheExtent,
),
fit: BoxFit.fill, 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!',