ReactNative export 'default'.'interpolate' (imported as 'Animated') was not found in 'react-native-reanimated'

huangapple go评论79阅读模式
英文:

ReactNative export 'default'.'interpolate' (imported as 'Animated') was not found in 'react-native-reanimated'

问题

抱歉,我无法提供完整的代码翻译,因为代码包含大量的技术术语和具体细节,无法直接翻译。但我可以帮你理解代码中的问题并提供一些指导。

根据你的描述,你在使用 React Navigation 创建一个抽屉导航,但遇到了一些错误。以下是一些可能有助于解决问题的提示:

  1. react-reanimated 版本不匹配:你提到检查了 react-reanimated 版本,但没有提供具体版本号。确保你的 react-reanimated 版本与其他相关库的版本兼容。有时不同版本之间的不兼容性会导致问题。

  2. 导航组件配置:检查你的导航配置,特别是抽屉导航(createDrawerNavigator)的配置是否正确。确保你正确地导入和配置了导航组件。

  3. 样式问题:在你的代码中,你可能需要检查样式是否正确设置。确保抽屉和叠加层的样式与你的需求一致,尤其是 zIndex、flex 等属性。

  4. 依赖库版本:检查你的项目中所有依赖库的版本是否与 React Navigation 和其他相关库的建议版本匹配。有时,不同版本之间的不兼容性会导致问题。

  5. 错误消息:你提到在控制台中看到了警告和错误消息。请查看这些消息,以获取更多关于问题的信息。它们通常会提供有关问题所在的线索。

  6. React Native 版本:确保你正在使用的 React Native 版本与 React Navigation 和其他相关库兼容。有时,升级或降级 React Native 可能有助于解决问题。

  7. 尝试运行在真机上:有时,某些问题只会在真机上出现,而不会在 Web 模拟器中出现。尝试在真机上运行你的应用程序,看看是否有不同的表现。

这些是一些可能有助于解决问题的一般性建议。要更详细地了解问题并找到解决方案,你可能需要查看控制台错误消息,以及检查你的代码和配置是否正确。如果你有特定的错误消息或问题,可以提供更多细节,我将尽力提供更具体的帮助。

英文:

Hi Guys I'm trying to make a drawer using React Navigation. The problem is, that I'm having an error that I'm not able to fix

When I run expo everything displays ok in the web

ReactNative export 'default'.'interpolate' (imported as 'Animated') was not found in 'react-native-reanimated'

But in console this warning is displayed

ReactNative export 'default'.'interpolate' (imported as 'Animated') was not found in 'react-native-reanimated'

When I try to render it on Android this appears

ReactNative export 'default'.'interpolate' (imported as 'Animated') was not found in 'react-native-reanimated'
ReactNative export 'default'.'interpolate' (imported as 'Animated') was not found in 'react-native-reanimated'

I have checked my version from react-reanimated

this is my babel.config.js

  1. module.exports = function(api) {
  2. api.cache(true);
  3. return {
  4. presets: ['babel-preset-expo'],
  5. };
  6. };

this is my App.js

  1. import React from 'react'
  2. import { StyleSheet, View,Text, } from 'react-native';
  3. import { NavigationContainer } from '@react-navigation/native';
  4. import { createMaterialTopTabNavigator } from '@react-navigation/material-top-tabs';
  5. import {createDrawerNavigator, DrawerContentScrollView,DrawerItemList, DrawerItem,} from '@react-navigation/drawer';
  6. function Feed() {
  7. return (
  8. <View style={{ flex: 1, justifyContent: 'center', alignItems: 'center' }}>
  9. <Text>Feed Screen</Text>
  10. </View>
  11. );
  12. }
  13. function Article() {
  14. return (
  15. <View style={{ flex: 1, justifyContent: 'center', alignItems: 'center' }}>
  16. <Text>Article Screen</Text>
  17. </View>
  18. );
  19. }
  20. function CustomDrawerContent(props) {
  21. return (
  22. <DrawerContentScrollView {...props}>
  23. <DrawerItemList {...props} />
  24. <DrawerItem label="Help" onPress={() => alert('Link to help')} />
  25. </DrawerContentScrollView>
  26. );
  27. }
  28. const Drawer = createDrawerNavigator();
  29. function MyDrawer() {
  30. return (
  31. <Drawer.Navigator
  32. useLegacyImplementation
  33. drawerContent={(props) => <CustomDrawerContent {...props} />}
  34. >
  35. <Drawer.Screen name="Feed" component={Feed} />
  36. <Drawer.Screen name="Article" component={Article} />
  37. </Drawer.Navigator>
  38. );
  39. }
  40. export default function App() {
  41. return (
  42. <NavigationContainer>
  43. <MyDrawer />
  44. </NavigationContainer>
  45. );
  46. }
  47. const styles = StyleSheet.create({
  48. container: {
  49. flex: 1,
  50. backgroundColor: '#fff',
  51. alignItems: 'center',
  52. justifyContent: 'center',
  53. },
  54. });

And this is my overlay.js

  1. function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
  2. import * as React from 'react';
  3. import { Platform, Pressable, StyleSheet } from 'react-native';
  4. import Animated from 'react-native-reanimated';
  5. const {
  6. // @ts-expect-error: this is to support reanimated 1
  7. interpolate: interpolateDeprecated,
  8. interpolateNode,
  9. cond,
  10. greaterThan
  11. } = Animated;
  12. const interpolate = interpolateNode ?? interpolateDeprecated;
  13. const PROGRESS_EPSILON = 0.05;
  14. const Overlay = /*#__PURE__*/React.forwardRef(function Overlay(_ref, ref) {
  15. let {
  16. progress,
  17. onPress,
  18. style,
  19. accessibilityLabel = 'Close drawer',
  20. ...props
  21. } = _ref;
  22. const animatedStyle = {
  23. opacity: interpolate(progress, {
  24. // Default input range is [PROGRESS_EPSILON, 1]
  25. // On Windows, the output value is 1 when input value is out of range for some reason
  26. // The default value 0 will be interpolated to 1 in this case, which is not what we want.
  27. // Therefore changing input range on Windows to [0,1] instead.
  28. inputRange: Platform.OS === 'windows' || Platform.OS === 'macos' ? [0, 1] : [PROGRESS_EPSILON, 1],
  29. outputRange: [0, 1]
  30. }),
  31. // We don't want the user to be able to press through the overlay when drawer is open
  32. // One approach is to adjust the pointerEvents based on the progress
  33. // But we can also send the overlay behind the screen, which works, and is much less code
  34. zIndex: cond(greaterThan(progress, PROGRESS_EPSILON), 0, -1)
  35. };
  36. return /*#__PURE__*/React.createElement(Animated.View, _extends({}, props, {
  37. ref: ref,
  38. style: [styles.overlay, overlayStyle, animatedStyle, style]
  39. }), /*#__PURE__*/React.createElement(Pressable, {
  40. onPress: onPress,
  41. style: styles.pressable,
  42. accessibilityRole: "button",
  43. accessibilityLabel: accessibilityLabel
  44. }));
  45. });
  46. const overlayStyle = Platform.select({
  47. web: {
  48. // Disable touch highlight on mobile Safari.
  49. // WebkitTapHighlightColor must be used outside of StyleSheet.create because react-native-web will omit the property.
  50. WebkitTapHighlightColor: 'transparent'
  51. },
  52. default: {}
  53. });
  54. const styles = StyleSheet.create({
  55. overlay: {
  56. ...StyleSheet.absoluteFillObject,
  57. backgroundColor: 'rgba(0, 0, 0, 0.5)'
  58. },
  59. pressable: {
  60. flex: 1
  61. }
  62. });
  63. export default Overlay;
  64. //# sourceMappingURL=Overlay.js.map

