-
Notifications
You must be signed in to change notification settings - Fork 220
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
Bypass font path prefix check in ResourcesCompat::loadFont
#1798
Conversation
// For testing loading font resources from directories other than 'res/' | ||
sourceSets.main.res.srcDirs += 'src/main/other_resources_dir' |
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.
nit: this looks good but might be better in a separate test project. Not a blocker for this PR.
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.
this change makes sense instead of an arbitrary contains
method, skipping the whole startsWith
method eval.
Thanks for the contribution!!
FWIW, that workaround was adopted from Android Studio's own implementation here:
generated sources are handled in a different manner. I'm curious: what's the use case for having alternate resource directories @DSteve595? And more importantly, does that mean that Android Studio's Compose Previews are broken for you given its reliance on the above linked implementation? |
yes I had the same thoughts. As this unblocks your issue, I have the same hesitancy to mimic AS vs our own differing solution. |
Our use case is basically just multiplatform, where we're using Android's directory structure but happened to called the directory "resources" rather than "res". It's something that's easily changed on our part (or easily worked around by copying the resources into a generated dir named "res"). But my thinking with this was: if it's a valid resource that an Android app can read, then Paparazzi should be able to read it too. |
This changes the way in which
ResourcesCompatVisitorFactory
works around the annoying font prefix check inResourcesCompat::loadFont
, which checks that font paths begin with"res/"
. The workaround introduced in #1586 works when the font's file path in the project contains"res/"
, but that's not guaranteed (e.g. alternate source directories, generated sources).Given that I don't think this resource path check gives any value to Paparazzi tests, this fixes those edge cases by bypassing the check completely, assuming
startsWith
returns true. Still hacky, but it already was.Fixes #1794