|
| 1 | +/** |
| 2 | + * Reproducer for https://github.com/rive-app/rive-nitro-react-native/issues/189 |
| 3 | + * |
| 4 | + * [Android] Rive files that have ViewModels but no default ViewModel for the |
| 5 | + * artboard freeze when dataBind is not explicitly set (defaults to Auto). |
| 6 | + * |
| 7 | + * Root cause: in Auto mode Android checks viewModelCount > 0 and passes |
| 8 | + * autoBind=true to setRiveFile. The Rive SDK then throws |
| 9 | + * "No default ViewModel found for artboard" when the artboard has no default |
| 10 | + * ViewModel assigned, which freezes the animation. |
| 11 | + * |
| 12 | + * Fix: don't use SDK-level autoBind for Auto mode. Let bindToStateMachine |
| 13 | + * handle it — it already catches ViewModelException gracefully. |
| 14 | + * |
| 15 | + * Marketplace: https://rive.app/community/files/27026-50856-no-default-vm-for-artboard/ |
| 16 | + * |
| 17 | + * Expected: bouncing animation plays on both platforms |
| 18 | + * Actual (Android, unfixed): animation freezes, ViewModelInstanceNotFound error |
| 19 | + */ |
| 20 | + |
| 21 | +import { View, StyleSheet, Text } from 'react-native'; |
| 22 | +import { RiveView, useRiveFile } from '@rive-app/react-native'; |
| 23 | +import { type Metadata } from '../shared/metadata'; |
| 24 | + |
| 25 | +export default function Issue189Page() { |
| 26 | + const { riveFile, error } = useRiveFile( |
| 27 | + require('../../assets/rive/nodefaultbouncing.riv') |
| 28 | + ); |
| 29 | + |
| 30 | + return ( |
| 31 | + <View style={styles.container}> |
| 32 | + {error != null && ( |
| 33 | + <Text style={styles.errorText}>Error: {String(error)}</Text> |
| 34 | + )} |
| 35 | + {riveFile && ( |
| 36 | + <RiveView |
| 37 | + file={riveFile} |
| 38 | + autoPlay={true} |
| 39 | + // No dataBind prop — defaults to Auto. On Android (unfixed) this |
| 40 | + // triggers "No default ViewModel found for artboard" and freezes. |
| 41 | + style={styles.rive} |
| 42 | + /> |
| 43 | + )} |
| 44 | + </View> |
| 45 | + ); |
| 46 | +} |
| 47 | + |
| 48 | +Issue189Page.metadata = { |
| 49 | + name: 'Issue #189', |
| 50 | + description: |
| 51 | + '[Android] Animation with ViewModels but no artboard default freezes in Auto dataBind mode', |
| 52 | +} satisfies Metadata; |
| 53 | + |
| 54 | +const styles = StyleSheet.create({ |
| 55 | + container: { |
| 56 | + flex: 1, |
| 57 | + backgroundColor: '#fff', |
| 58 | + }, |
| 59 | + errorText: { |
| 60 | + color: 'red', |
| 61 | + textAlign: 'center', |
| 62 | + padding: 8, |
| 63 | + }, |
| 64 | + rive: { |
| 65 | + flex: 1, |
| 66 | + width: '100%', |
| 67 | + }, |
| 68 | +}); |
0 commit comments