rive-app / rive-app/rive-android
Crash: TextureView doesn't support displaying a background drawable when using with compose
Nobody has claimed this yet.
- Dominant language
- Kotlin
- Stars
- 538
- Forks
- 66
- PR merge metrics
- No merged PRs in 30d
Description
Description
I receive a TextureView doesn't support displaying a background drawable crash when trying to use Rive with Compose on Android 11
Provide a Repro
AndroidView(
modifier = Modifier,
factory = { context ->
RiveAnimationView
.Builder(context)
.setAutoplay(true)
.setResource("my_res")
.build()
},
update = { }
)
Look like it happen because of a
fun build(): RiveAnimationView {
return RiveAnimationView(this)
}
which invokes
RiveTextureView(context, attrs),
which invokes
TextureView(context, attrs)
what I dig in my tests that you don't have to pass attrs if they are null, because under the hood the View.java class will try to applied default values which contains background attribute. And will try to it in any case where constructor different from
View(context) callled
So I guess the possible fix is to add another constructor for RiveTextureView (so a call will start something like this)
abstract class RiveTextureView(context: Context) :
TextureView(context),
TextureView.SurfaceTextureListener {
Expected behavior
App do not crashed
Device & Versions (please complete the following information)
- Device: BE2029 OnePlus Nord N10 5G
- SDK Level [e.g. Android SDK API Level 30]
Additional context
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start at RiveAnimationView.Builder.build and trace the RiveTextureView constructors shown in the report, focusing on how the Context and attrs arguments reach TextureView. Reproduce the Android 11 Compose case with the provided AndroidView snippet and verify that the animation view no longer crashes when built without attrs.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- android, kotlin
- Domain
- mobile
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 42/100