Load rive file from custom location
I'm using the iOS SDK v6.1.
In my app I'm downloading a rive file from a remote server. However creating a RiveViewModel
with a name tries to load a bundled .riv
file. Is there a way to use a custom file path to load the file?
Alternatively I can also let the SDK handle the download and initialize the view model by using RiveViewModel(webURL:)
. However this initializer doesn't seem to have the customLoader
to replace assets in runtime. Additionally using this initializer crashes with main (1): EXC_BAD_ACCESS (code=1, address=0x20)
when trying to configure it:
struct MyArtboardView: View { let viewModel: RiveViewModel init(viewModel: RiveViewModel) { self.viewModel = viewModel do { try viewModel.configureModel(artboardName: "myArtboardTitle") } catch { Logger.log(.error, "Rive: \(error)") } } var body: some View { viewModel.view() } }
This does not crash when using a locally bundled rive file and using the fileName
initializer.
So my question is: Is there A: a way of using a custom path to load a local rive file, or B: a non crashing way of loading a rive file using webURL
that also allows for a AssetLoader
closure.
I'm not sure. Let me grab our resident iOS expert and get back to you.
It looks like this got answered in Discord, but I'll add it here for posterity. :)
You can try the more verbose way of view model initialization by individually initializing the file, then the model, then the view model.
RiveFile
has a few initializers that take a URL, as well as a custom asset loader.
RiveModel
then has an initializer that takes aRiveFile
Finally,
RiveViewModel
has an initializer that takes aRiveModel