Skip to content

Add getName to experimental ViewModelInstance API#463

Closed
mfazekas wants to merge 1 commit into
rive-app:masterfrom
mfazekas:feat/view-model-instance-get-name
Closed

Add getName to experimental ViewModelInstance API#463
mfazekas wants to merge 1 commit into
rive-app:masterfrom
mfazekas:feat/view-model-instance-get-name

Conversation

@mfazekas

@mfazekas mfazekas commented Jul 9, 2026

Copy link
Copy Markdown
Contributor

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: CommandQueue only exposes getViewModelInstanceNames(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 (getViewModelInstanceViewModelName returns the view model's name), so the binding resolves it with runOnce on the command server thread via CommandServer::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.name for named, default, blank, nested and list-item instances against data_bind_test_impl.riv.

The same gap exists in the rive-ios experimental API (RiveRuntime 6.20.4 ViewModelInstance has no name member); the same design would apply there for parity.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 fetch ViewModelInstance::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)
@ErikUggeldahl ErikUggeldahl self-assigned this Jul 13, 2026
@ErikUggeldahl ErikUggeldahl added the enhancement New feature or request label Jul 13, 2026
@ErikUggeldahl

Copy link
Copy Markdown
Collaborator

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: runOnce is more of an escape hatch meant to be used for platform specifics (Android in this case) or testing functions. For canonical functions like getting the VMI name, it makes sense to add it to the API surface.

@ErikUggeldahl

Copy link
Copy Markdown
Collaborator

Closing as the PR will merge from upstream.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants