InboxUI
InboxUI is the main class for displaying an Inbox in your application. It manages its own state transitions — loading, loaded, and error — and provides a SwiftUI view that renders content cards using the layout and settings configured in Adobe Journey Optimizer.
Class Definition
Copied to your clipboard@available(iOS 15.0, *)public class InboxUI: Identifiable, ObservableObject
Public Properties
| Property | Type | Description |
|---|---|---|
id | UUID | A unique identifier for this inbox instance. |
surface | Surface | The surface this inbox is bound to. |
state | The current state of the inbox. Published — changes automatically update the view. | |
inboxSchemaData | The inbox schema data, including layout, heading, and empty state settings. Published and read-only. | |
listener | An optional listener to receive inbox state and card interaction events. | |
isPullToRefreshEnabled | Bool | Whether pull-to-refresh is enabled. Default: false. |
cardSpacing | CGFloat | The vertical spacing between content cards. Default: 16. |
contentPadding | EdgeInsets | The padding around the content area. Default: EdgeInsets(top: 12, leading: 16, bottom: 12, trailing: 16). |
unreadIconSize | CGFloat | The size of the unread indicator icon in points. Default: 16. |
view | some View | The SwiftUI view representing the inbox. Use this to embed the inbox in your app's view hierarchy. |
Initializer
init(surface:customizer:listener:)
Creates a new InboxUI instance. Use Messaging.getInboxUI(for:) as the preferred way to create an InboxUI from a surface.
Parameters
- surface - The
Surfacefor which to display the inbox. - customizer - An optional
ContentCardCustomizingobject to customize the appearance of content cards within the inbox. - listener - An optional
InboxEventListeningobject to listen to inbox events.
Syntax
Copied to your clipboardpublic init(surface: Surface,customizer: ContentCardCustomizing? = nil,listener: InboxEventListening? = nil)
Public Methods
refresh()
Programmatically triggers a refresh of inbox content. Calls updatePropositionsForSurfaces followed by getPropositionsForSurfaces for the inbox surface.
Syntax
Copied to your clipboardpublic func refresh()
Example
Copied to your clipboardinboxUI.refresh()
setBackground(_:)
Sets a custom background for the inbox container. Accepts any SwiftUI View — a color, gradient, image, etc.
Parameters
- view - A SwiftUI
Viewto use as the inbox background.
Syntax
Copied to your clipboardpublic func setBackground<V: View>(_ view: V)
Example
Copied to your clipboardinboxUI.setBackground(Color(.systemGroupedBackground))inboxUI.setBackground(LinearGradient(colors: [.blue.opacity(0.1), .purple.opacity(0.05)],startPoint: .top, endPoint: .bottom))
setLoadingView(_:)
Replaces the default loading view with a custom view.
Parameters
- builder - A closure that returns an
AnyViewto display while the inbox is loading.
Syntax
Copied to your clipboardpublic func setLoadingView(_ builder: @escaping () -> AnyView)
Example
Copied to your clipboardinboxUI.setLoadingView {AnyView(VStack {ProgressView()Text("Loading your inbox...")})}
setErrorView(_:)
Replaces the default error view with a custom view.
Parameters
- builder - A closure that receives the
Errorand returns anAnyViewto display when the inbox fails to load.
Syntax
Copied to your clipboardpublic func setErrorView(_ builder: @escaping (Error) -> AnyView)
Example
Copied to your clipboardinboxUI.setErrorView { error inAnyView(VStack {Text("Something went wrong")Text(error.localizedDescription).foregroundColor(.secondary)Button("Try Again") { inboxUI.refresh() }})}
setEmptyView(_:)
Replaces the default empty state view with a custom view.
Parameters
- builder - A closure that receives the optional
EmptyStateSettingsand returns anAnyViewto display when the inbox has no content.
Syntax
Copied to your clipboardpublic func setEmptyView(_ builder: @escaping (EmptyStateSettings?) -> AnyView)
Example
Copied to your clipboardinboxUI.setEmptyView { emptyStateSettings inAnyView(VStack {if let message = emptyStateSettings?.message {message.view} else {Text("No messages")}})}
setHeadingView(_:)
Replaces the default heading view with a custom view.
Parameters
- builder - A closure that receives the
AEPTextheading configured in Adobe Journey Optimizer and returns anAnyView.
Syntax
Copied to your clipboardpublic func setHeadingView(_ builder: @escaping (AEPText) -> AnyView)
Example
Copied to your clipboardinboxUI.setHeadingView { heading inAnyView(HStack {Image(systemName: "tray.fill")heading.view.font(.title2).fontWeight(.bold)}.padding())}
