@@ -16,20 +16,20 @@ import java.net.URL
1616
1717data class FileAndCache (
1818 val file : File ,
19- val cache : ReferencedAssetCache
19+ val cache : ReferencedAssetCache ,
20+ val loader : ReferencedAssetLoader ?
2021)
2122
2223@Keep
2324@DoNotStrip
2425class HybridRiveFileFactory : HybridRiveFileFactorySpec () {
25- private val assetLoader = ReferencedAssetLoader ()
26-
2726 private fun buildRiveFile (
2827 data : ByteArray ,
2928 referencedAssets : ReferencedAssetsType ?
3029 ): FileAndCache {
3130 val cache = mutableMapOf<String , app.rive.runtime.kotlin.core.FileAsset >()
32- val customLoader = assetLoader.createCustomLoader(referencedAssets, cache)
31+ val loader = ReferencedAssetLoader ()
32+ val customLoader = loader.createCustomLoader(referencedAssets, cache)
3333
3434 // TODO: The File object in Android does not have the concept of loading CDN assets
3535 val riveFile = if (customLoader != null ) {
@@ -38,7 +38,7 @@ class HybridRiveFileFactory : HybridRiveFileFactorySpec() {
3838 File (data)
3939 }
4040
41- return FileAndCache (riveFile, cache)
41+ return FileAndCache (riveFile, cache, if (customLoader != null ) loader else null )
4242 }
4343
4444 override fun fromURL (url : String , loadCdn : Boolean , referencedAssets : ReferencedAssetsType ? ): Promise <HybridRiveFileSpec > {
@@ -53,6 +53,7 @@ class HybridRiveFileFactory : HybridRiveFileFactorySpec() {
5353 val hybridRiveFile = HybridRiveFile ()
5454 hybridRiveFile.riveFile = fileAndCache.file
5555 hybridRiveFile.referencedAssetCache = fileAndCache.cache
56+ hybridRiveFile.assetLoader = fileAndCache.loader
5657 hybridRiveFile
5758 } catch (e: Exception ) {
5859 throw Error (" Failed to download Rive file: ${e.message} " )
@@ -79,6 +80,7 @@ class HybridRiveFileFactory : HybridRiveFileFactorySpec() {
7980 val hybridRiveFile = HybridRiveFile ()
8081 hybridRiveFile.riveFile = fileAndCache.file
8182 hybridRiveFile.referencedAssetCache = fileAndCache.cache
83+ hybridRiveFile.assetLoader = fileAndCache.loader
8284 hybridRiveFile
8385 } catch (e: Exception ) {
8486 throw Error (" Failed to load Rive file: ${e.message} " )
@@ -105,6 +107,7 @@ class HybridRiveFileFactory : HybridRiveFileFactorySpec() {
105107 val hybridRiveFile = HybridRiveFile ()
106108 hybridRiveFile.riveFile = fileAndCache.file
107109 hybridRiveFile.referencedAssetCache = fileAndCache.cache
110+ hybridRiveFile.assetLoader = fileAndCache.loader
108111 hybridRiveFile
109112 } catch (e: Exception ) {
110113 throw Error (" Failed to load Rive file: ${e.message} " )
@@ -122,6 +125,7 @@ class HybridRiveFileFactory : HybridRiveFileFactorySpec() {
122125 val hybridRiveFile = HybridRiveFile ()
123126 hybridRiveFile.riveFile = fileAndCache.file
124127 hybridRiveFile.referencedAssetCache = fileAndCache.cache
128+ hybridRiveFile.assetLoader = fileAndCache.loader
125129 hybridRiveFile
126130 } catch (e: Exception ) {
127131 throw Error (" Failed to load Rive file from bytes: ${e.message} " )
0 commit comments