Skip to content

feat: add dataBind prop to RiveView#23

Merged
mfazekas merged 24 commits intomainfrom
view-model-instance
Nov 18, 2025
Merged

feat: add dataBind prop to RiveView#23
mfazekas merged 24 commits intomainfrom
view-model-instance

Conversation

@mfazekas
Copy link
Copy Markdown
Collaborator

@mfazekas mfazekas commented Nov 13, 2025

Add a dataBind property to allow binding viewModelInstance in a declarative way.

Usages:
1.) Set and instance => no ref needed

const { riveViewRef, setHybridRef } = useRive();

 useEffect(() => {
   if (riveViewRef) {
     riveViewRef.bindViewModelInstance(instance);
   }
 }, [riveViewRef, instance]);
 
 
 return (
   <RiveView
      hybridRef={setHybridRef}
    />
 )
to just:
 return (
   <RiveView
      bind={instance}
    />
 )

2.) Also accepts by name:

<RiveView dataBind={{byName: 'green'}} />

3.) None or Auto for default

<RiveView dataBind={DataBindMode.AUTO} />

@mfazekas mfazekas force-pushed the view-model-instance branch from c981692 to d888d84 Compare November 13, 2025 15:25
@mfazekas mfazekas requested a review from HayesGordon November 13, 2025 16:38
@mfazekas mfazekas changed the title feat: add viewModelInstance to ViewProps, so we don't need to wait for ref feat: add bind to ViewProps, so we don't need to wait for ref Nov 14, 2025
@mfazekas mfazekas changed the title feat: add bind to ViewProps, so we don't need to wait for ref feat: add dataBind prop to RiveView Nov 17, 2025
@mfazekas mfazekas force-pushed the view-model-instance branch from d07d887 to 0358e2a Compare November 17, 2025 12:59
mfazekas and others added 15 commits November 17, 2025 14:00
- Remove needsReload trigger from dataBind property changes
- Add in-place binding update methods for both platforms
- Fix flicker when switching between binding modes

iOS Changes:
- Add applyDataBinding() method on RiveReactNativeView
- Call applyDataBinding() in didSet instead of needsReload
- Directly call bind/enableAutoBind/disableAutoBind on existing view

Android Changes:
- Add custom setter for dataBind property
- Add configureDataBinding() method
- Directly update viewModelInstance on existing state machine
- Make riveAnimationView internal for access from HybridRiveView

Result:
- Smooth transitions between red/green/blue/none/auto modes
- No visual flicker or reload when switching binding modes
- Better performance (no view recreation)

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
- Add artboard.bind(viewModelInstance:) in addition to stateMachine binding
- Required for visual changes to take effect when switching binding modes
- Matches old rive-react-native implementation pattern

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
- Add baseViewModel?.play() after binding view model instance
- Forces view to refresh and show the new binding state
- Helps ensure visual updates appear immediately

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
- Add baseViewModel?.play() for .none and .auto cases
- Ensures view refreshes when switching to these modes
- All binding modes now trigger play() for consistent behavior
- Fix prettier formatting in example

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
- Add artboard.viewModelInstance binding in addition to stateMachine
- Add view.play() call after all binding mode changes
- Matches iOS implementation for consistent behavior
- Ensures visual updates appear when switching modes

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
- Remove in-place configureDataBinding() method
- Set needsReload = true and call afterUpdate() when dataBind changes
- Matches old rive-react-native pattern for referencedAssets changes
- Full reload via setRiveFile() with new binding configuration
- iOS keeps play() approach for smoother experience

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
- Remove afterUpdate() call from custom setter
- React Native automatically calls afterUpdate() after all props update
- Prevents potential double-reload issues

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
- Add isFirstConfigure flag to track initial load
- Call play(stateMachineName, isStateMachine: true) after reload
- Only play on subsequent reloads, not on first configure
- Ensures state machine restarts with new binding

iOS note: iOS already calls baseViewModel.play() in applyDataBinding()
which handles non-first updates through the didSet mechanism

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
@mfazekas mfazekas force-pushed the view-model-instance branch from 0358e2a to 9c39621 Compare November 17, 2025 13:01
HayesGordon
HayesGordon previously approved these changes Nov 18, 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.

LGTM! Thanks for this!

@mfazekas mfazekas requested a review from HayesGordon November 18, 2025 14:52
@mfazekas mfazekas merged commit 592b189 into main Nov 18, 2025
17 of 20 checks passed
@HayesGordon HayesGordon deleted the view-model-instance branch December 9, 2025 16:27
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