更新记录

1.0.0(2026-02-27)

  • 首次发布 hans-rive
  • 支持 uni-app xApp-AndroidApp-iOS
  • 提供基础配置:srcautoPlayloopartboardNameanimationNamestateMachineNamedebug
  • 提供实例方法:play()pause()stop()reset()
  • 提供事件:readyplaypausestoperror(message)

平台兼容性

uni-app x(4.87)

Chrome Safari Android iOS 鸿蒙 微信小程序
- - - -

hans-rive

hans-rive 是一个 uni-app x 原生 Rive 组件,支持 App-AndroidApp-iOS

使用文档

平台支持

  • uni-app x / app-android:
  • uni-app x / app-ios:
  • uni-app x / app-harmony: -
  • 其他平台:-

安装

  • 在 HBuilderX 插件市场搜索 hans-rive,选择并导入到当前项目。
  • 导入后插件会自动安装到项目的 uni_modules/hans-rive 目录。
  • 组件可直接使用:<hans-rive />

快速开始

<template>
  <hans-rive
    ref="riveRef"
    style="width: 240px; height: 240px;"
    src="/static/animations/demo.riv"
    :autoPlay="true"
    :loop="true"
    :debug="false"
    @ready="onReady"
    @error="onError"
  />
</template>

<script setup lang="uts">
import { ref } from 'vue'
import { HansRiveInstance } from '@/uni_modules/hans-rive'

const riveRef = ref(null as HansRiveInstance | null)

function onReady() {
  riveRef.value?.play()
}

function onError(message: string) {
  console.error('[hans-rive]', message)
}
</script>

Props

  • src: string:Rive 文件路径。建议使用 /static/... 本地资源路径。
  • autoPlay?: boolean:是否自动播放。默认 true
  • loop?: boolean:是否循环播放。默认 true
  • artboardName?: string:可选,指定 Artboard 名称。
  • animationName?: string:可选,指定 Animation 名称。
  • stateMachineName?: string:可选,指定 StateMachine 名称。
  • debug?: boolean:是否开启调试日志。默认 false
  • command?: string:命令式控制,支持 play | pause | stop | reset
  • commandVersion?: number:命令版本号。每次下发新命令时递增,触发 command 执行。
  • width?: string | number:组件宽度(如 240240px100%)。
  • height?: string | number:组件高度(如 240240px100%)。

Methods(通过 ref 调用)

  • play():播放。
  • pause():暂停。
  • stop():停止。
  • reset():重置到初始状态。

Events

  • ready:原生视图初始化完成。
  • play:调用播放后触发。
  • pause:调用暂停后触发。
  • stop:调用停止后触发。
  • error(message: string):初始化或配置更新异常。

注意事项

  • src 仅支持项目内可访问的本地资源(推荐放在 static/ 目录)。
  • 使用 command 时需要同步递增 commandVersion,否则不会重复触发同一命令。

隐私、权限声明

1. 本插件需要申请的系统权限列表:

2. 本插件采集的数据、发送的服务器地址、以及数据用途说明:

3. 本插件是否包含广告,如包含需详细说明广告表达方式、展示频率:

暂无用户评论。