Xamarin.forms: [Bug] DisplayAlert should be DisplayAlertAsync

Created on 11 Oct 2019  Â·  4Comments  Â·  Source: xamarin/Xamarin.Forms

Current code for DisplayAlert doesn't follow the language best practices.
Here's an example:
public Task DisplayAlert(string title, string message, string accept, string cancel)
{
if (string.IsNullOrEmpty(cancel))
throw new ArgumentNullException("cancel");

        var args = new AlertArguments(title, message, accept, cancel);
        if (IsPlatformEnabled)
            MessagingCenter.Send(this, AlertSignalName, args);
        else
            _pendingActions.Add(() => MessagingCenter.Send(this, AlertSignalName, args));

        return args.Result.Task;
    }

Asynchronous methods should be trailed with Async.

proposal-open unverified enhancement âž•

Most helpful comment

I'm in favor of making existing methods obsolete and providing the new names, but this reminded me of an old request I made: https://github.com/xamarin/Xamarin.Forms/issues/2941

All 4 comments

You are correct that the name probably should have been DisplayAlertAsync. But the method is part of the public API; renaming it would be a breaking change. So I'm afraid we're stuck with DisplayAlert for the time being.

I'm in favor of making existing methods obsolete and providing the new names, but this reminded me of an old request I made: https://github.com/xamarin/Xamarin.Forms/issues/2941

That's one option. The catch is that we'd look like we were following the pattern of "async methods have the async suffix and synchronous methods don't have a suffix"; but the method that _looks_ synchronous (DisplayAlert) is actually async. Which would also surprise new users.

Maybe at some point in the future we'll have an opportunity to make a clean break or a whole new alert/dialog API, at which point we can better align our names with the conventions.

It should not use a bug tag.

Was this page helpful?
0 / 5 - 0 ratings