From db7e9bba770ca8596bbd9f12003da731f693de99 Mon Sep 17 00:00:00 2001 From: Gordon Hayes Date: Tue, 4 Jun 2024 19:23:32 +0200 Subject: [PATCH] feat: add nested inputs --- android/build.gradle | 2 +- .../rivereactnative/RiveReactNativeView.kt | 24 ++++++++ .../RiveReactNativeViewManager.kt | 29 ++++++++++ .../main/res/raw/runtime_nested_inputs.riv | Bin 0 -> 947 bytes example/ios/Assets/runtime_nested_inputs.riv | Bin 0 -> 947 bytes .../project.pbxproj | 6 ++ example/src/NestedInputs.tsx | 53 ++++++++++++++++-- ios/RiveReactNativeView.swift | 12 ++++ ios/RiveReactNativeViewManager.m | 3 + ios/RiveReactNativeViewManager.swift | 22 ++++++++ package.json | 2 +- src/Rive.tsx | 33 +++++++++++ src/types.ts | 9 +++ 13 files changed, 187 insertions(+), 8 deletions(-) create mode 100644 example/android/app/src/main/res/raw/runtime_nested_inputs.riv create mode 100644 example/ios/Assets/runtime_nested_inputs.riv diff --git a/android/build.gradle b/android/build.gradle index ade2dc9..606bee6 100644 --- a/android/build.gradle +++ b/android/build.gradle @@ -138,7 +138,7 @@ dependencies { implementation 'androidx.core:core-ktx:1.12.0' implementation 'androidx.appcompat:appcompat:1.6.1' implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core:1.4.1' - implementation 'app.rive:rive-android:9.3.6' + implementation 'app.rive:rive-android:9.4.0' implementation "androidx.startup:startup-runtime:1.1.1" implementation 'com.android.volley:volley:1.2.0' } diff --git a/android/src/main/java/com/rivereactnative/RiveReactNativeView.kt b/android/src/main/java/com/rivereactnative/RiveReactNativeView.kt index 911f608..6f56dd9 100644 --- a/android/src/main/java/com/rivereactnative/RiveReactNativeView.kt +++ b/android/src/main/java/com/rivereactnative/RiveReactNativeView.kt @@ -495,6 +495,30 @@ class RiveReactNativeView(private val context: ThemedReactContext) : FrameLayout } } + fun fireStateAtPath(inputName: String, path: String) { + try { + riveAnimationView.fireStateAtPath(inputName, path) + } catch (ex: RiveException) { + handleRiveException(ex) + } + } + + fun setBooleanStateAtPath(inputName: String, value: Boolean, path: String) { + try { + riveAnimationView.setBooleanStateAtPath(inputName, value, path) + } catch (ex: RiveException) { + handleRiveException(ex) + } + } + + fun setNumberStateAtPath(inputName: String, value: Float, path: String) { + try { + riveAnimationView.setNumberStateAtPath(inputName, value, path) + } catch (ex: RiveException) { + handleRiveException(ex) + } + } + private fun handleRiveException(exception: RiveException) { if (isUserHandlingErrors) { val rnRiveError = RNRiveError.mapToRNRiveError(exception) diff --git a/android/src/main/java/com/rivereactnative/RiveReactNativeViewManager.kt b/android/src/main/java/com/rivereactnative/RiveReactNativeViewManager.kt index 30766c7..7df8989 100644 --- a/android/src/main/java/com/rivereactnative/RiveReactNativeViewManager.kt +++ b/android/src/main/java/com/rivereactnative/RiveReactNativeViewManager.kt @@ -70,6 +70,35 @@ class RiveReactNativeViewManager : SimpleViewManager() { } } } + "fireStateAtPath" -> { + args?.let { + val inputName = it.getString(0) + val path = it.getString(1) + view.run { + fireStateAtPath(inputName, path) + } + } + } + "setBooleanStateAtPath" -> { + args?.let { + val inputName = it.getString(0) + val value = it.getBoolean(1) + val path = it.getString(2) + view.run { + setBooleanStateAtPath(inputName, value, path) + } + } + } + "setNumberStateAtPath" -> { + args?.let { + val inputName = it.getString(0) + val value = it.getDouble(1) + val path = it.getString(2) + view.run { + setNumberStateAtPath(inputName, value.toFloat(), path) + } + } + } // Touch Events diff --git a/example/android/app/src/main/res/raw/runtime_nested_inputs.riv b/example/android/app/src/main/res/raw/runtime_nested_inputs.riv new file mode 100644 index 0000000000000000000000000000000000000000..04c2395c9713e1bc4dfcd3501950506d9c69e236 GIT binary patch literal 947 zcmZXSJ8u&~6ot>-hwYe`iHs3Y#En~|4T{1;5PO#hM)@kX!yiqPR@_4*NCWyq zCv-%ogxTjR$T`0mM(u`7wmYGGlLwkXL6xDMJK@8xoO3}WcVh9hn+WOR0?=<uhdX`NH60XXCq_m8RH~LMr`W-zIfI&lT9`n+dA2kUbvn+VW~huDO}T218P~fLu3DYv ts^xjEI(j;7W1utv3eI0WB`Z0v>v0^tdoK-hwYe`iHs3Y#En~|4T{1;5PO#hM)@kX!yiqPR@_4*NCWyq zCv-%ogxTjR$T`0mM(u`7wmYGGlLwkXL6xDMJK@8xoO3}WcVh9hn+WOR0?=<uhdX`NH60XXCq_m8RH~LMr`W-zIfI&lT9`n+dA2kUbvn+VW~huDO}T218P~fLu3DYv ts^xjEI(j;7W1utv3eI0WB`Z0v>v0^tdoK(null); + return ( +