我已经删除了node_modules并重新运行npm安装。在此之后,我得到了一个错误:
Error while updating property 'fontSize' in shadow node of type: RCTText
Value for fontSize cannot be cast from String to Double
我以fontSize:'20‘的形式将所有fontSize更改为fontSize:20,但错误再次显示。现在,我删除了所有文件中的fontSize属性,并且再次存在错误。以下是我的package.json内容:
{
"name": "myApp",
"version": "0.0.1",
"private": true,
"scripts": {
"start": "node node_modules/react-native/local-cli/cli.js start",
"test": "jest"
},
"dependencies": {
"jetifier": "^1.6.4",
"native-base": "^2.13.8",
"prop-types": "^15.7.2",
"react": "16.8.3",
"react-native": "0.59.8",
"react-native-dialog": "^5.6.0",
"react-native-gesture-handler": "^1.5.0",
"react-native-ionicons": "^4.6.3",
"react-native-material-dropdown": "^0.11.1",
"react-native-responsive-screen": "^1.3.0",
"react-native-slideshow": "^1.0.1",
"react-navigation": "^3.13.0"
},
"devDependencies": {
"@babel/core": "7.4.4",
"@babel/runtime": "7.4.4",
"babel-jest": "24.8.0",
"jest": "24.8.0",
"metro-react-native-babel-preset": "0.54.0",
"react-test-renderer": "16.8.3"
},
"jest": {
"preset": "react-native"
},
"rnpm": {
"assets": [
"./assets/fonts"
]
}
}
更新:应用程序的 MainPage:
import React, { Component } from 'react';
import { View, Text,StyleSheet,Image,TouchableWithoutFeedback } from 'react-native';
import Slideshow from 'react-native-slideshow';
import {widthPercentageToDP as wp, heightPercentageToDP as hp} from 'react-native-responsive-screen';
import Colors from '../Colors';
import Strings from '../Strings';
import DrawerNavigator from '../routes/DrawerNavigator';
class AppMainPage extends Component {
constructor(props) {
super(props);
this.state = {
position: 0,
interval: null,
dataSource: [],
sliderSource:[]
};
}
componentDidMount(){
this.fetchSliderImage();
}
componentWillMount() {
this.setState({
interval: setInterval(() => {
this.setState({
position: this.state.position === this.state.dataSource.length-1 ? 0 : this.state.position + 1
});
}, 2000)
});
}
componentWillUnmount() {
clearInterval(this.state.interval);
}
getAuthAndReload(){
ajax.fetchAuth().then(()=>{this.fetchSliderImage()});
}
async fetchSliderImage(){
try{
let response = await fetch(Strings.baseUrl+'spanser/new?type=1&ostanId=1', {
method: 'POST',
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json',
'Authorization': 'Bearer ' +Strings.id_token
}
}).then((resp) => {
return resp.json()
})
.then((responseJson) => {
const json_data = responseJson;
if("title" in responseJson && responseJson.title=="Unauthorized" ){
this.setState({loadData:1},()=>this.getAuthAndReload());
return 0;
}
else{
const arr = Object.keys(json_data).map(function(_) { return json_data[_]; });
var resultArray=new Array();
for(i=0;i<arr.length;i++){
resultArray.push({'title':arr[i].title,'caption':'','url':Strings.imageUrl+arr[i].image1});
}
this.setState({sliderSource:resultArray,dataSource:arr});
return arr;
}
});
}
catch (error) {
console.error(error);
}
}
onImageClick(){
console.log('&&'+this.state.dataSource[0]);
console.log('******'+this.state.position);
this.props.navigation.navigate('SponserPage',{currentItem:this.state.dataSource[this.state.position]})
}
render() {
return (
<View style={{backgroundColor:'black',flex:1}}>
<DrawerNavigator/>
<View style={styles.rowViews}>
<View style={styles.columnViews}>
<Image style={styles.imgStyle} source={require('../Icons/play-button.png')}/>
<Text style={styles.txtStyle}>ویدیوی ویژه</Text>
</View>
<View style={styles.columnViews}>
<Image style={styles.imgStyle} source={require('../Icons/star.png')}/>
<Text style={styles.txtStyle}>پیشنهادهای ویژه</Text>
</View>
<View style={styles.columnViews}>
<Image style={styles.imgStyle} source={require('../Icons/irandokht.png')}/>
<TouchableWithoutFeedback onPress={()=>this.props.navigation.navigate('SalonList')}>
<Text style={styles.txtStyle}>لیست سالنها</Text></TouchableWithoutFeedback>
</View>
</View>
<View style={{width:'100%',height:2,backgroundColor:Colors.yellow}}/>
<View style={styles.rowViews}>
<View style={styles.columnViews}>
<Image style={styles.imgStyle} source={require('../Icons/trophy.png')}/>
<Text style={styles.txtStyle}>برندگان مسابقات</Text>
</View>
<View style={styles.columnViews}>
<Image style={styles.imgStyle} source={require('../Icons/trophy(1).png')}/>
<Text style={styles.txtStyle}>سالن برتر ماه</Text>
</View>
<TouchableWithoutFeedback style={styles.columnViews} onPress={()=>this.props.navigation.navigate('Mosabeqat')}>
<View >
<Image style={styles.imgStyle} source={require('../Icons/medal.png')}/>
<Text style={styles.txtStyle}>شرکت در مسابقه </Text>
</View>
</TouchableWithoutFeedback>
</View>
<View style={styles.rowViews}>
<View style={styles.columnViews}>
<Image style={styles.imgStyle} source={require('../Icons/contact.png')}/>
<Text style={styles.txtStyle}>ارتباط با ایران دخت</Text>
</View>
<TouchableWithoutFeedback style={styles.columnViews} onPress={()=>this.props.navigation.navigate('MajaleyeTakhasosi')}>
<View >
<Image style={styles.imgStyle} source={require('../Icons/open-magazine.png')}/>
<Text style={styles.txtStyle}>مجله تخصصی</Text>
</View>
</TouchableWithoutFeedback>
<View >
<Image style={styles.imgStyle} source={require('../Icons/newspaper.png')}/>
<TouchableWithoutFeedback style={styles.columnViews} onPress={()=>this.props.navigation.navigate('NewsNav')}>
<Text style={styles.txtStyle}>اخبار مهم</Text>
</TouchableWithoutFeedback></View>
</View>
<View style={styles.columnViews}>
{this.state.sliderSource.length>0?
<Slideshow
containerStyle={{padding: 10,}}
dataSource={this.state.sliderSource}
position={this.state.position}
resizeMode='contain'
onPositionChanged={position => this.setState({ position:position })}
onPress={()=>{this.onImageClick()}}/>
:
<View/>
}
</View>
</View>
);
}
}
const styles=StyleSheet.create(
{
rowViews:{
flexDirection:'row',
justifyContent: 'space-between',
alignItems: 'center',
margin:10,
flex:1
},
columnViews:{
flexDirection:'column',
justifyContent: 'center',
alignItems: 'center',
margin: 5,
},
txtStyle:{
fontFamily: 'BYEKAN',
color:'white'
},
imgStyle:{
height:hp('20%'),
width:wp('20%'),
resizeMode:'contain'
}
}
)
export default AppMainPage;
我不知道怎么纠正错误。谢谢你的帮助--这是错误的照片:
发布于 2020-06-06 09:17:53
在某个地方,您要将fontSize从字符串改为双倍--它可能是文本以及图标--如果您在某个地方使用图标,我已经解决了相同的问题,给出了我使用字体或图标的每个地方的等效数据类型。
发布于 2022-10-28 16:59:43
可以通过以下方式解决这一问题:
fontSize: 20
而不是:
fontSize: "20px"
或
fontSize: '20px'
..apparently期待的是一个数字而不是一个字符串。PS,string在iOS设备上运行良好,但在Android设备上出现错误。
如果您有package.lock文件或yarn.lock,请删除它,删除node_modules文件夹并运行
npm cache clean --force
然后跑:
npm install or yarn install
发布于 2020-04-07 10:34:45
react-native link
.这个问题为我解决了。
https://stackoverflow.com/questions/58771086
复制相似问题