-
Notifications
You must be signed in to change notification settings - Fork 24.5k
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
createAnimatedComponent should use forwardRef ? #19650
Comments
FYI this will break all existing libraries which rely on |
If you check the latest ~10 commits in master you can see that they tried adding |
This probably makes sense but it would be useful to see a very small complete sample that will help us understand how this is being used and what value you are looking for from both of the refs you are proposing. |
hi @TheSavior I'm not sure what you are expecting from me. My personal opinion is that it would be better to have animated and non-animated components return the same kind of ref, so that people do not have to think about that at all (end users or library authors). Not sure what kind of example you want me to provide. Yes that would be a breaking change, it is annoying and will break code for sure but I think this kind of usecase is the point of |
I don't think breaking all the libraries out there without any deprecation notice is a good idea.
Yeah, but react-native is not just a library, it's a framework. The change is more invasive and will break many libraries in its ecosystem. Whereas react-redux breaking this behavior will mostly require only the app code to be upgraded which is under user's control. I'm not against change, but we need to figure out a proper deprecation path before changing the API. |
yes I totally agree with that, here it's just to validate what we want in the future, I'm not asking for a breaking change right now :) |
Got it, I understand better now. Thanks for helping me get there. I think I agree that we should have a supported way to get the underlying node, we just need a good plan. 👍 |
Currently the ref provided by Animated.ScrollView is a wrapper, on which we can call "getNode()" The current change ensure that we unwrap the real scrollview before trying to use the scrollview methods, and keep retrocompatibility for non-animated scrollviews See also facebook/react-native#19650
Currently the ref provided by Animated.ScrollView is a wrapper, on which we can call "getNode()" The current change ensure that we unwrap the real scrollview before trying to use the scrollview methods, and keep retrocompatibility for non-animated scrollviews See also facebook/react-native#19650
There is a workaround to make
|
Great, didn't think about recreating the raw animated compos this way, makes sense to do that in userland. keeping this issue open for discussion whether or not react should automatically forward refs in the long term |
I'm gonna close this, as the remaining discussion should probably be handled somewhere else (React repo?) and we aren't planning on changing this API on RN itself right now. If you feel strongly, please do come forward with a plan and start implementing it in PRs. |
it is giving me this error @gavrix |
you can use |
For Discussion
Hi,
Currently createAnimatedComponent does not use forwardRef.
This is probably the case because we actually sometimes need access to the AnimatedComponent instance.
I propose to use
forwardRef
by default, and to use another prop likeanimatedRef
to get a reference to the animated wrapper, as it is probably a less common usecase (not sure of that but it looks to me)Currently, we need to call
getNode
on the animated component. This was added by @gre who seems to agree for using forwardRef by default (#9944 (comment))This would simplify client code.
For example in my case I created a ScrollView HOC react-native-scroll-into-view, and it must work with both animated and normal scrollviews.
This forces me to provide a fragile implementation like this to be sure to I can use the ScrollView imperative methods to get the responder:
The text was updated successfully, but these errors were encountered: