跳到主要内容

ViewModel

表示用于数据绑定的视图模型。

ViewModel 提供可在运行时读取和修改的结构化数据,使 Rive 文件能够响应应用程序状态。

type ViewModelExample = {
character: Input<Artboard<Data.Character>>,
instance: Artboard<Data.Character>?,
}

function init(self: ViewModelExample, context: Context): boolean
local vm = Data.Character.new()
self.instance = self.character:instance(vm)
return true
end

return function(): Node<ViewModelExample>
return {
character = late(),
instance = nil,
init = init,
}
end