Not getting event notifications on IOS / SwiftUI
Been trying to add in events to my Rive files to react to certain things. I copied the code from the runtime docs under the Apple section and under the Rive Events sections https://rive.app/docs/runtimes/rive-events I then added a event to my .riv file as seen in the attached images and using the code below, the event is never received. The debugPrint statements dont even run. Any help would be appreciated, surely i must be missing some basic step.
RiveRuntime 6.5.1
import RiveRuntime
struct RiveEventTesting: View {
@StateObject var animation = RiveEventViewModel(fileName: "port", artboardName: "intro")
var body: some View {
ZStack {
animation.riveView()
.onReceive(animation.$eventName) { name in
print(name)
}
}
}
}
class RiveEventViewModel: RiveViewModel {
@Published var eventName = ""
init(fileName: String, artboardName: String) {
super.init(fileName: fileName, artboardName: artboardName)
}
func riveView() -> some View {
return super.view()
}
@objc func onRiveEventReceived(onRiveEvent riveEvent: RiveEvent) {
debugPrint(riveEvent.name())
debugPrint(riveEvent.type())
if let generalEvent = riveEvent as? RiveGeneralEvent {
let eventProperties = generalEvent.properties()
if let message = eventProperties["message"] {
eventName = message as! String
}
}
}
}