✅ Solved: Android Autobinding - How to get VMI

Hi there,

I have been trying to make some POC’s of data binding (specifically with adding listeners to triggers in a view model) in React, iOS and Android. But I am having some issues trying to access the view model instance after autobinding has been applied on android.

Following the documentation at https://rive.app/docs/runtimes/data-binding in the autobinding section it shows you for react how to access the instance after autobinding

const { rive, RiveComponent } = useRive({
    src: 'your_file.riv',
    artboard: 'MyArtboard',
    stateMachine: 'MyStateMachine',
    autoBind: true, // Enable auto-binding
    // ... other options
});

// Once loaded, the instance is available:
const boundInstance = rive?.viewModelInstance;

It also shows you how to access it in Swift for iOS

let riveViewModel = RiveViewModel(...)
riveViewModel.riveModel.enableAutoBind { instance in
    // Store a reference to `instance` to later access properties
    // The instance may change as state machines and artboards change
}

// If you'd like to disable autoBind after enabling…
riveViewModel.riveModel!.disableAutoBind()

But in the android section, it doesn’t show you how you store the instance for use later on it just shows how to enable it

view.setRiveResource(
    R.raw.my_rive_file,
    autoBind = true,
)

Does anyone know how you can access this view model instance after autobinding has been applied in Android ?