Contents

familyActivityPicker(title:headerText:footerText:isPresented:selection:)

Present an activity picker sheet for selecting apps and websites to manage.

Declaration

@MainActor @preconcurrency func familyActivityPicker(title: String?, headerText: String? = nil, footerText: String? = nil, isPresented: Binding<Bool>, selection: Binding<FamilyActivitySelection>) -> some View

Parameters

  • title:

    An optional string that provides a title for the picker view.

  • headerText:

    An optional string that provides text for the header of the picker view.

  • footerText:

    An optional string that provides text for the footer of the picker view.

  • isPresented:

    A binding that indicates whether the app presents the picker view.

  • selection:

    A binding that manages the selected categories, apps, and web domains.

Discussion

Use this view modifier to present a FamilyControls/FamilyActivityPicker with a custom title.

struct ContentView: View {
    @State private var selection = FamilyActivitySelection()
    @State private var isPresented = false

    var body: some View {
        Button("Select Activities") {
            isPresented = true
        }
        .familyActivityPicker(
            title: "Choose Apps to Limit",
            headerText: "Select apps and websites to manage",
            footerText: "These selections will be used for screen time limits",
            isPresented: $isPresented,
            selection: $selection
        )
        .onChange(of: selection) { newSelection in
            // Handle the selected activities
            print("Selected \(newSelection.applications.count) apps")
        }
    }
}