升级到 React Native 0.62.0 获得警告标志 - “不再需要在 Animated 组件的 ref 上调用 `getNode()`

hel*_*llo 15 react-native react-navigation

我只是将我的本机应用程序升级到 0.62.0,现在我的应用程序不断收到此警告标志

ReactNativeFiberHostComponent: Calling `getNode()` on the ref of an Animated component 
is no longer necessary. You can now directly use the ref instead. 
This method will be removed in a future release.
Run Code Online (Sandbox Code Playgroud)

我不确定为什么会出现这个问题?有人可以解释一下吗?

我也看到堆栈

ref.getNode |
createAnimatedComponent.js:129:20

SafeView#_updateMeasurements | index.js:192:14

SafeView#componentDidUpdate | index.js:154:9
Run Code Online (Sandbox Code Playgroud)

更新

我相信这可能来自 react-navigation 的 SafeAreaView

Alv*_*ian 6

在升级 ro RN 0.62.1 后,我也遇到了这个警告,我根本没有使用getNode(),原来它来自我使用的依赖项,react-native-snap-carousel因为他们使用 FlatList 构建它并且可能使用了getNode()它。

现在在他们的 GitHub 存储库中有一个关于此的未决问题,我们可以关注,这是该问题的链接

更新

这也来自包react-native-safe-area-view,可能你的应用程序正在使用这个包,现在他们发布了新版本来修复getNode()弃用,请参阅此 PR

所以不要直接自己修复文件,你只需要更新包,只需运行: npm i react-native-safe-area-view

希望这有帮助:)


小智 6

要快速解决此问题,请转到 node_modules/react-native-safe-area-view => index.js

在第 192 行更改

this.view.getNode().measureInWindow((winX, winY, winWidth, winHeight)

this.view.measureInWindow((winX, winY, winWidth, winHeight)


Ovi*_*tcu 1

正如宣布发布 RN62 的博客文章getNode()中所示,现已弃用。ref不用打电话就可以直接使用getNode()。请参阅此提交

  • 问题是,我没有在 getNode 中使用任何东西,我引入的包是否可能正在使用它?我不确定如何查看哪个包使用它?有没有简单的方法可以找出来? (2认同)