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
@available(iOS 15.0, *)
public class InboxUI: Identifiable, ObservableObject
Public Properties
idUUIDsurfaceSurfaceinboxSchemaDatalistenerisPullToRefreshEnabledBoolfalse.cardSpacingCGFloat16.contentPaddingEdgeInsetsEdgeInsets(top: 12, leading: 16, bottom: 12, trailing: 16).unreadIconSizeCGFloat16.viewsome ViewInitializer
init(surfacelistener:)
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
data-slots=heading, code
data-repeat=1
data-languages=Swift
Swift
public 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
data-slots=heading, code
data-repeat=1
data-languages=Swift
Swift
public func refresh()
Example
data-slots=heading, code
data-repeat=1
data-languages=Swift
Swift
inboxUI.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
data-slots=heading, code
data-repeat=1
data-languages=Swift
Swift
public func setBackground<V: View>(_ view: V)
Example
data-slots=heading, code
data-repeat=1
data-languages=Swift
Swift
inboxUI.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
data-slots=heading, code
data-repeat=1
data-languages=Swift
Swift
public func setLoadingView(_ builder: @escaping () -> AnyView)
Example
data-slots=heading, code
data-repeat=1
data-languages=Swift
Swift
inboxUI.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
data-slots=heading, code
data-repeat=1
data-languages=Swift
Swift
public func setErrorView(_ builder: @escaping (Error) -> AnyView)
Example
data-slots=heading, code
data-repeat=1
data-languages=Swift
Swift
inboxUI.setErrorView { error in
AnyView(
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
data-slots=heading, code
data-repeat=1
data-languages=Swift
Swift
public func setEmptyView(_ builder: @escaping (EmptyStateSettings?) -> AnyView)
Example
data-slots=heading, code
data-repeat=1
data-languages=Swift
Swift
inboxUI.setEmptyView { emptyStateSettings in
AnyView(
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
data-slots=heading, code
data-repeat=1
data-languages=Swift
Swift
public func setHeadingView(_ builder: @escaping (AEPText) -> AnyView)
Example
data-slots=heading, code
data-repeat=1
data-languages=Swift
Swift
inboxUI.setHeadingView { heading in
AnyView(
HStack {
Image(systemName: "tray.fill")
heading.view
.font(.title2)
.fontWeight(.bold)
}
.padding()
)
}