首页 > 解决方案 > React-Native:Native-base:失败的道具类型:提供给“View”的无效 props.style 键“NativeBase”

问题描述

版本:

反应:16.3.1

反应原生:~0.55.2

本机基础:^2.8.0


问题:警告:道具类型失败:提供给“视图”的道具样式键“NativeBase”无效


平台:iOS & Android


每当我将本机基础集成到项目中时,我都会在 react-native 项目中收到此警告。

这是此代码。

import {
  View,
  TouchableHighlight,
  StyleSheet,
  Image,
  Dimensions,
  ScrollView,
  SafeAreaView
} from "react-native";
import { Button, Text } from "native-base";

<ScrollView>
            {props.detail.site_url !== '#' ? (
              <View style={styles.visitButton}>
                <TouchableHighlight>
                  <Button
                    success
                    onPress={() => props.visitSite(props.detail.site_url)}
                  >
                    <Text>{props.detail.name}</Text>
                  </Button>
                </TouchableHighlight>
              </View>
            ) : (
                <View></View>
              )}
          </ScrollView>

const styles = Stylesheet.create({
visitButton: {
    flex: 1,
    marginVertical: 20,
    display: 'flex',
    justifyContent: 'center',
    alignItems: 'center'
  }
})

在此处输入图像描述

标签: javascriptreactjsreact-nativenative-base

解决方案


您正在使用的库中的文件似乎存在问题。

他们将一个样式嵌套在另一个样式中,从而导致了这个警告。您可以在您提供的屏幕截图中看到这一点:

{
    "borderRadius": 5,
    "NativeBase": {
        // NativeBase block
    },
},
"Icon": {
    // Icon block
},

“NativeBase”块不应嵌套到另一个块中,它应与“Icon”处于同一级别,如下所示:

{
    "borderRadius": 5,
},
"NativeBase": {
    // NativeBase block
},
"Icon": {
    // Icon block
},

要修复它,您可以手动更改库中的文件或等待自动修复并在此时更新 native-base。


推荐阅读