Пример #1
0
        public Snackbar Add(string message, Severity severity = Severity.Normal, Action <SnackbarOptions> configure = null)
        {
            if (message.IsEmpty())
            {
                return(null);
            }

            message = message.Trimmed();

            var options = new SnackbarOptions(severity, Configuration);

            configure?.Invoke(options);

            var snackbar = new Snackbar(message, options);

            SnackBarLock.EnterWriteLock();
            try
            {
                if (Configuration.PreventDuplicates && SnackbarAlreadyPresent(snackbar))
                {
                    return(null);
                }
                snackbar.OnClose += Remove;
                SnackBarList.Add(snackbar);
            }
            finally
            {
                SnackBarLock.ExitWriteLock();
            }

            OnSnackbarsUpdated?.Invoke();

            return(snackbar);
        }
Пример #2
0
        public void Add(SnackbarType type, string message, Action <SnackbarOptions> configure)
        {
            if (message.IsEmpty())
            {
                return;
            }

            message = message.Trimmed();

            var options = new SnackbarOptions(type, Configuration);

            configure?.Invoke(options);

            var toast = new Snackbar(message, options);

            SnackBarLock.EnterWriteLock();
            try
            {
                if (Configuration.PreventDuplicates && ToastAlreadyPresent(toast))
                {
                    return;
                }
                toast.OnClose += Remove;
                SnackBarList.Add(toast);
            }
            finally
            {
                SnackBarLock.ExitWriteLock();
            }

            OnSnackbarsUpdated?.Invoke();
        }
Пример #3
0
        public void Clear()
        {
            SnackBarLock.EnterWriteLock();
            try
            {
                RemoveAllSnackbars(SnackBarList);
            }
            finally
            {
                SnackBarLock.ExitWriteLock();
            }

            OnSnackbarsUpdated?.Invoke();
        }
Пример #4
0
        public void Remove(Snackbar snackbar)
        {
            snackbar.Dispose();
            snackbar.OnClose -= Remove;

            SnackBarLock.EnterWriteLock();
            try
            {
                var index = SnackBarList.IndexOf(snackbar);
                if (index < 0)
                {
                    return;
                }
                SnackBarList.RemoveAt(index);
            }
            finally
            {
                SnackBarLock.ExitWriteLock();
            }

            OnSnackbarsUpdated?.Invoke();
        }
Пример #5
0
 private void ConfigurationUpdated()
 {
     OnSnackbarsUpdated?.Invoke();
 }