-
Notifications
You must be signed in to change notification settings - Fork 29.7k
Tighten asset variant detection criteria to only include device-pixel-ratio variants #110721
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
Tighten asset variant detection criteria to only include device-pixel-ratio variants #110721
Conversation
|
I suspect you'll need to rebase upstream to fix ci.yaml validation: |
0a92e44 to
bea7e2b
Compare
041cc8b to
6ddf3ac
Compare
527705c to
ddb1aab
Compare
|
I'm unsubscribing so I stop seeing notifications every time you push, please ping me when this is ready for review :) |
packages/flutter_tools/test/general.shard/asset_bundle_variant_test.dart
Outdated
Show resolved
Hide resolved
packages/flutter_tools/test/general.shard/asset_bundle_variant_test.dart
Outdated
Show resolved
Hide resolved
packages/flutter_tools/test/general.shard/asset_bundle_variant_test.dart
Outdated
Show resolved
Hide resolved
packages/flutter_tools/test/general.shard/asset_bundle_variant_test.dart
Outdated
Show resolved
Hide resolved
packages/flutter_tools/test/general.shard/asset_bundle_variant_test.dart
Outdated
Show resolved
Hide resolved
packages/flutter_tools/test/general.shard/asset_bundle_variant_test.dart
Outdated
Show resolved
Hide resolved
| - packages/flutter_gallery_assets/products/table.png | ||
| - packages/flutter_gallery_assets/products/teaset.png | ||
| - packages/flutter_gallery_assets/products/top.png | ||
| - packages/flutter_gallery_assets/people/ali.png |
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.
was this asset never used?
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.
It doesn't exist! 😄
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.
mind blown. that's not a build error?
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.
It became one with this fix!
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.
@christopherfujino see #110721 (comment) for an explanation
packages/flutter_tools/test/general.shard/asset_bundle_variant_test.dart
Outdated
Show resolved
Hide resolved
packages/flutter_tools/test/general.shard/asset_bundle_variant_test.dart
Outdated
Show resolved
Hide resolved
packages/flutter_tools/test/general.shard/asset_bundle_variant_test.dart
Outdated
Show resolved
Hide resolved
| .listSync() | ||
| .whereType<File>(); | ||
| final Iterable<FileSystemEntity> entities = _fileSystem.directory(directoryPath).listSync(); | ||
|
|
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.
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.
I like the blank like between entities and files because it puts some distance between the for loop that iterates over the files. The reason I like this separation is that entities is not only used for the file for loop--it's also used for the for loop.
| final List<String> excludeDirs = <String>[ | ||
| assetDirPath, | ||
| getBuildDirectory(), | ||
| if (flutterProject.ios.existsSync()) |
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.
Double checking here: The problem these solved is that we'd sometimes pickup variants from build output directories
Something like:
assets/foo.txt
build/bar/baz/intermediates/foo.txt
Would get picked up as a variant. But with this change, the bar/baz/intermediates/ should no longer match the variant code right?
If so, I believe you could remove all excludeDirs except for assetDirPath
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.
Yeah. We should only pick up variants that 1) are exactly one directly down from the main asset and 2) have a parent folder matching the pixel ratio pattern (2x, 3.0x, etc.). Before, we would look at any file under the directory (regardless of depth) of any asset.
I also completely removed all references to assetDirPath from the file, including AssetBundle, as it is unused. This should require a g3fix, right?
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.
is assetDirPath used by the google3 version of the manifest? If not, you can g3fix. If it is used I would just leave it for now
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.
I was slightly inaccurate in my previous comment, but the idea is the same. It was used here exclusively as an exclude directory, and I removed excludeDirs altogether. With that gone, I removed it altogether.
To answer your question, yes, g3 doesn't have any special use for it.
jonahwilliams
left a comment
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.
LGTM (with nit)
…ce-pixel-ratio variants (flutter/flutter#110721)
…ce-pixel-ratio variants (flutter/flutter#110721)
Fixes #69388
Background
If unfamiliar with the concept of asset variants, see Asset variants. Also see #69388.
Currently, when Flutter finds an asset file to use, it will scan adjacent directories for files that have the same filename and consider these files to be variants of the first file (also, the first file is considered to be a variant of itself).
For example, take this pubspec.yaml
and this application directory
In this scenario,
assets/my_icon.jpg,assets/2x/my_icon.png, andassets/dark/my_icon.jpgare considered to be variants ofassets/my_icon.jpg. Currently, this behavior is only utilized when looking for higher-resolution versions of images for devices with high pixel ratios (see Declaring resolution-aware image assets).However, there are scenarios where an image file could be detected as a variant of another when the user meant for them to be two distinct assets. Using the same pubspec from before, suppose we have this application directory:
In this scenario, attempts to load
icon.jpgwill result in one of the other two variants being loaded instead.This is because all three of these files are considered to be variants of
icon.jpg, and the implementation will just happen to pick the last one it encountered when going through the list of candidates. Specifically, all three files are considered to be 1x device-pixel-ratio (i.e. the default) variants oficon.jpg(code).Change
Flutter will now consider an image asset to be a variant of one in its grandparent directory if and only if the parent directory matches the pattern for a device-pixel-ratio (e.g.
2x,3.0x, etc.). Example:This change would call for a documentation change/overhaul of the Asset variants documentation. In particular, the
darkvariant example should be removed/replaced.Pre-launch Checklist
///).If you need help, consider asking for advice on the #hackers-new channel on Discord.