react-native - TypeError : undefined is not an object (evaluating 'style.width')
问题描述
Hello there I am trying to learn the basics of react navigation and I am setting up a background image for my simple application. I want my background image to fit in the background and I used ImageBackground so I can use components inside of it. The problem is that I keep getting this error TypeError:undefined is not an object ( evaluating style.width )
class loginScreen extends React.Component {
render() {
return (
<ImageBackground
source={require('./app/img/epicCat.jpg')}
Style={styles.backgroundImage}
>
<View Style={styles.parentContainer}>
<View Style={styles.usernameContainer}>
<Text Style={styles.usernameTextDesign}>USERNAME</Text>
<TextInput
Style={styles.usernameTextInput}
underlineColorAndroid='red'
>
</TextInput>
<Text Style={styles.passwordTextDesign}>PASSWORD</Text>
<TextInput Style={styles.passwordTextInput}
underlineColorAndroid='red'
>
</TextInput>
<Button Style={styles.loginButton}
title="LOG-IN"
>
</Button>
</View>
</View>
</ImageBackground>
);
}
}
const styles = StyleSheet.create({
parentContainer: {
flex: 1,
fontFamily: "Montserrat",
fontSize: 70,
alignItems: 'center',
justifyContent: 'center',
},
backgroundImage: {
flex: 1,
alignItems: 'center',
justifyContent: 'center',
height: '100%',
width: '100%',
},
解决方案
Looking from the code, I think you have a typo, instead ofStyle={...}
it should be style={...}
推荐阅读
- c# - XML 反序列化期间的“未知节点:VarName”
- powerbi - 根据条件增加日期列
- c - 将数组复制到每个数据字段中的链表
- regex - 如何在颤动中将空组与正则表达式匹配?
- node.js - Sequelize-Oracle 仅返回 100 行,即使限制超过 100
- cuda - Cuda:将一维数组从 CPU 复制到 GPU
- php - 如何在 PHP 中按值对对象数组集合进行排序
- pandas - vote_counts = md[md['vote_count'].notnull()]['vote_count'].astype('int')
- react-apollo - 如何获取整个分页列表/重新获取整个分页列表?
- css - 无法通过遍历
使用scrapy和css来刮