✅ Android Event Logging
Hi all,
I am very new to Rive and I have been developing some very simple proofs of concept with Rive in React, iOS and Android.
For this I made a simple file with some circles that have three timelines that can be played (there is also a state machine with triggers but I have currently just been playing it via the timelines only)
In the Rive file there are events that trigger at the end of each timeline and I have just been trying to log to the console when these events are triggered. I have been able to achieve this in iOS and React - but I have been struggling to do so in Android with my composable.
@Composable
fun RiveAnimationContainer(
@RawRes animation: Int,
modifier: Modifier = Modifier,
stateMachineName: String? = null,
alignment: app.rive.runtime.kotlin.core.Alignment = app.rive.runtime.kotlin.core.Alignment.CENTER,
fit: Fit = Fit.CONTAIN,
onInit: (RiveAnimationView) -> Unit,
) {
AndroidView(
modifier = modifier,
factory = { context ->
RiveAnimationView(context).also { riveView ->
riveView.setRiveResource(
resId = animation,
stateMachineName = stateMachineName,
alignment = alignment,
fit = fit,
)
riveView.addEventListener(eventListener)
}
},
update = { view -> onInit(view) }
)
}
val eventListener = object : RiveFileController.RiveEventListener {
override fun notifyEvent(event: RiveEvent) {
Log.e("RiveEvent", "Event name: ${event.name}")
}
}I know that the creation of this event listener could be done in a nicer way - but I just want to be able to see that the event name can be logged. Does anyone know where I am going wrong?
Here is the .rev file and .riv file if this helps :)
I should add that I am playing the animation later in the code like so and it does play the animation, but it does not log the event name that occurs at the end of this timeline.
riveAnimation?.play("Spin", Loop.ONESHOT, Direction.FORWARDS)