Skip to content

fabulous-dev/Fabulous.XamarinForms.SaveState

Repository files navigation

Fabulous.XamarinForms.SaveState

build NuGet version NuGet downloads Discord Twitter Follow

Add the save state feature to your Fabulous.XamarinForms app.
This package will automatically save the current state of your app when it is suspended and restore it when it is resumed.

How to use

  1. Add the Fabulous.XamarinForms.SaveState package to your project

  2. Open Fabulous.XamarinForms.SaveState at the top of the file where you declare your Fabulous program (eg. Program.stateful).

open Fabulous.XamarinForms.SaveState
  1. Add an additional Msg case to your app to handle the state save failure.
type Msg =
    | StateSaveFailure of exn // This one will be called if the serialization fails
    | ... // Other messages
  1. After the declaration of your Fabulous program, add the withSaveState function.
    (This example uses Newtonsoft.Json to serialize and deserialize the app state)
let encodeAppState (model: Model): string = JsonConvert.SerializeObject(model)
let decodeAppState (encodedState: string): Model = JsonConvert.DeserializeObject<Model>(encodedState)

let program =
    Program.stateful init update view
    |> Program.withSaveState encodeAppState decodeAppState StateSaveFailure

Supporting Fabulous

The simplest way to show us your support is by giving this project and the Fabulous project a star.

You can also support us by becoming our sponsor on the GitHub Sponsors program.
This is a fantastic way to support all the efforts going into making Fabulous the best declarative UI framework for dotnet.

If you need support see Commercial Support section below.

Contributing

Have you found a bug or have a suggestion of how to enhance Fabulous? Open an issue and we will take a look at it as soon as possible.

Do you want to contribute with a PR? PRs are always welcome, just make sure to create it from the correct branch (main) and follow the Contributor Guide.

For bigger changes, or if in doubt, make sure to talk about your contribution to the team. Either via an issue, GitHub discussion, or reach out to the team either using the Discord server.