在React Native中使用矢量图标中的预加载图标

如何解决在React Native中使用矢量图标中的预加载图标

我试图在Expo应用程序的矢量图标中使用Entypo的“竖起大拇指”图标。我收到关于它是自定义字体的错误,需要使用Font.loadAsync。我通过了Expo - Preoloading and Caching Assets和其他一些关于stackoverflow的文章,并相应地将代码更改为以下内容-

import React,{ useState } from 'react';
import { StyleSheet,View,Text } from 'react-native';
import AppText from '../components/AppText';
import Screen from '../components/Screen';
import { AppLoading } from 'expo';
import * as Font from 'expo-font';
import { Entypo } from '@expo/vector-icons';

async function _loadAssetsAsync() {
    await Promise.all([Font.loadAsync(Entypo.font)]);
}

function SecurityScanReport(props) {
  const [isReady,setIsReady] = useState(false);
  
  if(!isReady){
    return (
      <AppLoading
        startAsync={_loadAssetsAsync}
        onFinish={() => setIsReady(true)}
        onError={console.warn}
      />
    );
  }
  else{
    let report = (
      <View style={styles.reportContainer}>
        <Entypo name='thumbs-up' size={120} color='green'/>
        <Text style={[{color: 'green'},{fontSize: 20}]}>Safe to Enter</Text>
      </View>
    );
    if(props.permitaccess === false){
      report = (
        <View style={styles.reportContainer}>
          <Entypo name='thumbs-down' size={120} color='red'/>
          <Text style={[{color: 'red'},{fontSize: 20}]}>Access Denied</Text>
        </View>
      );
    }

    return (
      <Screen style={styles.container}>
        <View style={styles.reportContainer}>
          {report}
        </View>
      </Screen>
    );
  }
}

const styles = StyleSheet.create({
  container: {
    justifyContent: 'center',alignItems: 'center',},reportContainer: {
    flex: 1,width: '100%',justifyContent: 'center',padding: 8,}

});

export default SecurityScanReport;

但是,我仍然遇到以下相同的错误。如何使用预先加载的资产或资产未正确加载?

fontFamily "entypo" is not a system font and has not been loaded through Font.loadAsync.

- If you intended to use a system font,make sure you typed the name correctly and that it is supported by your device operating system.

- If this is a custom font,be sure to load it with Font.loadAsync.
* [native code]:null in __expoConsoleLog
- node_modules/react-native/Libraries/LogBox/LogBox.js:33:4 in console.error
- node_modules/expo/build/environment/muteWarnings.fx.js:27:4 in error
- node_modules/expo/node_modules/expo-font/build/Font.js:29:16 in processFontFamily
- node_modules/react-native/Libraries/Renderer/implementations/ReactNativeRenderer-dev.js:3872:14 in diffProperties
- node_modules/react-native/Libraries/Renderer/implementations/ReactNativeRenderer-dev.js:3744:37 in addnestedProperty
- node_modules/react-native/Libraries/Renderer/implementations/ReactNativeRenderer-dev.js:3883:40 in diffProperties
- node_modules/react-native/Libraries/Renderer/implementations/ReactNativeRenderer-dev.js:4268:28 in createInstance
- node_modules/react-native/Libraries/Renderer/implementations/ReactNativeRenderer-dev.js:16949:39 in completeWork
- node_modules/react-native/Libraries/Renderer/implementations/ReactNativeRenderer-dev.js:20912:27 in completeUnitOfWork
- node_modules/react-native/Libraries/Renderer/implementations/ReactNativeRenderer-dev.js:20882:29 in performunitOfWork
- node_modules/react-native/Libraries/Renderer/implementations/ReactNativeRenderer-dev.js:20848:38 in workLoopSync
- node_modules/react-native/Libraries/Renderer/implementations/ReactNativeRenderer-dev.js:20456:22 in performSyncWorkOnRoot
* [native code]:null in performSyncWorkOnRoot
- node_modules/react-native/Libraries/Renderer/implementations/ReactNativeRenderer-dev.js:5703:31 in runWithPriority$argument_1
- node_modules/react-native/node_modules/scheduler/cjs/scheduler.development.js:818:23 in unstable_runWithPriority
- node_modules/react-native/Libraries/Renderer/implementations/ReactNativeRenderer-dev.js:5698:21 in flushSyncCallbackQueueImpl
- node_modules/react-native/Libraries/Renderer/implementations/ReactNativeRenderer-dev.js:5686:28 in flushSyncCallbackQueue
- node_modules/react-native/Libraries/Renderer/implementations/ReactNativeRenderer-dev.js:19845:30 in scheduleUpdateOnFiber
- node_modules/react-native/Libraries/Renderer/implementations/ReactNativeRenderer-dev.js:11880:16 in dispatchAction
* [native code]:null in dispatchAction
* app/screens/SecurityScanReport.js:20:18 in AppLoading.props.onFinish
- node_modules/expo/build/launch/AppLoading.js:30:31 in _startLoadingAppResourcesAsync
- node_modules/regenerator-runtime/runtime.js:63:36 in tryCatch
- node_modules/regenerator-runtime/runtime.js:293:29 in invoke
- node_modules/regenerator-runtime/runtime.js:63:36 in tryCatch
- node_modules/regenerator-runtime/runtime.js:154:27 in invoke
- node_modules/regenerator-runtime/runtime.js:164:18 in PromiseImpl.resolve.then$argument_0
- node_modules/promise/setimmediate/core.js:37:13 in tryCallOne
- node_modules/promise/setimmediate/core.js:123:24 in setImmediate$argument_0
- node_modules/react-native/Libraries/Core/Timers/JSTimers.js:135:14 in _callTimer
- node_modules/react-native/Libraries/Core/Timers/JSTimers.js:183:16 in _callImmediatesPass
- node_modules/react-native/Libraries/Core/Timers/JSTimers.js:446:30 in callImmediates
* [native code]:null in callImmediates
- node_modules/react-native/Libraries/BatchedBridge/MessageQueue.js:396:6 in __callImmediates
- node_modules/react-native/Libraries/BatchedBridge/MessageQueue.js:144:6 in __guard$argument_0
- node_modules/react-native/Libraries/BatchedBridge/MessageQueue.js:373:10 in __guard
- node_modules/react-native/Libraries/BatchedBridge/MessageQueue.js:143:4 in flushedQueue
* [native code]:null in flushedQueue
* [native code]:null in invokeCallbackAndReturnFlushedQueue

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐


Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其他元素将获得点击?
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。)
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbcDriver发生异常。为什么?
这是用Java进行XML解析的最佳库。
Java的PriorityQueue的内置迭代器不会以任何特定顺序遍历数据结构。为什么?
如何在Java中聆听按键时移动图像。
Java“Program to an interface”。这是什么意思?
Java在半透明框架/面板/组件上重新绘画。
Java“ Class.forName()”和“ Class.forName()。newInstance()”之间有什么区别?
在此环境中不提供编译器。也许是在JRE而不是JDK上运行?
Java用相同的方法在一个类中实现两个接口。哪种接口方法被覆盖?
Java 什么是Runtime.getRuntime()。totalMemory()和freeMemory()?
java.library.path中的java.lang.UnsatisfiedLinkError否*****。dll
JavaFX“位置是必需的。” 即使在同一包装中
Java 导入两个具有相同名称的类。怎么处理?
Java 是否应该在HttpServletResponse.getOutputStream()/。getWriter()上调用.close()?
Java RegEx元字符(。)和普通点?