Example #1
0
    public async void ActionSheetBottom()
    {
        var config = new ActionSheetBottomAsyncConfig
        {
            Title            = "Action Sheet Bottom Async",
            Message          = "Hello world!",
            CancelButtonText = "Cancel"
        };

        config.Items.Add(new ActionSheetItemAsyncConfig {
            Message = "Item 1"
        });
        config.Items.Add(new ActionSheetItemAsyncConfig {
            Message = "Item 2"
        });
        config.Items.Add(new ActionSheetItemAsyncConfig {
            Message = "Item 3"
        });

        var item = await MessagingService.Instance.ActionSheetBottomAsync(config);

        if (item != null)
        {
            MessagingService.Instance.Toast($"Clicked: {item.Message}");
        }
    }
Example #2
0
    /// <summary>
    ///     Display an action sheet dialog from the bottom of the screen asynchronously.
    /// </summary>
    /// <param name="config">The action sheet configuration.</param>
    public Task <ActionSheetItemAsyncConfig> ActionSheetBottomAsync(ActionSheetBottomAsyncConfig config, CancellationToken cancellationToken = default)
    {
        // If available, call the delegate to see if presenting this dialog is allowed.
        if (MessagingServiceCore.Delegate != null && !MessagingServiceCore.Delegate.OnActionSheetBottomRequested(config))
        {
            return(Task.FromResult <ActionSheetItemAsyncConfig>(null));
        }

        var task = new TaskCompletionSource <ActionSheetItemAsyncConfig>();

        // Configure actions to complete the task.
        config.CancelButtonClickAction = () => task.TrySetResult(null);
        config.DismissedAction         = () => task.TrySetResult(null);
        config.ItemClickAction         = (item) => task.TrySetResult(item);

        var dialog = PresentActionSheetBottom(config);

        // Register the disposable of the dialog with the cancellation token, then return the task.
        using (cancellationToken.Register(() => dialog?.Dispose()))
            return(task.Task);
    }