-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d5af67f
commit d559406
Showing
8 changed files
with
88 additions
and
106 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
import React from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import { connect } from 'react-redux'; | ||
import Snackbar from 'react-native-snackbar'; | ||
|
||
export class SnackbarHandler extends React.Component { | ||
static get propTypes() { | ||
return { | ||
dispatch: PropTypes.func, | ||
systemMessage: PropTypes.shape({ | ||
message: PropTypes.string, | ||
// code: PropTypes.string, | ||
// error: PropTypes.bool, | ||
}), | ||
}; | ||
} | ||
|
||
componentDidUpdate(prevProps) { | ||
if ( | ||
this.props.systemMessage.message && | ||
this.props.systemMessage.message !== prevProps.systemMessage.message | ||
) { | ||
this.showSnackbar(); | ||
} | ||
} | ||
|
||
duration = 2750; | ||
|
||
showSnackbar = () => { | ||
Snackbar.show({ | ||
title: this.props.systemMessage.message, | ||
duration: this.duration, | ||
}); | ||
|
||
setTimeout(() => { | ||
this.resetError(); | ||
}, this.duration); // Snackbar.LENGTH_LONG does not work here so we need to manually add the duration | ||
}; | ||
|
||
resetError = () => { | ||
this.props.dispatch({ | ||
type: 'RESET_SYSTEM_MESSAGE', | ||
}); | ||
}; | ||
|
||
render() { | ||
return null; | ||
} | ||
} | ||
|
||
function mapStateToProps(state) { | ||
return { | ||
systemMessage: state.appState.systemMessage, | ||
}; | ||
} | ||
|
||
export default connect(mapStateToProps)(SnackbarHandler); |