fix: support clearing image and artboard properties on the new runtime - #360
Open
mfazekas wants to merge 2 commits into
Open
fix: support clearing image and artboard properties on the new runtime#360mfazekas wants to merge 2 commits into
mfazekas wants to merge 2 commits into
Conversation
`ViewModelImageProperty.set` and `ViewModelArtboardProperty.set` are typed to accept `undefined`, but both new-runtime backends dropped it: the iOS image property threw "Invalid image type", and the iOS artboard and Android artboard properties returned silently. Passing `undefined` now clears the property. Android image clearing stays a no-op for now — `ViewModelInstance.setImage` only accepts a non-null `ImageAsset` up to rive-android 11.7.2. The nullable overload landed upstream in rive-app/rive-android#13261 and ships in the next release; the call is logged instead of silently dropped until we bump the pin. Setting an image (and instantiating an artboard) is asynchronous, so a slow decode could previously land after a later `set()` and resurrect a stale value. Both properties now carry a generation counter and drop outdated completions.
The name said it verified clearing; it only asserts that set(undefined) does not throw, which is all the API allows — image properties are write-only and addListener is a no-op on both new backends. On Android's new backend it passes because the call is deliberately dropped, so green must not be read as 'clearing works'.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
ViewModelImageProperty.setandViewModelArtboardProperty.setare typed to acceptundefined— the artboard one is even documented as "pass undefined to clear" — but both new-runtime backends dropped it. The iOS image property threwInvalid image type - expected HybridRiveImage, and the iOS artboard and Android artboard properties returned silently. Passingundefinednow clears the property. Both legacy backends already handled this correctly.Android image clearing stays a no-op for now:
ViewModelInstance.setImageonly accepts a non-nullImageAssetup to rive-android 11.7.2. The nullable overload landed upstream in rive-app/rive-android#13261 and ships in the next release — until we bump the pin the call is logged rather than silently dropped. Swapping the log forsetImage(path, null)is the whole follow-up.Setting an image (and instantiating an artboard) is asynchronous on both new backends, so a slow decode could land after a later
set()and resurrect a stale value — including overwriting a clear. Both properties now carry a generation counter and drop outdated completions.Verification: built and ran the example on the iOS simulator against the new runtime (RiveRuntime 6.21.1).
imageProperty.set(undefined)no longer throws — that call is a hard error onmain— andartboardProperty.set(undefined)runs clean with no crash. I could not visually confirm the slot actually empties: neitherdatabinding_images.rivnormany_viewmodels.rivgives a usable visual channel, since the bound image slot renders its authored image regardless. Worth confirming against a.rivauthored for this, and re-checking once the runtimes that support clearing ship.Adds
example/src/reproducers/ClearImageAndArtboard.tsxfor manual checks, plus a harness case forimageProperty.set(undefined)which fails on the unfixed iOS build.