Add getName to experimental ViewModelInstance API#463
Conversation
There was a problem hiding this comment.
Pull request overview
Adds a new experimental API to retrieve a ViewModelInstance’s editor-assigned instance name by resolving it on the native command server thread (via runOnce) and returning it back to Kotlin, along with unit + instrumentation coverage.
Changes:
- Add
suspend fun ViewModelInstance.getName()to expose the resolved instance name. - Add
CommandQueue.getViewModelInstanceName(...)+ JNI bridge plumbing and native implementation to fetchViewModelInstance::name(). - Add unit test coverage for success/error paths and an Android instrumentation test asserting parity with the classic API.
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| kotlin/src/test/kotlin/app/rive/CommandQueueUnitTest.kt | Adds unit tests covering the new command-queue name lookup success and error behavior. |
| kotlin/src/main/kotlin/app/rive/ViewModelInstance.kt | Adds the new experimental getName() API on ViewModelInstance. |
| kotlin/src/main/kotlin/app/rive/core/CommandQueueBridge.kt | Extends the JNI bridge interface with cppGetViewModelInstanceName. |
| kotlin/src/main/kotlin/app/rive/core/CommandQueue.kt | Adds the suspend request + callback plumbing for retrieving a view model instance name. |
| kotlin/src/main/cpp/src/bindings/bindings_command_queue.cpp | Implements the JNI method that resolves instance name via CommandServer::getViewModelInstance(...)->name(). |
| kotlin/src/androidTest/kotlin/app/rive/core/ViewModelInstanceNameTest.kt | Adds an instrumented parity test against the classic API name resolution. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| * @throws RuntimeException If this instance has been [closed][close]. | ||
| * @throws IllegalStateException If the backing Rive worker has been released. | ||
| */ | ||
| suspend fun getName(): String = riveWorker.getViewModelInstanceName(instanceHandle) |
|
Hi @mfazekas. Thanks for this! I've cherry-picked your commit and added it upstream with some enhancements. You should get commit credit when it merges. Just a note if you end up doing enhancements like this in the future: |
|
Closing as the PR will merge from upstream. |
Summary
Adds
suspend fun ViewModelInstance.getName()to the experimental API, returning the editor-assigned instance name resolved by the command server.Consumers migrating from the classic API currently lose the instance name:
CommandQueueonly exposesgetViewModelInstanceNames(file, viewModelName)(the per-view-model name list), which cannot tell an existing instance which one it is. Instances created by name echo back what the caller already knew, while default, blank, nested (reference-path) and list-item instances have no way to learn their name at all.The command queue protocol has no message carrying an instance's own name (
getViewModelInstanceViewModelNamereturns the view model's name), so the binding resolves it withrunOnceon the command server thread viaCommandServer::getViewModelInstance()->name()and calls back into Kotlin from there — no runtime protocol change needed.Covered by unit tests and an instrumented test asserting parity with the classic API's
ViewModelInstance.namefor named, default, blank, nested and list-item instances againstdata_bind_test_impl.riv.The same gap exists in the rive-ios experimental API (RiveRuntime 6.20.4
ViewModelInstancehas no name member); the same design would apply there for parity.