rive-react-native
rive-react-native copied to clipboard
Being able to import local rive files
Hi there, thanks for updating the run times! is there any way we can require('../assets/myRive.riv') rive files so that the run time can consume it? thanks.
Hello, You can follow this https://github.com/rive-app/rive-react-native/issues/123#issuecomment-1522169006, it worked for me.
Hello, You can follow this #123 (comment), it worked for me.
Thanks, I'm using expo and android, can not apply the patch :(
I am using expo as well and using patch-package and this patch (almost the same patch by nderscore, thanks to him)
diff --git a/node_modules/rive-react-native/android/src/main/java/com/rivereactnative/RiveReactNativeView.kt b/node_modules/rive-react-native/android/src/main/java/com/rivereactnative/RiveReactNativeView.kt
index 53779aa..9996319 100644
--- a/node_modules/rive-react-native/android/src/main/java/com/rivereactnative/RiveReactNativeView.kt
+++ b/node_modules/rive-react-native/android/src/main/java/com/rivereactnative/RiveReactNativeView.kt
@@ -20,6 +20,7 @@ import com.facebook.react.bridge.ReadableArray
import com.facebook.react.modules.core.ExceptionsManagerModule
import com.facebook.react.uimanager.ThemedReactContext
import java.io.UnsupportedEncodingException
+import java.util.Base64
import kotlin.IllegalStateException
@@ -300,6 +301,24 @@ class RiveReactNativeView(private val context: ThemedReactContext) : FrameLayout
private fun setUrlRiveResource(url: String, autoplay: Boolean = this.autoplay) {
+ if (url.startsWith("data:")) {
+ val b64data = url.substringAfter(',')
+ val decoder: Base64.Decoder = Base64.getDecoder()
+ val bytes = decoder.decode(b64data)
+
+ riveAnimationView.setRiveBytes(
+ bytes,
+ fit = this.fit,
+ alignment = this.alignment,
+ autoplay = autoplay,
+ stateMachineName = this.stateMachineName,
+ animationName = this.animationName,
+ artboardName = this.artboardName
+ )
+
+ return
+ }
+
val queue = Volley.newRequestQueue(context)
val stringRequest = RNRiveFileRequest(url, { bytes ->
try {
I had to rebuild a version with eas to make it work.