- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
在这里 react 本地新人!
我正在尝试使用 expo 在我的 native 应用程序中使用自定义字体。我尝试按照 https://docs.expo.io/versions/latest/guides/using-custom-fonts.html#using-custom-fonts 上的说明进行操作没有运气。
这是我的 App.js:
import React from 'react';
import { View, Text, TouchableOpacity, TextInput, StyleSheet, AsyncStorage, Alert, Platform, NativeModules } from 'react-native';
import { Expo } from 'expo';
import { StackNavigator } from 'react-navigation';
import LoginScreen from './src/views/LoginScreen';
import AuthenticatedScreen from './src/views/AuthenticatedScreen';
import './ReactotronConfig'
import styles from './src/styles/ParentStyles'
const { StatusBarManager } = NativeModules;
const RootStack = StackNavigator(
{
Login: { screen: LoginScreen },
Authenticated: { screen: AuthenticatedScreen }
},
{ initialRouteName: 'Login'}
);
const STATUSBAR_HEIGHT = Platform.OS === 'ios' ? 20 : StatusBarManager.HEIGHT;
export default class App extends React.Component {
state = {
fontLoaded: false,
};
async componentDidMount() {
await Expo.Font.loadAsync({
'open-sans-bold': require('./src/assets/fonts/OpenSans-Bold.ttf'),
});
console.log('running')
this.setState({ fontLoaded: true });
}
render() {
console.log('statusBarHeight: ' + StatusBarManager.HEIGHT);
return (<RootStack />);
}
}
console.disableYellowBox = true;
open-sans-bold
在我的登录页面中,如下所示:
render() {
return (
<View style = { parentStyles.container } >
<View style={ loginStyles.backgroundImageContainer }>
<Image style={ loginStyles.backgroundImage } source={require('../assets/img/splash.png')} />
</View>
<View style={ loginStyles.logoImageContainer } >
<Image style={ loginStyles.logoImage } source={require('../assets/img/PMlogo.png')} resizeMode="contain"/>
</View>
<View style={{flex: 50 }} >
//***CALLING FONT HERE***
<Text style={{ fontFamily: 'open-sans-bold', fontSize: 56 }}>Email</Text>
<TextInput style = {loginStyles.input}
underlineColorAndroid = "transparent"
placeholder = "Email"
placeholderTextColor = "red"
autoCapitalize = "none"
ref = { input => { this.textInputEmail = input }}
onChangeText = { this.handleEmail }/>
<TextInput style = { loginStyles.input }
underlineColorAndroid = "transparent"
placeholder = "Password"
placeholderTextColor = "red"
autoCapitalize = "none"
ref = { input => { this.textInputPassword = input }}
onChangeText = { this.handlePassword }/>
<TouchableOpacity
style = {loginStyles.submitButton}
onPress = { () => this.login(this.state.email, this.state.password) }
>
<Text style = { loginStyles.submitButtonText }> Login </Text>
</TouchableOpacity>
</View>
</View>
)
}
fontFamily 'open-sans-bold' is not a system font and has not been loaded through Expo.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 Expo.Font.loadAsync.
最佳答案
嘿兄弟,这是适用于 app.js 的正确代码,仅适用于您的情况
import React from "react";
import { AppLoading, Font } from "expo";
import { StyleSheet, Text, View } from "react-native";
export default class App extends React.Component {
state = {
loaded: false,
};
componentWillMount() {
this._loadAssetsAsync();
}
_loadAssetsAsync = async () => {
await Font.loadAsync({
diplomata: require("./assets/fonts/DiplomataSC-Regular.ttf"),
});
this.setState({ loaded: true });
};
render() {
if (!this.state.loaded) {
return <AppLoading />;
}
return (
<View style={styles.container}>
<Text style={styles.info}>
Look, you can load this font! Now the question is, should you use it?
Probably not. But you can load any font.
</Text>
</View>
);
}
}
const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: "#fff",
alignItems: "center",
justifyContent: "center",
padding: 30,
},
info: {
fontFamily: "diplomata",
textAlign: "center",
fontSize: 14,
},
});
关于react-native - React Native Expo 不加载字体,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50256786/
我正在尝试设置 React 和 Expo monorepo 项目,一切似乎都很好,直到我想安装 react-navigation与 expo install根据 react-navigation 文档
我正在使用 expo-cli@3.0.10 此应用程序在安装在设备中的客户端博览会中运行良好 最佳答案 好的,我相信我找到了核心问题 - DNS 问题 . 无论您使用的是 Mac OS、Windows
如何在开发过程中获取重定向到 expo 应用程序的链接? 我有一个 React Native Expo 应用程序。在开发过程中以 èxpo start 开始。现在我喜欢使用 OAuth 2.0 身份验
为什么EXPO有两种通过Google进行身份验证的方式? 我不清楚expo-google-app-auth和expo-google-sign-in之间有什么区别。 在什么场合我应该使用哪一个? 最佳答
我正在使用 React Native 进行编码。当我第一次创建用于检查运行的 react native 应用程序时,我没有看到这一点。当我实现我的代码时看到这一点。我的目的是生成apk。 app.js
我已经在全局范围内安装了 expo-cli,但是当我尝试运行任何 expo 代码时,例如 expo start从任何地方,我得到:zsh: command not found: expoecho $P
我是react-native新手,我安装了expo,如下官方页面中提到的。 npm install expo-cli --global expo init my-new-project cd my-n
根据 Expo documentation with SQLite 我会这样查询: tx.executeSql(sqlStatement, arguments, success, error) 我是这
很多次我在启动 expo 项目后收到以下信息消息,似乎无法升级 expo-cli: 有一个新版本的 expo-cli 可用 (4.2.1)。您目前正在使用 expo-cli 3.28.0 使用您选择的
我已经使用 Expo 构建了一个应用程序,现在由于某些原因我想使用 expo eject 从 expo cli 中弹出该应用程序。我还能使用 Expo 套餐吗? 最佳答案 是的,Expo 包应该可以。
部署我的 Expo 网络项目时,我需要将一个文件添加到网络根目录(一个 Apple App 站点关联文件)。 Expo 开箱即用地支持此功能吗? 最佳答案 您所要做的就是在项目的根目录中创建一个名为“
我需要有关 expo xde 的帮助。 创建项目后,当我扫描二维码时,出现以下错误: there was a problem loading the experience. It looks like
我使用create-react-native-app创建了react-native项目。在此,我从 expo 导入权限模块, import {Permissions} from "expo"; 后来我
例如,如果我有组件: import React, { Component } from 'react'; import { Video } from 'expo'; let styles = requ
我将使用 Expo 制作一个应用程序,并与客户分享初步结果。我想告诉他们,这个世博应用程序反射(reflect)了最终的应用程序,它将作为独立的应用程序供我客户的客户一对一使用。 该应用程序的功能将是
When I run a Snack in the Expo Go app, is it doing anything more sophisticated than downloading t
我刚刚从 React 导航 5 升级到 6 并查看了 the doc for transparent modals .不幸的是,我无法让之前的屏幕显示在模态下。相反,我得到一个灰色背景。 我用我的代码
我尝试通过 expo 构建应用程序但失败了,我尝试重新安装 expo-cli。所以,我输入了下面的代码来删除 expo-cli。 npm -g uninstall expo-cli --save 和
我正在尝试运行我的 react-native 应用程序,我在 android 模拟器和我的手机 HUAWEI Y3II 上运行它,同样的事情发生了。 几天前我工作得很好,但突然这个错误不断出现:Cou
在 Expo 网络项目中是否有推荐的代码拆分方法? 我在文档中找不到任何内容,即使在网页性能页面上:https://docs.expo.io/guides/web-performance/ 我很惊讶,
我是一名优秀的程序员,十分优秀!