-
Notifications
You must be signed in to change notification settings - Fork 24.4k
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
Implement native Animated value listeners on Android #8844
Closed
janicduplessis
wants to merge
1
commit into
facebook:master
from
janicduplessis:animated-value-listener-android
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 17 additions & 0 deletions
17
ReactAndroid/src/main/java/com/facebook/react/animated/AnimatedNodeValueListener.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
/** | ||
* Copyright (c) 2015-present, Facebook, Inc. | ||
* All rights reserved. | ||
* | ||
* This source code is licensed under the BSD-style license found in the | ||
* LICENSE file in the root directory of this source tree. An additional grant | ||
* of patent rights can be found in the PATENTS file in the same directory. | ||
*/ | ||
|
||
package com.facebook.react.animated; | ||
|
||
/** | ||
* Interface used to listen to {@link ValueAnimatedNode} updates. | ||
*/ | ||
public interface AnimatedNodeValueListener { | ||
void onValueUpdate(double value); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Aren't we going to have a problem if we happen to re-render during an animation? Namely, out-of-date JS values will override up-to-date native values when the view us updated. Contrived example:
Tick 1 (first render):
Tick 2 (animation driven natively):
Tick 3: (still driving, listener called on the JS side)
Tick 4: (still driving, we call a re-render)
Tick 5 (re-rendered):
It seems like the old
__getValue
, this updated__getValue
behavior, and__getAnimatedValue
all have slightly different intents:(1) What prop values should we be setting on the native view when we render?
(2) What are the current values of animated props?
(3) What values are we driving and may need update via setNativeProps? (inverse of 1)
It seems like there is a great tension between an animate prop being treated like any other prop, and being managed independently.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would not see this as an issue. It's similar with all the events we receive from native. E.g. when you register onLayout event it doesn't necessarily mean the values you're getting are the actual dimensions of the element, those are just values that has been calculated during some layout pass in the past and might have already been changed from JS before we managed to process onLayout event
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's fine that the values passed to JS aren't representative of the true state of the element. What's not okay is if we take this stale data and use it to update the element, which we will do here whenever we render the element again. Concretely, you might see the animated view unexpectedly snap backward in time when you call setState, which would be jarring.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll take another look at this to make sure it doesn't cause issues when re-rendering during an animation when there is no value listener. It did work properly when using one since we update the js value of the node.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Another contrived example, but imagine there is no value listener and you do the following:
The bug will pop up when both the following conditions are true: