Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: support custom onPress as well as prop to disable default behaviour for clicking on animation #217

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

ridwansameer
Copy link

Adding in this PR based on a requirement we had.

Sometimes wrapping the Rive component with a TouchableOpacity or other Touchable (Other than TouchableWithoutFeedback) would not work. Because the inner TouchableWithoutFeedback is taking priority.

Therefore adding a custom onPress prop which can be called when the animation is clicked, as well as an option to disable the default handling

Our Use Case:

  • Animation has an onClick trigger
  • We want to trigger another side effect when animation is clicked
  • We cannot use a Touchable because it does not work
  • So using the new onPress to call riveRef.current?.setInputState to trigger the animation as well as our side effect

@ridwansameer
Copy link
Author

The example Podfile.lock also seems to be using an older version of Rive, so this updated it.

@HayesGordon
Copy link
Contributor

Hi @ridwansameer thank you for the PR. We'll take a look at it, as it is helpful to be able to disable the touch inputs.

As a side note, you may find events more helpful for this use case if you want to trigger some side effect from an event that occurs in an animation (communication from animation to code). See here: https://help.rive.app/runtimes/rive-events

@ridwansameer
Copy link
Author

Yes we considered events, but we felt React native telling Rive what state to change to instead of RN doing its thing based on an event from Rive to be a bit more of a better event direction. Not sure if everyone would agree.

With regards to this PR, I noticed that the touch event still does go through on a different rive file even though I was using the updated code (With patch package). Wondering if there's some lower level onClick (maybe from the native side) that is triggering it

Copy link

@roti-c137 roti-c137 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes in my work I do require a touch event that is wrapped outside of Rive.

Or is there any other way to get the touch event from Rive's own touchablewithoutfeedback that I missed out?

@@ -124,6 +129,7 @@ const RiveContainer = React.forwardRef<RiveRef, Props>(
animationName,
stateMachineName,
testID,
disableDefaultTouchHandling = false,

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can reduce this variable and do something like this
const isDisableDefaultTouch = onPress

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can ignore this if we need to support onPressIn at the same time too.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants