-
Notifications
You must be signed in to change notification settings - Fork 24k
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
Animated.modulo
can return negative number (Where is Animated.min
/Animated.max
?)
#37447
Comments
|
The reproduction I linked is using the latest Expo. |
Update (functional homegrown
|
Based on this success I imagine there are a few more Math-like helper functions that could be derived such as:
|
Animated.modulo
can return negative number (Where is Animated.min
/Animated.max
?)
This issue is stale because it has been open 180 days with no activity. Remove stale label or comment or this will be closed in 7 days. |
Maybe this comment could be updated/improved to better explain how it works and at least not claim that the modulo result is non-negative.
|
Description
Hello, I have a situation where I want to do Math.max between two different animated values. I have a chat bubble that floats on the bottom of the screen. Some screens it needs to float higher to be out of the way of nav bars, in this case, we animate it up, then back down again when navigating away.
We also need to animate the chat bubble up above the keyboard when the keyboard is opened. We started with the naive implementation:
But this is no good, because when we are on the screens with a nav bar and the keyboard is open, the chat bubble is too high above the keyboard. Ideally I want this:
But it does not seem to exist... So I decided to try to build it myself. This answer on stack overflow shows how to rebuild Math.max without any logical operators. In shorthand the formula looks like this:
max = ( (a+b) + |a-b| ) / 2
.After reviewing all the
Animated.*
operators I'm given, it looked like I was stuck because there is no absolute value operator. BUT WAIT, there's more! I noticed the documentation onAnimated.modulo
states the following:Which does produce the desired results when
a > b
. But whena < b
I get strange behavior and my animated value disappears completely. So I thought maybeInfinity
was too aggressive. Must be, because when using10000
instead, I found out that I get a large positive number whena < b
which appeared to simply be10000 + (a -b)
. In an attempt to get around this situation I tried using a negative modulo.Which for values:
a: 0
andb: 336
the result is-336
Which goes against the documentation above.
In general this has been really rather confusing because
Animated.modulo
does not perform a traditional%
modulo operation and does not seem to even hold to the documented exception of being always positive.React Native Version
0.70.5
Output of
npx react-native info
Steps to reproduce
Snack, code example, screenshot, or link to a repository
https://snack.expo.dev/@jcoy/ashamed-truffle
The text was updated successfully, but these errors were encountered: