Skip to content
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

Assets loaded with ImageDecoder throw a ClassCastException #1717

Open
colinrtwhite opened this issue Nov 22, 2024 · 2 comments
Open

Assets loaded with ImageDecoder throw a ClassCastException #1717

colinrtwhite opened this issue Nov 22, 2024 · 2 comments
Labels
bug Something isn't working
Milestone

Comments

@colinrtwhite
Copy link
Member

colinrtwhite commented Nov 22, 2024

Description
Assets decoded via ImageDecoder.createSource(AssetManager assets, String fileName) throw a ClassCastException when loaded inside Paparazzi. This is because PaparazziAssetRepository returns a FileInputStream and ImageDecoder expects an AssetInputStream.

Steps to Reproduce
Attempt to decode an asset with ImageDecoder.createSource(AssetManager assets, String fileName) in Paparazzi.

Expected behavior
PaparazziAssetRepository should return an AssetInputStream from PaparazziAssetRepository.

Additional information:

  • Paparazzi Version: 1.3.5
  • OS: MacOS
  • Compile SDK: 35
  • Gradle Version: 8.11.1
  • Android Gradle Plugin Version: 8.7.2
@colinrtwhite colinrtwhite added the bug Something isn't working label Nov 22, 2024
@geoff-powell
Copy link
Collaborator

geoff-powell commented Nov 26, 2024

So it looks like this is a LayoutLib bug and not specific to Paparazzi. We could potentially fix the issue by making the suggested changes.

You can repro this in Android Studio by creating this preview:

@Paparazzi
@Preview
@Composable
fun Sample() {
  if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
    ImageDecoder.createSource(LocalContext.current.assets, "test.png").decodeBitmap { info, source ->

    }
  }
}

I think the real issue is the reliance on the type AssetInputStream in ImageDecoder since the AssetManager.load method only returns type InputStream

@geoff-powell geoff-powell added this to the 2.0.0-alpha02 milestone Nov 26, 2024
@colinrtwhite
Copy link
Member Author

Yep it's definitely bad design on ImageDecoder's part. Worst case we can probably work around this in Coil by checking if the returned input stream is an AssetInputStream ahead of time.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants