【问题标题】:Invariant Violation: requireNativeComponent: "BVLinearGradient"不变违规:requireNativeComponent:“BVLinearGradient”
【发布时间】:2021-11-07 18:09:14
【问题描述】:

我一直在使用react-native-gradient,但我收到以下关于包的错误。

错误

Invariant Violation: requireNativeComponent: "BVLinearGradient" was not found in the UIManager.

This error is located at:
    in BVLinearGradient (at react-native-linear-gradient/index.ios.js:54)
    in LinearGradient (at SignupLogin.js:46)
    in RCTView (at View.js:34)
    in View (at createAnimatedComponent.js:165)
    in AnimatedComponent (at createAnimatedComponent.js:215)
    in ForwardRef(AnimatedComponentWrapper) (at TouchableOpacity.js:224)
   .........    
    in View (at AppContainer.js:106)
    in DevAppContainer (at AppContainer.js:121)
    in RCTView (at View.js:34)
    in View (at AppContainer.js:132)
    in AppContainer (at renderApplication.js:39)
at node_modules/react-native/Libraries/Core/ExceptionsManager.js:104:6 in reportException
at node_modules/react-native/Libraries/Core/ExceptionsManager.js:171:19 in handleException
at node_modules/react-native/Libraries/Core/setUpErrorHandling.js:24:6 in handleError
at node_modules/expo-error-recovery/build/ErrorRecovery.fx.js:12:21 in ErrorUtils.setGlobalHandler$argument_0
at [native code]:null in flushedQueue
at [native code]:null in invokeCallbackAndReturnFlushedQueue

用法

...
import * as Animatable from "react-native-animatable";
import LinearGradient from "react-native-linear-gradient";
import MaterialIcons from "react-native-vector-icons/MaterialIcons";
import { useTheme } from "@react-navigation/native";


const SignupLogin = ({ navigation }) => {
  const { colors } = useTheme();
  return (
    <View style={styles.container}>
      .....
        <View style={styles.button}>
          <TouchableOpacity onPress={() => navigation.navigate("sign-in")}>
            <LinearGradient
              colors={["#0831d4", "#0131ab"]}
              style={styles.signIn}
            >
              <Text style={styles.textSign}>Get started</Text>
              <MaterialIcons name="navigate-next" color="#fff" size={20} />
            </LinearGradient>
         .....
    </View>
  );
};


export default SignupLogin;

在页脚登录和注册菜单之间进行简单导航,App.js 和其余文件采用标准编码方法。

【问题讨论】:

    标签: javascript android ios react-native npm


    【解决方案1】:

    确认安装react-native-linear-gradient

    yarn add react-native-linear-gradient
    

    在ios中确认ios/podfile有这行

    pod 'BVLinearGradient', :path => '../node_modules/react-native-linear-gradient'
    

    然后在ios文件夹中运行pod install

    【讨论】:

    • 是的,我做到了。虽然我使用的是Linux系统。 npm install react-native-linear-gradient --save 然后使用 react-native link react-native-linear-gradient 链接它。问题出在 ios 文件中,但自从我在 Android 中运行应用程序以来,我没有在运行中使用它们。
    • 我想你可能不明白这个问题。我正在使用 Linux 机器,并使用这些库构建了一个 React Native 项目。当我尝试在 android 模拟器中运行应用程序时出现此问题,然后弹出此错误。正如我所见,依赖关系完好无损,我无法弄清楚哪里出了问题。
    • 也许我理解错了,但我之前在ios中遇到过类似的问题,我用上面的答案解决了。
    • 你在哪个平台有问题? android or ios?。在 linux 或 windows 中并不重要。
    • 对不起,我也混淆了一些东西。是的,Podfile 有你提到的链接和路径,但仍然出现错误
    猜你喜欢
    • 2020-05-06
    • 2019-08-27
    • 2020-09-02
    • 2021-06-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多