react-native-in-app-notification icon indicating copy to clipboard operation
react-native-in-app-notification copied to clipboard

consecutive calls shows just first one

Open dengue8830 opened this issue 4 years ago • 2 comments

Problem

if i call the notification two or more times consecutively it renders just the first one. If i use a timeout for the second one i get a good behaviour.

Proposal

I'm thinking implement a delayed queue in order to show consecutive calls in a queued way and show them one by one with a timeout. Do you accept a pull request for this?

dengue8830 avatar Oct 23 '19 15:10 dengue8830

Sure please propose a PR I’ll be happy to take a look :)

On 23 Oct 2019, at 16:36, David Rearte [email protected] wrote:

 Problem

if i call the notification two or more times consecutively it renders just the first one. If i use a timeout for the second one i get a good behaviour.

Proposal

I'm thinking implement a delayed queue in order to show consecutive calls in a queued way and show them one by one with a timeout. Do you accept a pull request for this?

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub, or unsubscribe.

robcalcroft avatar Oct 23 '19 15:10 robcalcroft

I will try to add this feature next week, by the moment i used this code (if someone find it useful) in my project

This is a resume of the real code

function timeout(ms) {
  return new Promise(resolve => setTimeout(resolve, ms));
}

class NotificationService {
    // you can call this one several times
    show(notif) {
          this.queue.push(notif);
          this.evaluateQueue();
    }

    async evaluateQueue() {
      if (!this.queue.length || this.isEvaluationProcessLocked) {
        return;
      }
      this.isEvaluationProcessLocked = true;
      // We can use a recursive approach too
      while (this.queue.length) {
        this._show(this.queue.splice(0, 1)[0]); // the real showNotification api
        await timeout(4000); // closeInterval, check docs of this lib
      }
      this.isEvaluationProcessLocked = false;
  }
}

dengue8830 avatar Oct 23 '19 20:10 dengue8830