更新类型为 RCTText 的影子节点中的属性“fontSize”时出错

Beg*_*mer 6 react-native

我已经删除了node_modules并重新运行npm install。之后我得到了这个错误:

\n\n
Error while updating property \'fontSize\' in shadow node of type: RCTText\nValue for fontSize cannot be cast from String to Double\n
Run Code Online (Sandbox Code Playgroud)\n\n

我将 fontSize:\'20\' 形式的所有 fontSize 更改为 fontSize:20 但错误再次显示。现在我删除了所有文件中的 fontSize 属性,并且再次存在错误。\n这是我的 package.json 内容:

\n\n
{\n"name": "myApp",\n  "version": "0.0.1",\n  "private": true,\n  "scripts": {\n    "start": "node node_modules/react-native/local-cli/cli.js start",\n    "test": "jest"\n  },\n  "dependencies": {\n    "jetifier": "^1.6.4",\n    "native-base": "^2.13.8",\n    "prop-types": "^15.7.2",\n    "react": "16.8.3",\n    "react-native": "0.59.8",\n    "react-native-dialog": "^5.6.0",\n    "react-native-gesture-handler": "^1.5.0",\n    "react-native-ionicons": "^4.6.3",\n    "react-native-material-dropdown": "^0.11.1",\n    "react-native-responsive-screen": "^1.3.0",\n    "react-native-slideshow": "^1.0.1",\n    "react-navigation": "^3.13.0"\n  },\n  "devDependencies": {\n    "@babel/core": "7.4.4",\n    "@babel/runtime": "7.4.4",\n    "babel-jest": "24.8.0",\n    "jest": "24.8.0",\n    "metro-react-native-babel-preset": "0.54.0",\n    "react-test-renderer": "16.8.3"\n  },\n  "jest": {\n    "preset": "react-native"\n  },\n  "rnpm": {\n    "assets": [\n      "./assets/fonts"\n    ]\n  }\n}\n
Run Code Online (Sandbox Code Playgroud)\n\n

更新: \n应用程序主页:

