public async void ActionSheet() { var config = new ActionSheetAsyncConfig { Title = "Action Sheet 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.ActionSheetAsync(config); if (item != null) { MessagingService.Instance.Toast($"Clicked: {item.Message}"); } }
/// <summary> /// Display an action sheet dialog asynchronously. /// </summary> /// <param name="config">The action sheet configuration.</param> public Task <ActionSheetItemAsyncConfig> ActionSheetAsync(ActionSheetAsyncConfig config, CancellationToken cancellationToken = default) { // If available, call the delegate to see if presenting this dialog is allowed. if (MessagingServiceCore.Delegate != null && !MessagingServiceCore.Delegate.OnActionSheetRequested(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 = PresentActionSheet(config); // Register the disposable of the dialog with the cancellation token, then return the task. using (cancellationToken.Register(() => dialog?.Dispose())) return(task.Task); }