CMP-4196 Add support for subdirectories in resource folders#5591
Open
cmelchior wants to merge 2 commits intoJetBrains:masterfrom
Open
CMP-4196 Add support for subdirectories in resource folders#5591cmelchior wants to merge 2 commits intoJetBrains:masterfrom
cmelchior wants to merge 2 commits intoJetBrains:masterfrom
Conversation
This commit adds support for subdirectories in `/drawable-*` and `/font-*/` folders. This feature can be controlled using `ResourceHolder.allowAccessorSubDirs`. - Subdirectories are transformed to object classes under the appropriate `Res.<type>`, e.g. `Res.drawable.subdir`. This puts some limitations on the naming, .e.g no symbols, no starting digit, no whitespace. Conversion rules can be added later, similar to how some file names are transformed. - Qualified resources will match across subdirectories, similar to how it is done now on the top-level. - It is disallowed to have directories and files create the same key, .e.g. `/drawable/subdir/` and `/drawable/subdir.png` will throw an exception. Also the logic for validating resource files have been improved: - Calculating available ResourceItem's have been isolated in a new class: `ResourceHolder`, making it easier to unit test the logic and keep Gradle Tasks cleaner. - All invalid input errors are now GradleException which provides a better experience in the Gradle output. - Illegal characters in file names, like whitespace or `.` will now show a proper exception message. - Files that would accidentially merge resource keys now throw an exception, e.g. `/drawable/compose.png` and `/drawable/compose.jpg` - We now ignore case when collapsing resource directories. Previously `/drawable/COMPOSE.png` and `/drawable/compose.png` would be two different keys, but this logic would break on case-insensitive filesystems. Now they collapse to the same key. The one from the un-qualified directory (e.g `/drawable`) is used. - String keys across files could conflict without error. This will now throw an exception
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Fixes https://youtrack.jetbrains.com/issue/CMP-4196/Add-ability-to-have-subfolders-in-composeResources
This commit adds support for subdirectories in
/drawable-*and/font-*/folders. The feature can be controlled usingResourceHolder.allowAccessorSubDirs.The following logic has been added:
Res.<type>, e.g.,Res.drawable.subdir. This puts some limitations on the naming, e.g., no symbols, no starting digit, no whitespace. Conversion rules can be added later, similar to how some file names are transformed./drawable/subdir/and/drawable/subdir.pngwill throw an exception.The logic for validating resource files has been improved:
ResourceHolder, making it easier to unit test the logic and keep Gradle Tasks cleaner.GradleException, which provides a better experience in the Gradle output..will now show a proper exception message./drawable/compose.pngand/drawable/compose.jpg./drawable/COMPOSE.pngand/drawable/compose.pngwould be two different keys, but this logic would break on case-insensitive filesystems. Now they collapse to the same key. The keyfrom the unqualified directory (e.g.,/drawable) is used.Testing:
ResourceTestpass.ResourceHolderValidationTest.Open Questions:
In this PR, the subdirectory support is enabled by default. However, the Compose Multiplatform Plugin is not yet aware of these changes. Because it optimistically re-creates the accessors when a user adds new resources or renames them, the plugin will break subdir support in these cases. This PR can be merged with
ResourceHolder.allowAccessorSubDirs = false, and then the flag can be toggled once the Plugin has been updated. I'm not sure what the best approach is here?Some of the validation logic is now stricter. It is technically a breaking change to collapse resource names while ignoring their casing, but the previous implementation had bugs that didn't show up until the app was run on the "wrong" platform. If it is not acceptable to break this in this PR, a migration strategy should probably be put in place instead. But guidance here is needed.
Release Notes
Features - Multiple Platforms
/composeResources/drawablesand/composeResources/fonts