I have tried to find multiple solutions and nothing is working please help !!

答案1

得分: 1

I don't know if you have tried it yet.

你不知道你是否已经尝试过了。

The "entry point" in your input file can be the index.js or the App.js file. Make sure you add the following:
import 'react-native-gesture-handler;' at the beginning of the file, that there is nothing else before that import. And make sure you have react-native-gesture-handler installed as describe here in this documentation

你输入文件中的“入口点”可以是index.js或App.js文件。确保在文件开头添加以下内容:import 'react-native-gesture-handler;',在此导入之前没有其他内容。并确保按照这里的说明安装了react-native-gesture-handler documentation

And in your babel.config.js file put it like this

  1. module.exports = function (api) {
  2. api.cache(true);
  3. return {
  4. presets: ['babel-preset-expo'],
  5. plugins:[['react-native-reanimated/plugin']],
  6. };
  7. };

在你的 babel.config.js 文件中将其设置如下:

  1. module.exports = function (api) {
  2. api.cache(true);
  3. return {
  4. presets: ['babel-preset-expo'],
  5. plugins:[['react-native-reanimated/plugin']],
  6. };
  7. };

Uninstall the app from the emulator or device where you are testing it, reinstall it and try to start it with this command
npm start -- --reset-cache or with npx expo start -c to clear the app cache.

从您测试的模拟器或设备上卸载该应用程序,然后重新安装,并尝试使用以下命令启动它:npm start -- --reset-cachenpx expo start -c 来清除应用程序缓存。

英文:

I don't know if you have tried it yet.

The "entry point" in your input file can be the index.js or the App.js file. Make sure you add the following:
import 'react-native-gesture-handler; at the beginning of the file, that there is nothing else before that import. And make sure you have react-native-gesture-handler installed as describe here in this documentation

And in your babel.config.js file put it like this

  1. module.exports = function (api) {
  2. api.cache(true);
  3. return {
  4. presets: ['babel-preset-expo'],
  5. plugins:[[['react-native-reanimated/plugin']],],
  6. };
  7. };

Uninstall the app from the emulator or device where you are testing it, reinstall it and try to start it with this command
npm start -- --reset-cache or with npx expo start -c to clear the app cache.

答案2

得分: 0

在使用 react-native-reanimated 时,需要在 babel.config.js 文件中添加一个插件,如下所示:

  1. module.exports = function (api) {
  2. api.cache(true);
  3. return {
  4. presets: ['babel-preset-expo'],
  5. plugins: [
  6. 'react-native-reanimated/plugin',
  7. ]
  8. };
  9. };

之后,删除所有的 node_modules,然后通过运行以下命令重新安装:

  1. npm install

然后,通过以下方式重新运行您的代码:

  1. npm start //{or}
  2. expo start

现在您的 Expo 项目将正常工作。

英文:

While working on react-native-reanimated, you need to add a plugin in the babel.config.js file like this ,

<!-- begin snippet: js hide: false console: true babel: false -->

<!-- language: lang-js -->

  1. module.exports = function (api) {
  2. api.cache(true);
  3. return {
  4. presets: [&#39;babel-preset-expo&#39;],
  5. plugins: [
  6. &#39;react-native-reanimated/plugin&#39;,
  7. ]
  8. };
  9. };

<!-- end snippet -->

After that Delete all your node_modules ,after that install it again by running

<!-- begin snippet: js hide: false console: true babel: false -->

<!-- language: lang-js -->

  1. npm install

<!-- end snippet -->

After that re-run your code by using ,

<!-- begin snippet: js hide: false console: true babel: false -->

<!-- language: lang-js -->

  1. npm start //{or}
  2. expo start

<!-- end snippet -->

Now your expo project will work perfectly.

huangapple
  • 本文由 发表于 2023年6月15日 11:07:24
  • 转载请务必保留本文链接:https://go.coder-hub.com/76478834.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定