【发布时间】:2017-10-14 20:09:14
【问题描述】:
问题: 所以我正在使用自定义字体编写应用程序,并且我对其进行了编码,因此当您按下按钮时,字体将加载。当您按下显示“15 秒后按我加载!”的按钮时用户输入框应该与一些空帖子、一些文本和另一个按钮(还没有做任何事情)一起出现,但什么都没有显示。我没有收到任何错误。我想知道为什么什么都没有显示,以及如何获得正确的东西来渲染。
工作原理: 当您按下按钮“按我在 15 秒后加载应用程序!”变量 fontLoaded 应该更改为 true (我不知道它是否真的发生了变化),然后这将导致代码渲染所有其他内容以开始。没有渲染。
我还尝试了什么: 我尝试了另一种方法,您将变量 fontLoaded 放在加载字体的代码之后,因此它是自动的,并且也没有任何作用。我没有尝试过其他任何东西,因为我不知道还能尝试什么。
代码:
import React, { Component } from 'react';
import { StyleSheet, Text, View, Image, TextInput, ScrollView, TouchableHighlight, Button } from 'react-native';
import { Font } from 'expo';
var fontLoaded = false;
export default class App extends React.Component {
state = {
fontLoaded: false,
};
componentDidMount() {
Expo.Font.loadAsync({
'Cabin-Regular-TTF': require('./Cabin-Regular-TTF.ttf'),
});
}
constructor(props) {
super(props);
this.state = { postInput: ""}
}
render() {
return (
<View style={styles.container}>
<View style={styles.container}>
<View style={{width: 1, height: 30, backgroundColor: '#e8e8e8'}} />
<Button
onPress={() => this.setState({ fontLoaded: true })}
title="Press Me To Load the App After 15 Seconds!"
color="#fe8200"
accessibilityLabel="Wait 15 seconds and then press me to load the font!"
/>
</View>
{fontLoaded ? (
<View style={styles.container}>
<Text style={{ fontFamily: 'Cabin-Regular-TTF', fontSize: 16 }}>
Whats on your mind? Create a post!
</Text>
<TextInput>
style={{height:40, width: 320, borderColor: '#303030', borderWidth: 1}}
onChangeText={(postInput)=>this.setState({postInput})}
value={this.state.postInput}
</TextInput>
<Button
title="+"
color="#fe8200"
accessibilityLabel="Wait 15 seconds and then press me to load the font!"
/>
<ScrollView>
<View style={{width: 1, height: 6, backgroundColor: '#e8e8e8'}} />
<View style={{width: 300, height: 250, backgroundColor: '#1daff1'}} />
<View style={{width: 300, height: 40, backgroundColor: '#147aa8'}} />
<View style={{width: 1, height: 6, backgroundColor: '#e8e8e8'}} />
<View style={{width: 300, height: 250, backgroundColor: '#1daff1'}} />
<View style={{width: 300, height: 40, backgroundColor: '#147aa8'}} />
<View style={{width: 1, height: 6, backgroundColor: '#e8e8e8'}} />
</ScrollView>
</View>) : (null) }
</View>
);
}
}
const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: '#e8e8e8',
alignItems: 'center',
justifyContent: 'center'
},
});
【问题讨论】:
标签: javascript css react-native