Message Center inbox view
Show the complete Message Center inbox using MessageCenterView for an all-in-one view, MessageCenterContent for custom navigation, or a UIKit view controller.
The inbox view shows the complete Message Center: the message list and, when a message is selected, its content. Choose the view that matches how much control you need over navigation.
MessageCenterViewprovides its own navigation and works on its own.MessageCenterContentprovides only the content, so you supply the navigation.- A UIKit view controller wraps
MessageCenterViewfor UIKit apps.
MessageCenterView
MessageCenterView is a complete Message Center with a built-in navigation stack. Place it anywhere in your SwiftUI hierarchy.
Embed MessageCenterView
import SwiftUI
import AirshipMessageCenter
struct MyMessageCenterScreen: View {
var body: some View {
MessageCenterView()
}
}// Not available in Objective-C. Use a UIKit view controller (see below).The initializer accepts a navigation style and an optional controller:
public init(navigationStyle: NavigationStyle = .auto, controller: MessageCenterController? = nil)Navigation styles
The navigationStyle parameter controls how the list and message panes are arranged:
// Adaptive: split view on iPad, stack on iPhone
MessageCenterView(navigationStyle: .auto)
// Single-column navigation on all devices
MessageCenterView(navigationStyle: .stack)
// Two-column master-detail layout on all devices
MessageCenterView(navigationStyle: .split).auto(default): Uses split view on iPad and stack view on iPhone..stack: Single-column navigation for all devices..split: Two-column master-detail layout for all devices.
Styling and filtering
Apply view modifiers to theme the view, filter messages, or replace the list item and message views:
MessageCenterView()
.messageCenterTheme(theme)
.messageCenterPredicate(CustomPredicate())
.messageCenterItemViewStyle(CustomListItemViewStyle())
.messageCenterMessageViewStyle(CustomMessageViewStyle()).messageCenterTheme(_:)applies a theme..messageCenterPredicate(_:)filters messages in this view only..messageCenterItemViewStyle(_:)replaces the list item view..messageCenterMessageViewStyle(_:)replaces the message view.
MessageCenterContent
For full control over navigation, use MessageCenterContent, which provides the message list without a built-in navigation stack. It requires a MessageCenterController to keep the list and message state in sync.
Drive navigation with the controller’s path, and provide a destination for the message route:
Custom navigation with MessageCenterContent
import SwiftUI
import AirshipMessageCenter
struct MyMessageCenterScreen: View {
@StateObject
private var controller = MessageCenterController()
var body: some View {
NavigationStack(path: $controller.path) {
MessageCenterContent(controller: controller)
.navigationTitle("Messages")
.navigationDestination(for: MessageCenterController.Route.self) { route in
switch route {
case .message(let messageID):
MessageCenterMessageViewWithNavigation(messageID: messageID)
}
}
}
}
}MessageCenterController publishes its navigation state so you can respond to selection changes:
public enum Route: Sendable, Hashable {
case message(String)
}
@Published public var path: [Route]
// Navigate to a message, or pass nil to pop to the list
public func navigate(messageID: String?)To filter the messages shown, pass a predicate to the initializer:
MessageCenterContent(
controller: controller,
predicate: CustomPredicate()
)UIKit
For UIKit apps, create a view controller that hosts the Message Center. The factory returns a standard view controller you can present or push.
UIKit view controller
let viewController = MessageCenterViewControllerFactory.make(
controller: MessageCenterController()
)
navigationController?.pushViewController(viewController, animated: true)UIViewController *viewController = [UAMessageCenterViewControllerFactory make];
[self.navigationController pushViewController:viewController animated:YES];To embed the Message Center inside an existing view controller in Objective-C, use embed(in:), which adds the Message Center as a child and returns a container view:
UIView *messageCenterView = [UAMessageCenterViewControllerFactory embedIn:self];
[self.containerView addSubview:messageCenterView];