fix(AbstractNotificationsContainer): dismiss timeout not always set
The docs of 'componentDidUpdate' say that it's not called for the initial render. If the component is added to the DOM with 1 notification already, then the update will not happen and timeout will never be set which will effectively break the timeouts chain.
This commit is contained in:
parent
f3f8dc2072
commit
95f684da2f
|
@ -51,18 +51,40 @@ export default class AbstractNotificationsContainer<P: Props>
|
||||||
this._onDismissed = this._onDismissed.bind(this);
|
this._onDismissed = this._onDismissed.bind(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets a timeout for the first notification (if applicable).
|
||||||
|
*
|
||||||
|
* @inheritdoc
|
||||||
|
*/
|
||||||
|
componentDidMount() {
|
||||||
|
// Set the initial dismiss timeout (if any)
|
||||||
|
this._manageDismissTimeout();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets a timeout if the currently displayed notification has changed.
|
* Sets a timeout if the currently displayed notification has changed.
|
||||||
*
|
*
|
||||||
* @inheritdoc
|
* @inheritdoc
|
||||||
*/
|
*/
|
||||||
componentDidUpdate(prevProps: P) {
|
componentDidUpdate(prevProps: P) {
|
||||||
|
this._manageDismissTimeout(prevProps);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets/clears the dismiss timeout for the top notification.
|
||||||
|
*
|
||||||
|
* @param {P} [prevProps] - The previous properties (if called from
|
||||||
|
* {@code componentDidUpdate}).
|
||||||
|
* @returns {void}
|
||||||
|
* @private
|
||||||
|
*/
|
||||||
|
_manageDismissTimeout(prevProps: ?P) {
|
||||||
const { _notifications } = this.props;
|
const { _notifications } = this.props;
|
||||||
|
|
||||||
if (_notifications.length) {
|
if (_notifications.length) {
|
||||||
const notification = _notifications[0];
|
const notification = _notifications[0];
|
||||||
const previousNotification
|
const previousNotification
|
||||||
= prevProps._notifications.length
|
= prevProps && prevProps._notifications.length
|
||||||
? prevProps._notifications[0]
|
? prevProps._notifications[0]
|
||||||
: undefined;
|
: undefined;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue