画板
有关在 Rive 编辑器中创建画板的更多信息,请参阅画板。
选择画板
当 Rive 对象被实例化或 Rive 文件被渲染时,您可以指定要使用的画板。如果未指定画板,则使用在 Rive 编辑器中设置的默认画板。如果未设置默认画板,则使用第一个画板。
一次只能渲染一个画板。
新版运行时(推荐)
列出画板(Listing artboards)
加载 RiveFile 后,您可以获取其中包含的画板:
const { riveFile } = useRiveFile(require('./assets/my_file.riv'));
// 在 effect 或事件处理程序中
const artboardNames = await riveFile.getArtboardNamesAsync();
const artboardCount = await riveFile.getArtboardCountAsync();
显示画板(Displaying an artboard)
在 RiveView 上设置 artboardName 属性。如果省略,则使用默认画板。
export default function App() {
const { riveFile } = useRiveFile(require('./assets/my_file.riv'));
return riveFile ? (
<RiveView
file={riveFile}
artboardName="My Artboard"
style={{ width: 400, height: 400 }}
/>
) : null;
}
如果没有该名称的画板,RiveView 会通过 onError 报告错误。参见错误处理。
要在运行时将一个画板渲染到另一个画板内,请使用数据绑定中的画板属性。
旧版运行时
export default function App() {
return (
<View>
<Rive resourceName="my_rive_file" artboardName="My Artboard" autoplay />
</View>
);
}