TypeError: undefined is not an object (evaluating style.width) react native

本杰明·海因克

我只是想在<ImageBackground>我的 React Native 项目中添加一个,但我总是收到错误消息:“TypeError: undefined is not an object (evaluating style.width)”。错误位于 ImageBackground(在 index.js:31)。

我有另一个项目,它可以像这样完美地工作。会不会是 React Native 版本的问题?

import React, {Component} from 'react'
import {
StyleSheet,
View,
TouchableOpacity,
Text,
AsyncStorage,
Dimensions,
ImageBackground
} from 'react-native'
import * as Colors from '../../themes/colors'
import {getNavigationOptions} from '../../utils/navigation'
import * as ducks from '../../ducks'
import {connect} from 'react-redux'

class LoginScreen extends Component{
  login(){
    const {updateCurrentUser} = this.props
    updateCurrentUser({name: 'Mauricio'})
    console.log('login', this.props.currentUser)
  }

olvidarContraseña(){
   console.log('olvidar contraseña')
}

render(){
return (
  <View style={styles.container}>
    <View style={[styles.input, {borderColor: Colors.primary}]}>
      <ImageBackground>
        style={styles.backgroundImage}
        source={require('./trigo_background.jpg')}>
        {/* <TouchableOpacity
          style={styles.btnSubmit}
          onPress={() => this.login()}
        >
          <Text style={{textAlign: 'center', color: Colors.primary}}>
            Iniciar Sesión
          </Text>
        </TouchableOpacity> */}
      </ImageBackground>
    </View>
  </View>
)
}
}

const styles = StyleSheet.create({
 container: {
  flex: 1,
  justifyContent: 'center',
  alignItems: 'center',
  backgroundColor: '#F5FCFF'
},
backgroundImage: {
 width: Dimensions.get('window').width,
 height: Dimensions.get('window').height,
 position: 'absolute',
 top: 0,
 left: 0
},
btnSubmit: {
 justifyContent: 'center',
 padding: 10,
 flexDirection: 'row'
},
input: {
 height: 40,
 paddingHorizontal: 10,
 borderWidth: 1,
 borderRadius: 5
 }
})

LoginScreen.navigationOptions = ({navigation}) =>
  getNavigationOptions('Login', Colors.primary, 'white')

const mapStateToProps = store => ({
   currentUser: store.currentUser
})

const mapDispatchToProps = {
  updateCurrentUser: ducks.updateCurrentUser
}

export default connect(mapStateToProps, mapDispatchToProps)(LoginScreen)
不列颠瓦迪亚

错误在您的代码片段中

<ImageBackground> <== Here
        style={styles.backgroundImage}
        source={require('Valcereal/assets/trigo_background.jpg')}>
        {/* <TouchableOpacity
          style={styles.btnSubmit}
          onPress={() => this.login()}
        >
          <Text style={{textAlign: 'center', color: Colors.primary}}>
            Iniciar Sesión
          </Text>
        </TouchableOpacity> */}
      </ImageBackground>

您已关闭标签在其后添加代码行,这会引发错误,因为它不是有效的jsx

正确的代码是

<ImageBackground
            style={styles.backgroundImage}
            source={require('Valcereal/assets/trigo_background.jpg')}>
            {/* <TouchableOpacity
              style={styles.btnSubmit}
              onPress={() => this.login()}
            >
              <Text style={{textAlign: 'center', color: Colors.primary}}>
                Iniciar Sesión
              </Text>
            </TouchableOpacity> */}
          </ImageBackground>

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

react native TypeError: TypeError: undefined is not an object (evaluating'_this.state.cartAmount')

TypeError: undefined is not an object (evaluating 'navigation.navigate') React Native

React Native: TypeError: undefined is not an object (evaluating 'this.props.navigation.navigate') 当点击按钮时。为什么?

Expo/React Native 错误 - TypeError: undefined is not an object (evaluating 'string.toLowerCase')

TypeError: undefined is not an object (evaluating 'navigation.navigate') - React Navigation

TypeError: undefined is not an object (evaluating 'this.props.location') [ReactJS + react-router-dom V4]

React Native TypeError: TypeError: undefined is not an object (评估'this.props.data.map')

React-Native:TypeError:undefined 不是对象

[Vue 警告]:渲染错误:“TypeError: undefined is not an object (evaluating 'this.$store.state')”

如何解决 TypeError: undefined is not an object (evaluating 'rss.items[0].title')

TypeError : Object (...) is not a function react native stack navigation

React Native Component Exception: undefined 不是一個對象 (evaluating_useContext.isAuthenticated

TypeError : undefined 不是一个对象(评估“style.width”)

React Native TypeError:undefined 不是对象(评估“props.getItem”)

React Native,TypeError:undefined不是一个对象,当它是

react native TypeError: this.setState is not a function.'this.setState' is undefined)

TypeError: undefined 不是 React-Native 中的对象

第二次访问屏幕时,React Native null is not an object (evaluating'_this2.state.data') 错误

“'Undefined is not an object (evaluating 'row[0].val')” 反应原生错误

如何修复“TypeError: null is not an object (evaluating 'data[index]')

React Native:TypeError:undefined不是一个对象(评估'_this.props.data.map')

React Native:未处理的Promise拒绝:TypeError:undefined不是对象(评估'response.json')

TypeError:undefined不是一个对象(正在评估“ navigation.push”)React Native

TypeError:undefined不是React Native中的一个对象(评估'this.state.Gas')

TypeError:undefined不是React Native中的一个对象(评估'this.state.Gase')

TypeError:undefined不是在react-native-google-places-autocomplete中的对象(评估“ navigator.geolocation.getCurrentPosition”)

如何解决TypeError:undefined不是React-Native中的对象(评估'_core.pathUtils.urlToPathAndParams')

React Native:TypeError:undefined不是一个对象(评估'this.props.navigation.navigate')

React Native TypeError:undefined 不是一个对象(评估'_ref.item')