iOS SDK
Open the assistant
Show Cartesian as an adaptive panel, embed it in a tab, or present it from UIKit.
The panel modifier
Attach .cartesianPanel to the screen the assistant should open over, and control it with a CartesianPanelState:
@StateObject private var assistant = CartesianPanelState()
var body: some View {
YourScreen(onAsk: { assistant.open() })
.cartesianPanel(assistant)
}swiftIf you only need a Bool, bind it directly:
@State private var showAssistant = false
ContentView()
.cartesianPanel(isPresented: $showAssistant, prompt: nil)swiftCartesianPanelHost(state) { content } is the same thing as a container view.
Adaptive layouts
With layout: .auto (the default) the panel picks a presentation from the space the modified view gets:
| Space | Layout | Behaviour |
|---|---|---|
| Width < 600pt, height ≥ 480pt (iPhone portrait) | .bottomSheet | A sheet that opens at full height with a 70% detent available. |
| Height < 480pt (iPhone landscape) | .fullScreen | A full-screen cover. |
| 600–1200pt wide (iPad, split view) | .sidePanel | A 440pt panel docked on the right over a dimmed scrim. |
| ≥ 1200pt wide (large iPad landscape) | .floating | A 420×720 card in the bottom-right corner. |
The layout is recomputed when the size changes (rotation, Split View). To force one, pass layout: .bottomSheet and so on. Apply the modifier at screen level so it measures the whole window.
Sheet behaviour
- The sheet opens at
.full. Useopen(detent: .half)to start at 70% height. - At full height, scrolling the conversation never drags the sheet (iOS 16.4+). At half height, dragging resizes the sheet.
- A sheet at half height expands to full when an answer starts or the keyboard appears.
- The grabber is visible; swiping down dismisses.
CartesianPanelState
assistant.open() // full height
assistant.open(prompt: "Gluten-free pasta under $5") // open and send a question
assistant.open(detent: .half)
assistant.expand() // half → full
assistant.hide()
assistant.isVisible // Bool, @Published
assistant.layout // the resolved PanelLayout
assistant.detent // .hidden, .half or .fullswiftReady-made triggers
Ask button
A capsule button with the agent orb. It hides while the panel is open and comes back when it closes.
CartesianAskButton(
state: assistant,
expanded: !scrolled, // collapses to the orb while the shopper scrolls
label: "Ask FreshMart",
icon: nil, // or your own Image
prompt: nil, // or a question to send straight away
containerColor: nil,
contentColor: nil
)swiftPass visible: to combine with your own logic.
Ask bar
A search-style field. What the shopper types is sent as the first question.
CartesianAskBar(state: assistant, placeholder: "Ask about any product")swiftEmbed the chat
CartesianChatView is the full chat screen as a view, for a tab or a navigation destination:
TabView {
HomeView().tabItem { Label("Home", systemImage: "house") }
CartesianChatView().tabItem { Label("Assistant", systemImage: "sparkles") }
}swiftPass onClose: to show a close button in the header.
UIKit
Cartesian.present(from: viewController, prompt: "What's good for a picnic?")swiftThis presents a page sheet with a 70% detent and a large detent, starting at large, and returns the presented controller.