Skip to content

Instantly share code, notes, and snippets.

@khanlou
Last active Aug 1, 2020
Embed
What would you like to do?

This is designed to look like sheet(item:content:):

func sheet<Item, Content>(item: Binding<Item?>, content: @escaping (Item) -> Content) -> some View

But for pushing views instead of presenting them as sheets.

To use it, create a @State variable for your selected item:

@State var selectedPerson: Person?

Then, chain at the end of your view:

    .pushView(item: $selectedPerson) { person in
        PersonDetail(person: person)
    }

If you need mutation, your Item type should probably be some kind of ID or index with which to fetch the item, otherwise you will end up with stale data.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment