首页 > 解决方案 > 在 SDK 40 上反应本机博览会警告

问题描述

我正在做一个基本的 react native expo 应用程序,我有这个警告:

Your project is accessing the following APIs from a deprecated global rather than a module import: Font (expo-font).

The global "__expo" and "Expo" objects will be removed in SDK 41. Learn more about how to fix this warning: https://expo.fyi/deprecated-globals

我该如何解决?(不仅忽略警告,我还想解决这个问题)。我的代码是:

// RNRF logic here
import React, { Component } from 'react';

import {
  StyleSheet,
  TouchableOpacity,
  Text,
  View,
} from 'react-native'

import AppLoading from 'expo-app-loading';
import * as Font from 'expo-font';
import { Ionicons } from '@expo/vector-icons';

import { Container, Root} from 'native-base';

import Constants from 'expo-constants';

export default class App extends React.Component {
  constructor(props) {
    super(props);
    this.state = {
      isReady: false,
    };
  }

  async componentDidMount() {
    await Expo.Font.loadAsync({
      'Roboto': require('native-base/Fonts/Roboto.ttf'),
      'Roboto_medium': require('native-base/Fonts/Roboto_medium.ttf'),
      ...Ionicons.font,
    });
    this.setState({ isReady: true });
  }

  render(){
    if (!this.state.isReady) {
      return <AppLoading />;
    }

    return(
            <View>
                <Text>Hello</Text>
            </View>
        );
  }
}

谢谢................................................. ……

标签: react-nativeexpo

解决方案


尝试从“componentDidMount”函数中删除单词“Expo”,因为您已经从“expo-font”导入“Font”


推荐阅读