javascript - 不变违规 : requireNativeComponent: "BVLinearGradient"

标签 javascript android ios react-native npm

我一直在使用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 和其余文件均采用标准编码方法。

最佳答案

如果您使用的是 Windows 和 React-native cli(不是 expo):

1-android/settings.gradle 中,检查是否

包括':react-native-线性梯度' 项目(':react-native-linear-gradient').projectDir = new File(rootProject.projectDir,'../node_modules/react-native-线性-gradient/android')

存在..如果不存在,添加它们


2-android/app/build.gradle 中,检查是否

implementation project(':react-native-linear-gradient')

存在于依赖项{ ... } ..如果不存在,则添加


3-android/app/src/main/java/com/{YOUR_APP_NAME}/MainApplication.java 中,找到

@覆盖 protected 列表 getPackages() { ....}

然后替换注释//packages.add(new MyReactNativePackage());

与=> packages.add(new LinearGradientPackage());


它对我有用..希望它也对你有用

关于javascript - 不变违规 : requireNativeComponent: "BVLinearGradient",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/69145911/

相关文章:

javascript - 警告 : Failed prop type: Invalid prop `component` of type `object` supplied to `Route` , 预期 `function` 使用 react-router-dom 时出错

android - 警报对话框两个按钮

javascript - 在 Javascript 中创建和处理我自己的事件

javascript - grunt build 出现 "Broken @import"错误?

android - 共享元素到 ImageView 的转换在退出时有效,但在进入时不平滑

ios - 自定义 UITableViewCell 图像在滚动之前不会显示

ios - 从 xcode ios 中删除未使用的方法

ios - 在自定义 UITableviewCell 中设置图像不会*粘*

javascript - 将参数传递给 jQuery .click 同时保留事件参数

java - 无法以编程方式启动 DialogPreference(抛出空指针异常)