-
Notifications
You must be signed in to change notification settings - Fork 24.2k
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
[NativeAnimated][Android] Add support for animated events #9253
[NativeAnimated][Android] Add support for animated events #9253
Conversation
By analyzing the blame information on this pull request, we identified @kmagiera and @ericvicenti to be potential reviewers. |
cc @brentvatne |
Other thought:
|
const prop = nextProps[key]; | ||
if (prop instanceof AnimatedEvent && prop.__isNative) { | ||
// TODO: Map event names using the map in UIManager. | ||
if (key === 'onScroll') { |
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.
Which props aside from onScroll do you think we might want to be able to bind natively to with Animated.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.
Actually pan responders would be a good example of these kinds of events
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.
@brentvatne this approach will only work for "direct" events. That is because touch handling has a bubbling logic written in JS and we cannot determine which view is going to be responsible for handling the touch without running some JS code
This is so exciting!
Not sure about this one, will leave it to someone else to comment on.
Another option would be to just make ScrollView take care of attaching the event, but this doesn't work for other views and leaks the responsibility for this outside of the Animated codebase. We need to know:
I'm sure that there are ways we could work around this but I can't think of any solid ones, so I'm for |
cc @kmagiera |
@@ -9,6 +9,8 @@ | |||
|
|||
package com.facebook.react.animated; | |||
|
|||
import android.util.Log; |
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.
revert this
77953a3
to
16a3566
Compare
@janicduplessis updated the pull request. |
1 similar comment
@janicduplessis updated the pull request. |
@janicduplessis updated the pull request. |
} | ||
|
||
_attachNativeEvents(newProps) { | ||
if (newProps !== this.props) { |
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.
This can perhaps be optimised so that we don't reattach native props every time when non relevant property gets changed. Also, I'm not sure if this statement can even evaluate to true (if props hasn't been updated componentWillReceiveProps
will not be triggered)
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 think the common case is to create a new event in every render so it should be fine to reattach everytime, I'll take another look see if I can improve it though.
<ScrollView
onScroll={Animated.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.
We should perhaps add to the documentation that creating event in render method is not the most effective way
@janicduplessis updated the pull request. |
@janicduplessis updated the pull request. |
@janicduplessis updated the pull request. |
@janicduplessis updated the pull request - view changes - changes since last import |
@janicduplessis updated the pull request - view changes - changes since last import |
@facebook-github-bot shipit |
Just importing it again, see if I can fix the test somehow. |
Thanks for importing. If you are an FB employee go to Phabricator to review internal test results. |
I tried to merge this pull request into the Facebook internal repo but some checks failed. To unblock yourself please check the following: Does this pull request pass all open source tests on GitHub? If not please fix those. Does the code still apply cleanly on top of GitHub master? If not can please rebase. In all other cases this means some internal test failed, for example a part of a fb app won't work with this pull request. I've added the Import Failed label to this pull request so it is easy for someone at fb to find the pull request and check what failed. If you don't see anyone comment in a few days feel free to comment mentioning one of the core contributors to the project so they get a notification. |
@janicduplessis how can I use this in a |
To use it with ListView you'll need to create an AnimatedListView using |
I did that but still failed, have you tried it? ???? iPhone ? 2016?9?19??01:25?Janic Duplessis <notifications@git.luolix.topmailto:notifications@github.com> ??? To use it with ListView you'll need to create an AnimatedListView using Animated.createAnimatedComponent. You are receiving this because you commented. |
Ok, I think I know why. Does it work if you add getScrollableNode: function() {
if (this._scrollComponent && this._scrollComponent.getScrollableNode) {
return this._scrollComponent.getScrollableNode();
}
}, in ListView.js |
@janicduplessis It's definitely awesome, working so great, say goodbye to bad scrolling effects, thank you again, wish this can be merged soon |
6565929
BOOM. |
@janicduplessis what about to add support for |
I'll make another PR for the ListView fix. |
Summary: This adds support for `Animated.event` driven natively. This is WIP and would like feedback on how this is implemented. At the moment, it works by providing a mapping between a view tag, an event name, an event path and an animated value when a view has a prop with a `AnimatedEvent` object. Then we can hook into `EventDispatcher`, check for events that target our view + event name and update the animated value using the event path. For now it works with the onScroll event but it should be generic enough to work with anything. Closes facebook/react-native#9253 Differential Revision: D3759844 Pulled By: foghina fbshipit-source-id: 86989c705847955bd65e6cf5a7d572ec7ccd3eb4
suggested by @janicduplessis in facebook#9253 (comment) I'm using this in my own apps
Summary: suggested by janicduplessis in #9253 (comment) I'm using this in my own apps Closes #11339 Differential Revision: D4325343 fbshipit-source-id: f1da26a2107093865f04e1d81245b33482776001
Summary: suggested by janicduplessis in facebook#9253 (comment) I'm using this in my own apps Closes facebook#11339 Differential Revision: D4325343 fbshipit-source-id: f1da26a2107093865f04e1d81245b33482776001
This adds support for
Animated.event
driven natively. This is WIP and would like feedback on how this is implemented.At the moment, it works by providing a mapping between a view tag, an event name, an event path and an animated value when a view has a prop with a
AnimatedEvent
object. Then we can hook intoEventDispatcher
, check for events that target our view + event name and update the animated value using the event path.For now it works with the onScroll event but it should be generic enough to work with anything.