-
-
Notifications
You must be signed in to change notification settings - Fork 35
feat: implement webtoon-style viewer for tall images #584
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
Open
omnessssssssss
wants to merge
8
commits into
khoadng:master
Choose a base branch
from
omnessssssssss:tall-images-viewer
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 7 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
44e4ddb
feat: implement webtoon-style viewer for tall images
omnessssssssss 5c7c495
Remove unused variables and fix linter warnings
omnessssssssss 4315cb9
refactor: inline post content method and fix generic type issues
omnessssssssss c1fa3ae
fix: restore swipe-up for post info on tall images when UI is visible
omnessssssssss 442efa9
chore: merge upstream master and resolve conflicts
omnessssssssss 52ba79d
Merge branch 'master' into tall-images-viewer
omnessssssssss 918b2fd
feat: add tall media viewer with scrollable support for tall images
omnessssssssss 572e391
refactor(tall-media): simplify settings and convert classifier to fun…
omnessssssssss File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
137 changes: 137 additions & 0 deletions
137
lib/core/posts/details/src/utils/tall_media_classifier.dart
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,137 @@ | ||
| // Flutter imports: | ||
| import 'package:flutter/foundation.dart'; | ||
| import 'package:flutter/widgets.dart'; | ||
|
|
||
| // Project imports: | ||
| import '../../../../settings/settings.dart'; | ||
|
|
||
| class TallMediaDisposition { | ||
| const TallMediaDisposition._({ | ||
| required this.isTall, | ||
| required this.shouldFitToWidth, | ||
| required this.aspectRatio, | ||
| required this.viewportRatio, | ||
| required this.pixelCount, | ||
| required this.scrollExtent, | ||
| }); | ||
|
|
||
| const TallMediaDisposition.standard({ | ||
| required double aspectRatio, | ||
| required double viewportRatio, | ||
| required double pixelCount, | ||
| }) : this._( | ||
| isTall: false, | ||
| shouldFitToWidth: false, | ||
| aspectRatio: aspectRatio, | ||
| viewportRatio: viewportRatio, | ||
| pixelCount: pixelCount, | ||
| scrollExtent: 0, | ||
| ); | ||
|
|
||
| factory TallMediaDisposition.tall({ | ||
| required double aspectRatio, | ||
| required double viewportRatio, | ||
| required double pixelCount, | ||
| required double scrollExtent, | ||
| }) => TallMediaDisposition._( | ||
| isTall: true, | ||
| shouldFitToWidth: true, | ||
| aspectRatio: aspectRatio, | ||
| viewportRatio: viewportRatio, | ||
| pixelCount: pixelCount, | ||
| scrollExtent: scrollExtent, | ||
| ); | ||
|
|
||
| final bool isTall; | ||
| final bool shouldFitToWidth; | ||
| final double aspectRatio; | ||
| final double viewportRatio; | ||
| final double pixelCount; | ||
| final double scrollExtent; | ||
|
|
||
| bool get hasScrollableExtent => scrollExtent > 0; | ||
| } | ||
|
|
||
| class TallMediaClassifier { | ||
omnessssssssss marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| const TallMediaClassifier({ | ||
| required this.settings, | ||
| required this.viewportSize, | ||
| }); | ||
|
|
||
| final TallMediaSettings settings; | ||
| final Size viewportSize; | ||
|
|
||
| TallMediaDisposition classify({ | ||
| required double width, | ||
| required double height, | ||
| required bool isVideo, | ||
| }) { | ||
| if (width <= 0 || height <= 0 || isVideo) { | ||
| final aspectRatio = width <= 0 || height <= 0 ? 0.0 : height / width; | ||
| final viewportRatio = viewportSize.height == 0 | ||
| ? 0.0 | ||
| : height / viewportSize.height; | ||
| return TallMediaDisposition.standard( | ||
| aspectRatio: aspectRatio, | ||
| viewportRatio: viewportRatio, | ||
| pixelCount: width * height, | ||
| ); | ||
| } | ||
|
|
||
| final aspectRatio = height / width; | ||
| final viewportRatio = viewportSize.height == 0 | ||
| ? 0.0 | ||
| : height / viewportSize.height; | ||
| final pixelCount = width * height; | ||
| final projectedHeight = _projectedHeight(width, height); | ||
| final rawScrollExtent = projectedHeight - viewportSize.height; | ||
| final hasScroll = rawScrollExtent > settings.minScrollExtentPx; | ||
|
|
||
| final meetsAspect = aspectRatio >= settings.aspectRatioThreshold; | ||
| final meetsHeight = height >= settings.minHeightPx; | ||
| final meetsViewport = viewportRatio >= settings.minViewportHeightRatio; | ||
| final meetsPixels = pixelCount >= settings.minPixelCount; | ||
|
|
||
| final isTall = | ||
| hasScroll && | ||
| ((meetsAspect && meetsViewport) || | ||
| (meetsAspect && meetsHeight && meetsPixels) || | ||
| (meetsHeight && meetsViewport && meetsPixels)); | ||
|
|
||
| if (kDebugMode) { | ||
| debugPrint( | ||
| 'TallMediaClassifier: aspect=$aspectRatio viewportRatio=$viewportRatio ' | ||
| 'pixels=$pixelCount projectedHeight=$projectedHeight scroll=$rawScrollExtent ' | ||
| '-> isTall=$isTall', | ||
| ); | ||
| } | ||
|
|
||
| if (!isTall) { | ||
| return TallMediaDisposition.standard( | ||
| aspectRatio: aspectRatio, | ||
| viewportRatio: viewportRatio, | ||
| pixelCount: pixelCount, | ||
| ); | ||
| } | ||
|
|
||
| final scrollExtent = rawScrollExtent > 0 ? rawScrollExtent : 0.0; | ||
|
|
||
| return TallMediaDisposition.tall( | ||
| aspectRatio: aspectRatio, | ||
| viewportRatio: viewportRatio, | ||
| pixelCount: pixelCount, | ||
| scrollExtent: scrollExtent > 0 ? scrollExtent : 0, | ||
| ); | ||
| } | ||
|
|
||
| double _projectedHeight(double width, double height) { | ||
| final viewportWidth = viewportSize.width; | ||
| if (width <= 0 || height <= 0 || viewportWidth <= 0) { | ||
| return height; | ||
| } | ||
|
|
||
| final scale = viewportWidth / width; | ||
| final clampedScale = scale < 1 ? scale : 1.0; | ||
| return height * clampedScale; | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -23,6 +23,7 @@ class PostDetailsImage<T extends Post> extends ConsumerStatefulWidget { | |
| super.key, | ||
| this.heroTag, | ||
| this.imageCacheManager, | ||
| this.fitWidthForTallImages = false, | ||
| }); | ||
|
|
||
| final BooruConfigAuth config; | ||
|
|
@@ -31,12 +32,15 @@ class PostDetailsImage<T extends Post> extends ConsumerStatefulWidget { | |
| final String Function(T post)? thumbnailUrlBuilder; | ||
| final ImageCacheManager? imageCacheManager; | ||
| final T post; | ||
| final bool fitWidthForTallImages; | ||
|
|
||
| @override | ||
| ConsumerState<PostDetailsImage> createState() => _PostDetailsImageState(); | ||
| ConsumerState<PostDetailsImage<T>> createState() => | ||
| _PostDetailsImageState<T>(); | ||
| } | ||
|
|
||
| class _PostDetailsImageState extends ConsumerState<PostDetailsImage> { | ||
| class _PostDetailsImageState<T extends Post> | ||
| extends ConsumerState<PostDetailsImage<T>> { | ||
| @override | ||
| Widget build(BuildContext context) { | ||
| final imageUrl = widget.imageUrlBuilder != null | ||
|
|
@@ -117,10 +121,11 @@ class _PostDetailsImageState extends ConsumerState<PostDetailsImage> { | |
| imageUrl: imageUrl, | ||
| placeholderUrl: placeholderImageUrl, | ||
| aspectRatio: post.aspectRatio, | ||
| forceCover: post.aspectRatio != null, | ||
| forceCover: false, // Never force cover when we want fit width | ||
|
Owner
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. This should be conditional based on fitWidthForTallImages |
||
| imageHeight: post.height, | ||
| imageWidth: post.width, | ||
| forceFill: true, | ||
| forceFill: false, | ||
|
Owner
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. Same as above? |
||
| fitWidthForTallImages: widget.fitWidthForTallImages, | ||
| borderRadius: BorderRadius.zero, | ||
| forceLoadPlaceholder: true, | ||
| imageCacheManager: widget.imageCacheManager, | ||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Change the class name, it sounds strange. Maybe
MediaViewportConfiguration