TypeError:undefined不是对象(评估“ asset.scales”)

XaviHub

我对React Native还是很陌生,但我正在尝试使用该ImageBackground组件将png添加为背景图像我的项目目录中的“资产”文件夹中有png。当我在iPhone上使用Expo运行应用程序时,出现以下错误:TypeError: undefined is not an object (evaluating 'asset.scales')

这是我的代码:

import React, {useState, Component} from 'react';
import {StyleSheet, Text, View, TextInput, TouchableOpacity, Image} from 'react-native';
import * as Font from "expo-font";
import {ImageBackground} from "react-native-web";

class LoginPage extends Component {

    state = {
        fontLoaded: false,
    };


    async componentDidMount() {
        await Font.loadAsync({
            'Veles-Regular' : require("./assets/fonts/Veles-Regular.otf"),
        });
        console.log('HI');
        this.setState({fontLoaded: true});
    }


    render() {
        return (
            <ImageBackground source={require('./assets/login_splash.png')} style={{width: 100, height: 100}}>
                <View style={styles.loginScreen}>
                    <View style={{flex: 1, justifyContent: 'center'}}>
                        {
                            this.state.fontLoaded ? (
                                <Text style={{fontSize: 60, color: 'white', fontFamily: 'Veles-Regular'}}>App Name</Text>
                            ) : null
                        }
                    </View>
                    <View style={{flex: 1, justifyContent: 'center', alignItems: 'center', width: '85%'}}>
                        <TextInput style={[styles.loginInput, {marginBottom: 5}]} placeholder=' username'
                                   placeholderTextColor={'rgba(255,255,255,0.3)'} textAlign='center'/>
                        <TextInput style={[styles.loginInput, {marginTop: 5, marginBottom: 5}]} placeholder=' password'
                                   placeholderTextColor={'rgba(255,255,255,0.3)'} textAlign='center'/>
                        <View style={{height: 15}}/>
                        <TouchableOpacity onPress={() => {
                        }}>
                            <Text style={{color: 'white', fontWeight: 'bold', fontSize: 24}}>Log in</Text>
                        </TouchableOpacity>
                    </View>
                    <View style={{flex: 2, justifyContent: 'center'}}>
                        <View style={{flex: 9}}/>
                        <Text style={{flex: 1, fontSize: 24, color: 'white', textAlign: 'center'}}>Don't have an
                            account?</Text>
                        <TouchableOpacity style={{color: 'white', fontWeight: 'bold', fontSize: 24}}>
                            <Text style={{color: 'white', fontWeight: 'bold', fontSize: 24, textAlign: 'center'}}>Sign
                                Up</Text>
                        </TouchableOpacity>
                        <View style={{height: 30}}/>
                    </View>
                </View>
            </ImageBackground>
        );
    }
}


const styles = StyleSheet.create({
    loginScreen: {
        flex: 1,
        paddingTop: 50,
        alignItems: 'center',
        justifyContent: 'center',
    },
    loginInput: {
        width: '100%',
        backgroundColor: 'rgb(40,40,40)',
        height: 44,
        fontSize: 24,
        color: 'white',
        borderWidth: 1,
        borderColor: 'rgb(60,60,60)',
        borderRadius: 25
    },
});

export default LoginPage;

Andropogon

我有类似的问题,“图像”组件和类似的错误“ TypeError:未定义不是对象(评估'asset.scales')”。这个问题的解决方法非常简单,更改:

import {ImageBackground} from "react-native-web";

至:

import React, {useState, Component, ImageBackground} from 'react';

看来我们从错误的包中导入了组件:)

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

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

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

TypeError:undefined不是对象(评估'object ['body']')

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

TypeError:undefined不是对象(评估'_asyncStorage.AsyncStorage.setItem')

TypeError:undefined不是对象(评估'_this3.state.bind')

TypeError:undefined不是对象(评估'table [0] [3]')

TypeError:undefined不是对象(正在评估'const.join')

TypeError : undefined 不是对象(评估“this3.props”)

TypeError:undefined不是对象(评估'nod.images.fluid')-

TypeError:undefined不是带有React-router-dom的对象(评估“ undefined.state”)

TypeError:undefined不是函数(评估调度)

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

为什么在删除组件时出现TypeError:undefined不是对象(评估“ items.items.map”)?

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

TypeError:undefined不是一个对象(评估“ navigation.state”)-反应本机

jQuery数据表子行-TypeError:undefined不是对象(评估'm [n] .style')

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

TypeError:使用FlatList替换ListView时,undefined不是对象(评估'_this2.state.dataSource.cloneWithRows')

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

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

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

因果关系+ angular-mocks TypeError:'undefined'不是对象(评估'angular.mock = {}')

TypeError:undefined不是对象(评估'_this.props.auth(values.username,values.password).then')

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

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

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

如何解决'TypeError:undefined不是对象(评估'subitem.media_details.sizes.medium.source_url')'

使用firestoreConnect的react-redux-firebase错误。TypeError:undefined不是对象(正在评估“ this.store.firestore”)

可能的未处理的承诺拒绝(id:0):TypeError:undefined不是对象(评估'_this.props.navigation.navigate')

ReactNative TypeError:undefined 不是一个对象(评估'Object.keys(dataBlob[sectionID])')