\n\n
import React, { Component } from \'react\';\nimport { View, Text,StyleSheet,Image,TouchableWithoutFeedback } from \'react-native\';\nimport Slideshow from \'react-native-slideshow\';\nimport {widthPercentageToDP as wp, heightPercentageToDP as hp} from \'react-native-responsive-screen\';\nimport Colors from \'../Colors\';\nimport Strings from \'../Strings\';\nimport DrawerNavigator from \'../routes/DrawerNavigator\';\nclass AppMainPage extends Component {\n  constructor(props) {\n    super(props);\n    this.state = {\n        position: 0,\n        interval: null,\n        dataSource: [],\n        sliderSource:[]\n      };\n  }\n  componentDidMount(){\n    this.fetchSliderImage();\n  }\n  componentWillMount() {\n    this.setState({\n      interval: setInterval(() => {\n        this.setState({\n          position: this.state.position === this.state.dataSource.length-1 ? 0 : this.state.position + 1\n        });\n      }, 2000)\n    });\n  }\n\n  componentWillUnmount() {\n    clearInterval(this.state.interval);\n  }\n  getAuthAndReload(){\n    ajax.fetchAuth().then(()=>{this.fetchSliderImage()});\n  }\n  async fetchSliderImage(){\n    try{\n      let response = await fetch(Strings.baseUrl+\'spanser/new?type=1&ostanId=1\', {\n        method: \'POST\',\n        headers: {\n            \'Accept\': \'application/json\',\n            \'Content-Type\': \'application/json\',\n            \'Authorization\': \'Bearer \' +Strings.id_token\n        }\n        }).then((resp) => {\n          return resp.json()\n      })\n      .then((responseJson) => {\n        const json_data = responseJson; \n        if("title" in responseJson && responseJson.title=="Unauthorized" ){\n          this.setState({loadData:1},()=>this.getAuthAndReload());\n          return 0;\n        }\n        else{\n          const arr = Object.keys(json_data).map(function(_) { return json_data[_]; });\n          var resultArray=new Array();\n          for(i=0;i<arr.length;i++){\n            resultArray.push({\'title\':arr[i].title,\'caption\':\'\',\'url\':Strings.imageUrl+arr[i].image1});\n          }\n            this.setState({sliderSource:resultArray,dataSource:arr});\n          return arr;\n        }\n      });\n      } \n    catch (error) {\n        console.error(error);\n    }\n  }\n  onImageClick(){\n    console.log(\'&&\'+this.state.dataSource[0]);\n    console.log(\'******\'+this.state.position);\n    this.props.navigation.navigate(\'SponserPage\',{currentItem:this.state.dataSource[this.state.position]})\n  }\n  render() {\n    return (\n      <View style={{backgroundColor:\'black\',flex:1}}>\n        <DrawerNavigator/>\n        <View style={styles.rowViews}>\n            <View style={styles.columnViews}>\n                <Image  style={styles.imgStyle} source={require(\'../Icons/play-button.png\')}/>\n                <Text style={styles.txtStyle}>\xd9\x88\xdb\x8c\xd8\xaf\xdb\x8c\xd9\x88\xdb\x8c \xd9\x88\xdb\x8c\xda\x98\xd9\x87</Text>\n            </View>\n            <View style={styles.columnViews}>\n                <Image  style={styles.imgStyle}  source={require(\'../Icons/star.png\')}/>\n                <Text style={styles.txtStyle}>\xd9\xbe\xdb\x8c\xd8\xb4\xd9\x86\xd9\x87\xd8\xa7\xd8\xaf\xd9\x87\xd8\xa7\xdb\x8c \xd9\x88\xdb\x8c\xda\x98\xd9\x87</Text>\n            </View>\n            <View style={styles.columnViews}>\n                <Image  style={styles.imgStyle}  source={require(\'../Icons/irandokht.png\')}/>\n                <TouchableWithoutFeedback onPress={()=>this.props.navigation.navigate(\'SalonList\')}>\n                  <Text style={styles.txtStyle}>\xd9\x84\xdb\x8c\xd8\xb3\xd8\xaa \xd8\xb3\xd8\xa7\xd9\x84\xd9\x86\xd9\x87\xd8\xa7</Text></TouchableWithoutFeedback>\n            </View>\n        </View>\n        <View style={{width:\'100%\',height:2,backgroundColor:Colors.yellow}}/>\n        <View style={styles.rowViews}> \n            <View style={styles.columnViews}>\n                <Image  style={styles.imgStyle}  source={require(\'../Icons/trophy.png\')}/>\n                <Text style={styles.txtStyle}>\xd8\xa8\xd8\xb1\xd9\x86\xd8\xaf\xda\xaf\xd8\xa7\xd9\x86 \xd9\x85\xd8\xb3\xd8\xa7\xd8\xa8\xd9\x82\xd8\xa7\xd8\xaa</Text>\n            </View>\n            <View style={styles.columnViews}>\n                <Image  style={styles.imgStyle}  source={require(\'../Icons/trophy(1).png\')}/>\n                <Text style={styles.txtStyle}>\xd8\xb3\xd8\xa7\xd9\x84\xd9\x86 \xd8\xa8\xd8\xb1\xd8\xaa\xd8\xb1 \xd9\x85\xd8\xa7\xd9\x87</Text>\n            </View>\n            <TouchableWithoutFeedback style={styles.columnViews} onPress={()=>this.props.navigation.navigate(\'Mosabeqat\')}>\n            <View >\n                <Image  style={styles.imgStyle}  source={require(\'../Icons/medal.png\')}/>\n                <Text style={styles.txtStyle}>\xd8\xb4\xd8\xb1\xda\xa9\xd8\xaa \xd8\xaf\xd8\xb1 \xd9\x85\xd8\xb3\xd8\xa7\xd8\xa8\xd9\x82\xd9\x87 </Text>\n            </View>\n            </TouchableWithoutFeedback>\n        </View>\n        <View style={styles.rowViews}> \n        <View style={styles.columnViews}>\n                <Image  style={styles.imgStyle}  source={require(\'../Icons/contact.png\')}/>\n                <Text style={styles.txtStyle}>\xd8\xa7\xd8\xb1\xd8\xaa\xd8\xa8\xd8\xa7\xd8\xb7 \xd8\xa8\xd8\xa7 \xd8\xa7\xdb\x8c\xd8\xb1\xd8\xa7\xd9\x86 \xd8\xaf\xd8\xae\xd8\xaa</Text>\n            </View>\n            <TouchableWithoutFeedback style={styles.columnViews} onPress={()=>this.props.navigation.navigate(\'MajaleyeTakhasosi\')}>\n              <View >\n                  <Image  style={styles.imgStyle}  source={require(\'../Icons/open-magazine.png\')}/>\n                  <Text style={styles.txtStyle}>\xd9\x85\xd8\xac\xd9\x84\xd9\x87 \xd8\xaa\xd8\xae\xd8\xb5\xd8\xb5\xdb\x8c</Text>\n              </View>\n            </TouchableWithoutFeedback>\n\n            <View >\n                <Image  style={styles.imgStyle}  source={require(\'../Icons/newspaper.png\')}/>\n                <TouchableWithoutFeedback style={styles.columnViews} onPress={()=>this.props.navigation.navigate(\'NewsNav\')}>\n                  <Text style={styles.txtStyle}>\xd8\xa7\xd8\xae\xd8\xa8\xd8\xa7\xd8\xb1 \xd9\x85\xd9\x87\xd9\x85</Text>\n                </TouchableWithoutFeedback></View>\n        </View>\n        <View  style={styles.columnViews}>\n        {this.state.sliderSource.length>0?\n          <Slideshow \n          containerStyle={{padding: 10,}}\n          dataSource={this.state.sliderSource}\n          position={this.state.position}\n          resizeMode=\'contain\'\n          onPositionChanged={position => this.setState({ position:position })} \n          onPress={()=>{this.onImageClick()}}/>\n          :\n          <View/>\n          }\n        </View>\n      </View>\n    );\n  }\n}\nconst styles=StyleSheet.create(\n    {\n        rowViews:{\n            flexDirection:\'row\',\n            justifyContent: \'space-between\',\n            alignItems: \'center\',\n            margin:10,\n            flex:1\n        },\n        columnViews:{\n            flexDirection:\'column\',\n            justifyContent: \'center\',\n            alignItems: \'center\',\n            margin: 5,\n        },\n        txtStyle:{\n            fontFamily: \'BYEKAN\',\n            color:\'white\'\n        },\n        imgStyle:{\n            height:hp(\'20%\'),\n            width:wp(\'20%\'),\n            resizeMode:\'contain\'\n        }\n    }\n)\nexport default AppMainPage;\n
Run Code Online (Sandbox Code Playgroud)\n\n

我不知道如何修复错误。感谢您的帮助\n这些是错误的照片:\n错误图像

\n

小智 8

这可以通过使用来解决:

fontSize: 20
Run Code Online (Sandbox Code Playgroud)

代替:

fontSize: "20px" 
Run Code Online (Sandbox Code Playgroud)

或者

fontSize: '20px' 
Run Code Online (Sandbox Code Playgroud)

..显然它需要一个数字而不是一个字符串。PS,字符串在 iOS 设备上运行良好,但在 Android 设备上出现错误。

如果您有package.lock文件或yarn.lock,请将其删除,删除node_modules文件夹并运行

npm cache clean --force
Run Code Online (Sandbox Code Playgroud)

然后运行:

npm install or yarn install
Run Code Online (Sandbox Code Playgroud)


sah*_*555 2

在某个地方,您将 fontSize 从字符串更改为双倍,如果您在某个地方使用图标,它可能是文本也可能是图标,我遇到了同样的问题,为我使用字体或图标的每个地方提供等效的数据类型