React native 已升级为React Native 0.62.0,收到警告标志-“;不再需要对动画组件的ref调用'getNode()'
我刚刚将我的react原生应用升级到0.62.0,现在我的应用一直收到这个警告标志React native 已升级为React Native 0.62.0,收到警告标志-“;不再需要对动画组件的ref调用'getNode()',react-native,react-navigation,React Native,React Navigation,我刚刚将我的react原生应用升级到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. 我不知
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.
我不知道为什么会出现这个问题?有人能解释一下吗
我也看到了Stack
ref.getNode |
createAnimatedComponent.js:129:20
SafeView#_updateMeasurements | index.js:192:14
SafeView#componentDidUpdate | index.js:154:9
更新
我相信这可能来自react navigation的SafeAreaView,正如在宣布RN62发布时所看到的,
getNode()
现在已被弃用。您可以只使用ref
,而不调用getNode()
。看到这一点。在升级ro RN 0.62.1后,我也遇到了这个警告,我根本没有使用getNode()
,结果它来自我使用的一个依赖项,称为react native snap carousel
,因为它们使用平面列表构建它,并且可能还使用getNode()
现在在他们的GitHub回购协议中有一个公开的问题,我们可以关注,下面是链接
更新
这也来自软件包react native safe area view
,可能您的应用程序正在使用此软件包,现在他们发布了新版本来修复getNode()
弃用
因此,您不需要自己直接修复文件,只需更新包,只需运行:npm i react native safe area view
希望这是帮助:)当您使用createAnimatedComponent作为组件时,问题将发生,而它已经存在于动画库中,例如,如果我们使用它来平面列表,将显示此警告 要修复它,只需直接调用componenty 有关更多详细信息,请更改
return this._carouselRef && this._carouselRef.getNode && this._carouselRef.getNode();
const AnimatedFlatList = FlatList ? Animated.createAnimatedComponent(FlatList) : null;
const AnimatedScrollView = Animated.Animated.createAnimatedComponent(ScrollView);
到
*删除getNode()将解决此问题。要快速解决此问题,请转到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)如果您使用的是
react native snap carousel
,您可以通过在本地修改节点模块来修复它
先去
./node_modules/react-native-snap-carousel/src/Carousel.js
改变
const AnimatedFlatList = FlatList ? Animated.createAnimatedComponent(FlatList) : null;
const AnimatedScrollView = Animated.Animated.createAnimatedComponent(ScrollView);
进入
最后,将\u getWrappedRef
函数更改为
_getWrappedRef () {
return this._carouselRef
}
这将停止警告,直到我们对该软件包进行更新。问题是,我没有在getNode中使用任何东西,是否有可能我带来的软件包正在使用它?我不确定如何才能看到哪个软件包在使用它?有没有简单的方法找到?更新-我想它可能来自react navigationye的SafeAreaView啊,警告可能来自您的一些依赖项,比如您提到的İn除此之外,您现在可以更新您的节点模块
npm i react native safe area view
您可以应用回答中提到的更改,并在您的项目npx patch package react native safe area view
中为其创建一个补丁,该补丁将被保存到修补程序文件夹我刚更新到最新版本,警告已消失。我如上所述更新了react native snap carousel(^3.9.1”),但仍有一条警告。可能消息来自其他库,如何检查?警告开始如下:调用getNode()不再需要动画组件的ref。您现在可以直接使用ref。此方法将在将来的版本中删除。“,”ReactNativeFiberHostComponent“,”\n SafeView。
_getWrappedRef () {
return this._carouselRef
}