Allow `Shell.Current.DisplayPromptAsync` to be cancelled with a `CancellationTokenSource`
See original GitHub issueDescription
I have a usecase, where a prompt is displayed and an input is required. If the input doesn’t happen in a specified time, the prompt should close and return null
.
Public API Changes
await Shell.Current.DisplayPromptAsync(
"Input Unit",
"Waiting for robo to input the Unit.", x,x,x,
new CancellationTokenSource(TimeSpan.FromSeconds(30))
)
Intended Use-Case
When a CancellationTokenSource
is passed, and it’s cancled (by timeout or whatever), the prompt should be closed and return null or an empty string.
Issue Analytics
- State:
- Created 5 months ago
- Reactions:1
- Comments:6 (2 by maintainers)
Top Results From Across the Web
DisplayPromptAsync Maui Cancel options
As the doc says: "If the Cancel button is tapped, null is returned.". Thus, ResultName.ToString() gives a null exception. Fix: check whether ...
Read more >Task Cancellation
A successful cancellation involves the requesting code calling the CancellationTokenSource.Cancel method and the user delegate terminating ...
Read more >Xamarin.Forms 4.4.0.991537 (4.4.0 Service Release 3) ...
Release notes detailing new features, improvements, and issues fixed in Xamarin.Forms 4.4.0.991537 (4.4.0 Service Release 3)
Read more >Xamarin.Forms 5.0.0.2612
... public Task<string> DisplayPromptAsync(string title, string message, string accept, string cancel, string placeholder, int maxLength, Keyboard keyboard) ...
Read more >Xamarin Forms Loading Popup
Popup: Allows you to create Xamarin. We released the Visual Studio extension for this tool in February and now a new version is...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@rachelkang From what I can see, this should work. However I haven’t tested yet. I’ll do so tomorrow and close the issue if the suggestion works as intended 😃
Thank you @pictos
@AndreasReitberger you can use the new extension method called
.WaitAsync
, that should work.await Shell.Current.DisplayPromptAsync("f", "f").WaitAsync(new CancellationTokenSource(TimeSpan.FromSeconds(30)).Token);