[FIX] Prevent toast ref error (#1744)

This commit is contained in:
Diego Mello 2020-02-17 13:06:08 -03:00 committed by GitHub
parent 290c53efa9
commit 677b28818d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 6 additions and 2 deletions

View File

@ -43,15 +43,19 @@ class Toast extends React.Component {
EventEmitter.removeListener(LISTENER);
}
getToastRef = toast => this.toast = toast;
showToast = ({ message }) => {
this.toast.show(message, 1000);
if (this.toast && this.toast.show) {
this.toast.show(message, 1000);
}
}
render() {
const { theme } = this.props;
return (
<EasyToast
ref={toast => this.toast = toast}
ref={this.getToastRef}
position='center'
style={[styles.toast, { backgroundColor: themes[theme].toastBackground }]}
textStyle={[styles.text, { color: themes[theme].buttonText }]}