-
Notifications
You must be signed in to change notification settings - Fork 310
lightbox: Display thumbnail with original image sizing #833
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -217,12 +217,16 @@ class _ImageLightboxPage extends StatefulWidget { | |
required this.message, | ||
required this.src, | ||
required this.thumbnailUrl, | ||
required this.originalWidth, | ||
required this.originalHeight, | ||
}); | ||
|
||
final Animation<double> routeEntranceAnimation; | ||
final Message message; | ||
final Uri src; | ||
final Uri? thumbnailUrl; | ||
final double? originalWidth; | ||
final double? originalHeight; | ||
|
||
@override | ||
State<_ImageLightboxPage> createState() => _ImageLightboxPageState(); | ||
|
@@ -259,8 +263,14 @@ class _ImageLightboxPageState extends State<_ImageLightboxPage> { | |
if (frame != null) return child; | ||
|
||
// Display the thumbnail image while original image is downloading. | ||
return RealmContentNetworkImage(widget.thumbnailUrl!, | ||
filterQuality: FilterQuality.medium); | ||
return FittedBox( | ||
fit: BoxFit.scaleDown, | ||
child: SizedBox( | ||
width: widget.originalWidth, | ||
height: widget.originalHeight, | ||
child: RealmContentNetworkImage(widget.thumbnailUrl!, | ||
Comment on lines
+266
to
+271
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Cool, this seems nice and clean. |
||
filterQuality: FilterQuality.medium, | ||
fit: BoxFit.contain))); | ||
} | ||
|
||
Widget _loadingBuilder(BuildContext context, Widget child, ImageChunkEvent? loadingProgress) { | ||
|
@@ -301,11 +311,7 @@ class _ImageLightboxPageState extends State<_ImageLightboxPage> { | |
child: RealmContentNetworkImage(widget.src, | ||
filterQuality: FilterQuality.medium, | ||
frameBuilder: _frameBuilder, | ||
loadingBuilder: _loadingBuilder), | ||
), | ||
), | ||
), | ||
)); | ||
loadingBuilder: _loadingBuilder)))))); | ||
} | ||
} | ||
|
||
|
@@ -536,18 +542,10 @@ class _VideoLightboxPageState extends State<VideoLightboxPage> with PerAccountSt | |
} | ||
} | ||
|
||
enum MediaType { | ||
video, | ||
image | ||
} | ||
|
||
Route<void> getLightboxRoute({ | ||
int? accountId, | ||
BuildContext? context, | ||
required Message message, | ||
required Uri src, | ||
required Uri? thumbnailUrl, | ||
required MediaType mediaType, | ||
Route<void> _getLightboxRoute({ | ||
required int? accountId, | ||
required BuildContext? context, | ||
required RoutePageBuilder pageBuilder, | ||
}) { | ||
return AccountPageRouteBuilder( | ||
accountId: accountId, | ||
|
@@ -559,17 +557,7 @@ Route<void> getLightboxRoute({ | |
Animation<double> secondaryAnimation, | ||
) { | ||
// TODO(#40): Drag down to close? | ||
return switch (mediaType) { | ||
MediaType.image => _ImageLightboxPage( | ||
routeEntranceAnimation: animation, | ||
message: message, | ||
src: src, | ||
thumbnailUrl: thumbnailUrl), | ||
MediaType.video => VideoLightboxPage( | ||
routeEntranceAnimation: animation, | ||
message: message, | ||
src: src), | ||
}; | ||
return pageBuilder(context, animation, secondaryAnimation); | ||
}, | ||
transitionsBuilder: ( | ||
BuildContext context, | ||
|
@@ -583,3 +571,43 @@ Route<void> getLightboxRoute({ | |
}, | ||
); | ||
} | ||
|
||
Route<void> getImageLightboxRoute({ | ||
int? accountId, | ||
BuildContext? context, | ||
required Message message, | ||
required Uri src, | ||
required Uri? thumbnailUrl, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: include trailing comma in intermediate commit (that helps reduce the diff both for that commit and the one after it) |
||
required double? originalWidth, | ||
required double? originalHeight, | ||
}) { | ||
return _getLightboxRoute( | ||
accountId: accountId, | ||
context: context, | ||
pageBuilder: (context, animation, secondaryAnimation) { | ||
return _ImageLightboxPage( | ||
routeEntranceAnimation: animation, | ||
message: message, | ||
src: src, | ||
thumbnailUrl: thumbnailUrl, | ||
originalWidth: originalWidth, | ||
originalHeight: originalHeight); | ||
}); | ||
} | ||
|
||
Route<void> getVideoLightboxRoute({ | ||
int? accountId, | ||
BuildContext? context, | ||
required Message message, | ||
required Uri src, | ||
}) { | ||
return _getLightboxRoute( | ||
accountId: accountId, | ||
context: context, | ||
pageBuilder: (context, animation, secondaryAnimation) { | ||
return VideoLightboxPage( | ||
routeEntranceAnimation: animation, | ||
message: message, | ||
src: src); | ||
}); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cool, I like this refactor splitting into two different entry-point functions. The resulting API feels more thoroughly well-typed.