Skip to content

Commit

Permalink
fix: nested triggers at path using incorrect method parameter
Browse files Browse the repository at this point in the history
Brought up on Slack here: https://2dimensions.slack.com/archives/C029X99PETE/p1727370202337659

Explicitly setting the argument names. Added tests.

Diffs=
68f58eef4 fix: nested triggers at path using incorrect method parameter (#8237)

Co-authored-by: Gordon <[email protected]>
  • Loading branch information
HayesGordon and HayesGordon committed Sep 27, 2024
1 parent 60d9936 commit 1a214e5
Show file tree
Hide file tree
Showing 4 changed files with 85 additions and 10 deletions.
2 changes: 1 addition & 1 deletion .rive_head
Original file line number Diff line number Diff line change
@@ -1 +1 @@
4566a1208a50671aede1fd1bf30a1806b757c343
68f58eef4ef521e93a5ada5cb3bf4fbfc7c7687d
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
package app.rive.runtime.kotlin.core

import androidx.test.ext.junit.runners.AndroidJUnit4
import androidx.test.internal.runner.junit4.statement.UiThreadStatement
import app.rive.runtime.kotlin.core.errors.StateMachineInputException
import app.rive.runtime.kotlin.test.R
import org.junit.Assert.assertThrows
import org.junit.Before
import org.junit.Test
import org.junit.runner.RunWith

@RunWith(AndroidJUnit4::class)
class RiveNestedInputsTest {
private val testUtils = TestUtils()
private val appContext = testUtils.context
private lateinit var view: TestUtils.MockRiveAnimationView


@Before
fun init() {
view = TestUtils.MockRiveAnimationView(appContext)
}

@Test
fun can_set_inputs_at_path_no_errors() {
UiThreadStatement.runOnUiThread {
view.setRiveResource(R.raw.nested_inputs_test, artboardName = "Artboard", stateMachineName = "State Machine 1")
view.play()
view.setBooleanStateAtPath("bool", true, "nested")
view.setNumberStateAtPath("number", 1f, "nested")
view.fireStateAtPath("trigger", "nested")
}
}

@Test
fun set_incorrect_name_inputs_at_path_throws() {
UiThreadStatement.runOnUiThread {
view.setRiveResource(R.raw.nested_inputs_test, artboardName = "Artboard", stateMachineName = "State Machine 1")
view.play()
assertThrows(StateMachineInputException::class.java) {
view.setBooleanStateAtPath("wrongname", true, "nested")
view.artboardRenderer?.advance(0.16f)
}
assertThrows(StateMachineInputException::class.java) {
view.setNumberStateAtPath("wrongname", 1f, "nested")
view.artboardRenderer?.advance(0.16f)
}
assertThrows(StateMachineInputException::class.java) {
view.fireStateAtPath("wrongname", "nested")
view.artboardRenderer?.advance(0.16f)
}
}
}

@Test
fun set_incorrect_path_inputs_at_path_throws() {
UiThreadStatement.runOnUiThread {
view.setRiveResource(R.raw.nested_inputs_test, artboardName = "Artboard", stateMachineName = "State Machine 1")
view.play()
assertThrows(StateMachineInputException::class.java) {
view.setBooleanStateAtPath("bool", true, "wrongPath")
view.artboardRenderer?.advance(0.16f)
}
assertThrows(StateMachineInputException::class.java) {
view.setNumberStateAtPath("number", 1f, "wrongPath")
view.artboardRenderer?.advance(0.16f)
}
assertThrows(StateMachineInputException::class.java) {
view.fireStateAtPath("trigger", "wrongPath")
view.artboardRenderer?.advance(0.16f)
}
}
}

}
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -550,27 +550,27 @@ class RiveFileController(
}

fun fireState(stateMachineName: String, inputName: String, path: String? = null) {
queueInput(stateMachineName, inputName, path)
queueInput(stateMachineName = stateMachineName, inputName = inputName, path = path)
}

fun setBooleanState(stateMachineName: String, inputName: String, value: Boolean, path: String? = null) {
queueInput(stateMachineName, inputName, value, path)
queueInput(stateMachineName = stateMachineName, inputName = inputName, value = value, path = path)
}

fun setNumberState(stateMachineName: String, inputName: String, value: Float, path: String? = null) {
queueInput(stateMachineName, inputName, value, path)
queueInput(stateMachineName = stateMachineName, inputName = inputName, value = value, path = path)
}

fun fireStateAtPath(inputName: String, path: String) {
queueInput("", inputName, path)
queueInput(stateMachineName = "", inputName = inputName, path = path)
}

fun setBooleanStateAtPath(inputName: String, value: Boolean, path: String) {
queueInput("", inputName, value, path)
queueInput(stateMachineName = "", inputName = inputName, value = value, path = path)
}

fun setNumberStateAtPath(inputName: String, value: Float, path: String) {
queueInput("", inputName, value, path)
queueInput(stateMachineName = "", inputName = inputName, value = value, path = path)
}

/**
Expand Down Expand Up @@ -611,7 +611,7 @@ class RiveFileController(
}
}

private var userSetVolume: Float? = null; // Default value
private var userSetVolume: Float? = null // Default value

/**
* Get the active [Artboard]'s volume.
Expand All @@ -622,8 +622,8 @@ class RiveFileController(
* Set the active [Artboard]'s volume to [value].
*/
fun setVolume(value: Float) {
userSetVolume = value;
activeArtboard?.volume = value;
userSetVolume = value
activeArtboard?.volume = value
}

private fun animations(animationName: String): List<LinearAnimationInstance> {
Expand Down

0 comments on commit 1a214e5

Please sign in to comment.