userActivity

Advertises a user activity type.

View ModifieriOS 14.0+macOS 11.0+tvOS 14.0+watchOS 7.0+

Overloads

2 ways to call compose().userActivity(). Each is one SwiftUI overload, picked by the arguments you pass.

React
compose().userActivity<P>(
  activityType: string,
  options: {
    element: P | null;
    update: { activityType?: string; title?: string; webpageURL?: string; userInfo?: Record<string, unknown>; isEligibleForHandoff?: boolean; isEligibleForSearch?: boolean; isEligibleForPrediction?: boolean; };
  }
)
Swift
nonisolated func userActivity<P>(
    _ activityType: String,
    element: P?,
    _ update: @escaping (P, NSUserActivity) -> ()
) -> some View

Parameters

  • activityType*string

    The type of activity to advertise.

  • options.element*P | null

    If the element is nil, the handler will not be associated with the activity (and if there are no handlers, no activity is advertised). The method passes the non-nil element to the handler as a convenience so the handlers don't all need to implement an early exit with guard element = element else { return }.

  • options.update*{ activityType?: string; title?: string; webpageURL?: string; userInfo?: Record<string, unknown>; isEligibleForHandoff?: boolean; isEligibleForSearch?: boolean; isEligibleForPrediction?: boolean; }

    A function that modifies the passed-in activity for advertisement.

Discussion

The scope of the activity applies only to the scene or window the view is in.

See also

More in Input and interaction.