Don't call setState if unmounted before font loads

fbshipit-source-id: 2ff8070
This commit is contained in:
Brent Vatne
2017-07-07 00:08:48 +00:00
committed by Exponent GitHub Bot
parent c0d7f949a0
commit 04fe6fb39d
2 changed files with 9 additions and 6 deletions
+8 -5
View File
@@ -1,10 +1,8 @@
import React from 'react';
import { Text } from 'react-native';
import { Font } from 'expo';
import createIconSet
from './vendor/react-native-vector-icons/lib/create-icon-set';
import createIconButtonComponent
from './vendor/react-native-vector-icons/lib/icon-button';
import createIconSet from './vendor/react-native-vector-icons/lib/create-icon-set';
import createIconButtonComponent from './vendor/react-native-vector-icons/lib/icon-button';
export default function(glyphMap, fontName, expoAssetId) {
const expoFontName = Font.style(fontName, {
@@ -22,12 +20,17 @@ export default function(glyphMap, fontName, expoAssetId) {
};
async componentWillMount() {
this._mounted = true;
if (!this.state.fontIsLoaded) {
await Font.loadAsync(font);
this.setState({ fontIsLoaded: true });
this._mounted && this.setState({ fontIsLoaded: true });
}
}
componentWillUnmount() {
this._mounted = false;
}
setNativeProps(props) {
if (this._icon) {
this._icon.setNativeProps(props);