-
-
Save brianwernick/0a0e276bd072252b2c7a80f90ce41e43 to your computer and use it in GitHub Desktop.
This file contains 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
// This Gist is a simple setup repro for https://github.com/rive-app/rive-android/issues/306 | |
// using Rive-Android 8.3.0 ("app.rive:rive-android:8.3.0") | |
/** | |
* Displays [Rive](https://rive.app/) animations | |
* | |
* NOTE: | |
* Rive native support for Compose is tracked at https://github.com/rive-app/rive-android/issues/259 | |
*/ | |
@Composable | |
fun RiveImage( | |
@ResId animationRessourceId: Int, | |
modifier: Modifier = Modifier, | |
stateController: RiveStateController? = null, | |
) { | |
// We wrap the AndroidView in a Box to correct positioning, for some reason when it was just | |
// the AndroidView it wouldn't center the RiveAnimationView as expected (slightly lower vertically) | |
Box(modifier = modifier) { | |
AndroidView( | |
factory = { context -> | |
RiveAnimationView(context) | |
}, | |
modifier = Modifier.align(Alignment.Center) | |
) { animationView -> | |
animationView.setRiveResource(animationResourceId) | |
} | |
} | |
} | |
@Composable | |
fun LoadingContent( | |
loading: State<Boolean>, | |
modifier: Modifier = Modifier, | |
content: @Composable () -> Unit | |
) { | |
Box(modifier = modifier) { | |
content() | |
AnimatedVisibility( | |
visible = loading.value, | |
) { | |
RiveImage( | |
animation = RiveAnimation.Resource(R.raw.tangrams), | |
modifier = Modifier | |
.fillMaxSize() | |
.background(MaterialTheme.colors.surface) | |
.contentDescription("Loading...") | |
) | |
} | |
} | |
} |
The RiveStateController
was unintentionally left in the example; it's from a more recent branch that we were adding support for changing the stateMachine, animations, and listeners but it's not currently used or tied-in to the code that we are running in production.
I'll play around and see if we can find any relevant patterns from crash reporting, etc. and update rive-app/rive-android#306 with any information we find.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@brianwernick Mmh yeah, I'm wondering if this is tied more to the lifecycle of the View than the example itself. We're trying to build a repro by stress-testing the view lifecycle a bit.
Also, there's a reference to a
RiveStateController
, but in the code snippet that's not being used. That might be relevant to reproduce the crash. Are you saving/restoring state? If so, could you share those bits too?