[未处理的承诺拒绝:TypeError:未定义不是一个函数(正在评估'_expo2.default.loadAsync')]

时间:2018-09-19 20:43:08

标签: javascript react-native

我收到一个带有此错误的黄色框[未处理的承诺拒绝:TypeError:未定义不是函数(正在评估'_expo2.default.loadAsync')]

我不知道为什么它无法加载屏幕组件和字体。任何与我有关的想法都很感激。

class ProfileScreen extends Component {   
state = {
    fontLoaded: false,
};
async componentDidMount() {
    await Font.loadAsync({
        'Rubik-Regular': require('../../assets/Rubik-Regular.ttf'),
    }),
    // Setting the state to true when font is loaded
    this.state({fontLoaded: true});
}
render() {
    return (
        <Container style={styles.container}> 
        {
            this.state.fontLoaded ? (
        <ScrollView>
            <View style={{flex: 1}}>
            <Text style={{textAlign: 'center', color: '#fff'}}>
                Sam James
            </Text>
            </View>
            <View style={styles.container}>
            <Avatar
                size="xlarge"
                rounded
                source={{uri: "https://s3.amazonaws.com/uifaces/faces/twitter/adhamdannaway/128.jpg"}}
                onPress={() => console.log("Works!")}
                activeOpacity={0.7}
                />
            </View>
            </ScrollView>
        ) : null
        }

        </Container>
    );
  }
}

2 个答案:

答案 0 :(得分:0)

您在这里@bmovement

import React, { Component } from "react";
import { 
View,
Text,
StyleSheet,
} from "react-native";

import {ImageBackground, Tile , Overlay, Subtitle} from '@shoutem/ui'
import {Avatar} from 'react-native-elements'
import {Container, } from 'native-base'
import Font from 'expo'

答案 1 :(得分:0)

我认为Font导入应类似于:

import { Font } from 'expo';

请参见以下示例:https://medium.com/@piyushgupta_81472/using-custom-fonts-in-expo-the-best-way-81f0e785580c