SuggestedActionsView
A view that displays suggested actions for a message.
Declaration
@MainActor struct SuggestedActionsViewOverview
The suggested actions view displays inline actions for a messaging app, next to a message, using context you provide. This view animates suggested actions as they become available. If no suggested actions are available, the view’s size is zero and remains zero until they become available. At size zero, a SuggestedActionsView doesn’t affect your surrounding layout. As a result, place the view for every message in a conversation. It doesn’t introduce gaps between messages if a message doesn’t have suggested actions.
Customize the appearance
To customize a SuggestedActionsView, apply standard SwiftUI view modifiers to change its appearance. Additionally, the view reads the following modifiers from its parent views:
Generate suggested actions for future use
To avoid showing a loading state when the view appears, call generate(message:previousMessages:) to let the Suggested Actions framework create suggested actions and cache them for future use. When you later initialize a SuggestedActionsView, the framework checks the id of cached suggested actions based on their messages’ id property. If it finds an id that matches the id of a new SuggestedActionsMessage, the system uses the already generated suggested action.
The following example shows how an app might show a SuggestedActionsView with information about previous messages using a capsule border shape, blue tint, and the callout font style:
SuggestedActionsView(
message: message.suggestedActionsMessage,
previousMessages: message.previousMessages
.suffix(SuggestedActionsMessage.previousMessagesLimit)
.map(\.suggestedActionsMessage)
)
.buttonBorderShape(.capsule)
.tint(.blue)
.font(.callout)