【问题标题】:[Unhandled promise rejection: TypeError: undefined is not a function (evaluating '_expo2.default.loadAsync')][Unhandled promise rejection: TypeError: undefined is not a function (evaluating '_expo2.default.loadAsync')]
【发布时间】:2019-02-24 02:31:11
【问题描述】:

我收到一个带有此错误的黄色框 [未处理的承诺拒绝:TypeError: undefined is not a function (evalating '_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>
    );
  }
}

【问题讨论】:

  • 你能在代码 sn-p 中包含你的导入吗?看起来 loadAsync 是未定义的,但如果没有看到导入,就很难说出原因。

标签: javascript react-native


【解决方案1】:

给你@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'

【讨论】:

    【解决方案2】:

    我认为Font 导入应该是这样的:

    import { Font } from 'expo';
    

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

    【讨论】:

      猜你喜欢
      • 2019-11-02
      • 2020-07-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-04-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多