바르고 뜨겁게
ReactNative - Assets PreLoad 세팅 본문
ReactNative - Assets PreLoad 세팅
App.js
import React from 'react';
import { AppLoading } from "expo";
import * as Font from "expo-font";
import { Ionicons } from "@expo/vector-icons";
import { StyleSheet, Text, View } from 'react-native';
export default class App extends React.Component {
state = {
loaded: false
};
handleError = error => console.log(error); // 에러 핸들러
handleLoaded = () => this.setState({ loaded: true }); // 로딩 끝난 뒤
// 성공시 handleLoaded 호출
// 실패시 handleError 호출
loadAssets = async () => {
await Font.loadAsync({
Ionicons.font
});
};
render() {
const { loaded } = this.state;
if (loaded) {
return (
<View style={styles.container}>
<Text>Open up App.js to start working on your app!</Text>
</View>
);
} else {
return (
<AppLoading
startAsync={this.loadAssets}
onFinish={this.handleLoaded}
onError={this.handleError}
/>
);
}
}
}
const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: '#fff',
alignItems: 'center',
justifyContent: 'center',
},
});
'자바스크립트 > React Native' 카테고리의 다른 글
ReactNative - 슬라이드 배너 (0) | 2019.06.21 |
---|---|
ReactNative - CSS 두가지 방법 (0) | 2019.06.19 |
ReactNative - 화면이동 버튼 TouchableOpacity (1) | 2019.06.18 |
ReactNative - Tab Navigation (0) | 2019.06.18 |
ReactNative - 리액트란? + 환경 설정 (0) | 2019.06.18 |
Comments