Skip to content

feat: Reanimated shared value → Rive property binding#64

Merged
mfazekas merged 11 commits into
mainfrom
mfazekas/rnrea-shared-values
Dec 8, 2025
Merged

feat: Reanimated shared value → Rive property binding#64
mfazekas merged 11 commits into
mainfrom
mfazekas/rnrea-shared-values

Conversation

@mfazekas
Copy link
Copy Markdown
Collaborator

@mfazekas mfazekas commented Dec 3, 2025

Summary

  • Added playIfNeeded() to make sure rive graphics is not in steady state after update
  • Adds example demonstrating driving Rive properties from Reanimated shared values
  • Uses NitroModules.box() to share ViewModelNumberProperty with worklets
  • Updates happen synchronously on UI thread - no async bridging

How it works

const boxedProperty = useMemo(() => {
  const posYProperty = instance.numberProperty('posY');
  return NitroModules.box(posYProperty);
}, [instance]);

useAnimatedReaction(
  () => progress.value,
  (value) => {
    'worklet';
    const property = boxedProperty.unbox() as ViewModelNumberProperty;
    property.value = value;  // Direct setter on UI thread!
   }
);

Test plan

  • Run the "Reanimated Shared Value" example
  • Blue circle (React Native) and red circle (Rive) should animate in sync

In slow motion there is up to 1 frame difference:

Comment thread nitrogen/generated/android/c++/JFunc_void.hpp
HayesGordon
HayesGordon previously approved these changes Dec 4, 2025
Copy link
Copy Markdown
Contributor

@HayesGordon HayesGordon left a comment

Choose a reason for hiding this comment

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

Nice!

Demonstrates driving Rive ViewModelNumberProperty from Reanimated shared values
using NitroModules.box() to share HybridObjects with worklets.
@mfazekas mfazekas force-pushed the mfazekas/rnrea-shared-values branch from e8715a1 to b26295e Compare December 4, 2025 15:04
@mfazekas mfazekas force-pushed the mfazekas/rnrea-shared-values branch from c179481 to 270562d Compare December 4, 2025 16:26
@mfazekas mfazekas requested a review from HayesGordon December 5, 2025 14:34
@mfazekas mfazekas merged commit de1c4c5 into main Dec 8, 2025
7 checks passed
mfazekas added a commit that referenced this pull request Dec 9, 2025
PR #40 was merged with nitrogen files generated by nitro-modules@0.31.8.
PR #64 upgraded to nitro-modules@0.31.10 but was developed before PR #40
merged, so it didn't regenerate ViewModelImageProperty.

The new nitro-modules version requires JNICallable.hpp include.
mfazekas added a commit that referenced this pull request Dec 9, 2025
* fix: regenerate nitrogen files for nitro-modules 0.31.10

PR #40 was merged with nitrogen files generated by nitro-modules@0.31.8.
PR #64 upgraded to nitro-modules@0.31.10 but was developed before PR #40
merged, so it didn't regenerate ViewModelImageProperty.

The new nitro-modules version requires JNICallable.hpp include.

* fix(android): fix HybridViewModelImageProperty addListener type mismatch

The listeners property is MutableList<(Unit) -> Unit> but onChanged is () -> Unit.
Wrap in lambda to match the expected signature, same pattern as TriggerProperty.

* fix(android): fix updateAsset call signature after PR #63 refactor

PR #63 changed updateAsset from 3 args to 2 args (removed context) in
ReferencedAssetLoader but missed updating the call site in HybridRiveFile.

* fix(ci): force turbo rebuild on stale cache fallback match
@HayesGordon HayesGordon deleted the mfazekas/rnrea-shared-values branch December 9, 2025 16:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants