Fabulous
API Reference
1.0
1.0
  • Fabulous 1.0
  • Get Started
  • Samples & Tutorials
    • Samples
    • Videos
  • Basics
    • MVU
    • Application state
      • Commands
      • State validation
    • User interface
      • Animations
    • Testing
    • Error monitoring
  • Advanced
    • Saving and Restoring app state
    • Performance optimization
  • Architecture
  • Xamarin.Forms
    • Get Started
    • User interface
      • Custom controls
      • Effects
      • Navigation
      • Pop-ups
    • Extensions
      • FFImageLoading
      • OxyPlot
      • SkiaSharp
      • VideoManager
      • Xamarin.Forms.Maps
Powered by GitBook
On this page
Edit on GitHub
  1. Xamarin.Forms
  2. User interface

Pop-ups

PreviousNavigationNextExtensions

Last updated 1 year ago

Pop-ups are a special case in Fabulous for Xamarin.Forms: they are part of the view, but don’t follow the same lifecycle as the rest of the UI. In Xamarin.Forms pop-ups are exposed through 2 methods of the current page: DisplayAlert and DisplayActionSheet.

In Fabulous for Xamarin.Forms we only describe what a page should look like and have no access to UI elements. As such, there is no direct implementation of those 2 methods in Fabulous but instead we can use the static property Application.Current.MainPage exposed by Xamarin.Forms.

Here is an example of the use of a confirmation pop-up - note the requirement of Cmd.AsyncMsg so as not to block on the UI thread:

type Msg =
    | DisplayAlert
    | AlertResult of bool

let update (msg : Msg) (model : Model) =
    match msg with
    | DisplayAlert ->
        let alertResult = async {
            let! alert =
                Application.Current.MainPage.DisplayAlert("Display Alert", "Confirm", "Ok", "Cancel")
                |> Async.AwaitTask
            return AlertResult alert }

        model, Cmd.ofAsyncMsg alertResult

    | AlertResult alertResult -> ... // Do something with the result

Why don’t we add a Fabulous wrapper for those? Doing so would only end up duplicating the existing methods and compel us to maintain these in sync with Xamarin.Forms. See for more information

Pull Request #147