Esempio n. 1
0
        private async Task OnCustomClickHanlder(MouseEventArgs args)
        {
            if (Disabled || !OnCustomClick.HasDelegate)
            {
                return;
            }

            // Handle unintentional double clicks
            if (PreviousClick != null && DateTime.Now.Subtract(PreviousClick.Value).TotalMilliseconds <= ClickFilterMilliSeconds)
            {
                return;
            }

            Disabled = true;

            try
            {
                if (IsCallbackType(OnCustomClick, typeof(Func <Task>)))
                {
                    await OnCustomClick.InvokeAsync();
                }
                else if (IsCallbackType(OnCustomClick, typeof(Action)))
                {
                    // Trigger blazor page update lifecycle ...
                    await Task.Delay(50);

                    await OnCustomClick.InvokeAsync();
                }
                else if (IsCallbackType(OnCustomClick, typeof(Func <MouseEventArgs, Task>)))
                {
                    await OnCustomClick.InvokeAsync(args);
                }
                else if (IsCallbackType(OnCustomClick, typeof(Action <MouseEventArgs>)))
                {
                    // Trigger blazor page update lifecycle ...
                    await Task.Delay(50);

                    await OnCustomClick.InvokeAsync(args);
                }
                else
                {
                    throw new NotSupportedException();
                }
            }
            finally
            {
                if (!(IsDisposed || IsLocationChanged))
                {
                    Disabled = false;
                }
                PreviousClick = DateTime.Now;
            }
        }
Esempio n. 2
0
        protected virtual async Task CustomOnClickHandler(MouseEventArgs args)
        {
            if (Disabled || !OnCustomClick.HasDelegate)
            {
                return;
            }

            Disabled = true;

            try
            {
                await OnCustomClick.InvokeAsync(args);
            }
            finally
            {
                Disabled = false;
            }
        }
Esempio n. 3
0
        protected override async Task CustomOnClickHandler(MouseEventArgs args)
        {
            if (Disabled || !OnCustomClick.HasDelegate)
            {
                return;
            }

            Disabled = true;

            try
            {
                // Trigger Blazor lifecycle methods ...
                // While this statement is by itself not harmful, it may cause the Blazor screen updates to be not as the
                // developer expects, see this example:
                // https://github.com/akovac35/TestingBlazor/blob/59d43141cd9909b93ddf6507d7acc882dbca1423/Pages/LoadingIndicator.razor.cs#L95
                await Task.Delay(50);

                await OnCustomClick.InvokeAsync(args);
            }
            finally
            {
                Disabled = false;
            }
        }