Pin Widget
BambuserPinWidget is a persistent floating pin that sits on top of your app and, on tap, opens the full Calls Widget. It renders either the Bambuser widget's own Overlay Widget (OLW) inside a WKWebView — driven by your BamHub theme — or a custom SwiftUI card with host-provided image / video + text.
The pin is fully independent of BambuserCallController. Both can be mounted separately, or wired together via BambuserPinWidgetCallAdapter which handles the pin → call handoff for you.
Only one WebView is alive at a time. When the shopper taps the pin, the adapter destroys the pin's WebView before creating the call's, and re-creates the pin's WebView when the call ends.
Two rendering modes
BambuserPinWidgetConfiguration.content picks between:
.bambuserWidget(...)— the Bambuser widget's own OLW rendered inside a WebView. Content (avatar image, text, video URL, colours) comes from your BamHub theme. No local assets needed..custom(...)— a fully-native SwiftUI card with host-provided content. No WebView. Three variants:.avatar,.video,.imageWithText.
Requirements
- iOS 16+
- Swift 5.9 / Xcode 15+
- A Bambuser workspace on
lcx.bambuser.com(US) orlcx-eu.bambuser.com(EU) Info.plistkeys (required for the call flow after the shopper taps the pin — the pin itself needs no permissions):NSCameraUsageDescriptionNSMicrophoneUsageDescription
- For
.bambuserWidgetmode: OLW variants configured on your BamHub theme. - For
.custommode: image assets inAssets.xcassetsand/or an mp4 in the app bundle for the variant you pick.
Setup — .bambuserWidget mode
BamHub theme drives every pixel; you supply only the trigger + variant hint.
import SwiftUI
import BambuserCallsShopper
struct RootView: View {
@StateObject private var bambuserCall = BambuserCallController(
configuration: BambuserCallConfiguration(orgId: "YOUR_ORG_ID", environment: .us)
)
@StateObject private var pin = BambuserPinWidget(
configuration: BambuserPinWidgetConfiguration(
orgId: "YOUR_ORG_ID",
environment: .us,
content: .bambuserWidget(
BambuserPinWidgetBambuserOptions(
variantOverride: .sideDock, // .avatar / .sideDock / .video / nil
popupTimeoutSeconds: 5 // nil → merchant's BamHub default
)
)
)
)
@State private var adapter: BambuserPinWidgetCallAdapter?
var body: some View {
ZStack {
YourAppContent()
BambuserCallOverlay(controller: bambuserCall)
.ignoresSafeArea(edges: .bottom)
BambuserPinWidgetView(pin: pin)
}
.onAppear {
if adapter == nil {
adapter = BambuserPinWidgetCallAdapter(pin: pin, call: bambuserCall)
}
pin.present()
}
}
}
Drop BambuserPinWidgetView(pin: pin) at the root of your view tree so the pin follows the shopper across every screen. The adapter handles pin → call → back-to-pin automatically.
When to pick this mode: you want marketing / content to iterate on the pin's copy, avatar, colours, and OLW variant from BamHub without shipping a new app build. The Bambuser widget renders in a small transparent WKWebView pinned to the bottom-right of the screen.
Options (BambuserPinWidgetBambuserOptions):
variantOverride: BambuserPinWidgetVariant?—.avatar/.sideDock/.video/nil.niluses whichever variant the merchant selected in BamHub (the "smart" default).popupTimeoutSeconds: TimeInterval?— seconds to wait before the OLW appears.niluses the merchant's BamHub value (typically 60).
Setup — .custom mode
Fully-native SwiftUI card. No WebView is created for the pin — only the host-provided content renders, until the shopper taps and the adapter mounts the call WebView.
Prep the asset. For the .video variant, drag your looping mp4 into the app target (Copy items if needed, target membership on). For .image variants, add the image to Assets.xcassets.
import SwiftUI
import BambuserCallsShopper
struct RootView: View {
@StateObject private var bambuserCall = BambuserCallController(
configuration: BambuserCallConfiguration(orgId: "YOUR_ORG_ID", environment: .us)
)
@StateObject private var pin = BambuserPinWidget(
configuration: BambuserPinWidgetConfiguration(
orgId: "YOUR_ORG_ID",
environment: .us,
content: .custom(
BambuserPinWidgetCustomOptions(
variant: .video(
url: Bundle.main.url(forResource: "welcome", withExtension: "mp4")!,
title: "Meet our experts",
ctaTitle: "Start a call"
),
size: .medium, // .small / .medium / .large / .custom
popupTimeoutSeconds: 5,
position: .bottomTrailing,
padding: EdgeInsets(top: 0, leading: 0, bottom: 90, trailing: 16),
isDismissible: true
)
)
)
)
@State private var adapter: BambuserPinWidgetCallAdapter?
var body: some View {
ZStack {
YourAppContent()
BambuserCallOverlay(controller: bambuserCall)
.ignoresSafeArea(edges: .bottom)
BambuserPinWidgetView(pin: pin)
}
.onAppear {
if adapter == nil {
adapter = BambuserPinWidgetCallAdapter(pin: pin, call: bambuserCall)
}
pin.present()
}
}
}
Swap the .video(...) variant for any of the other two:
// Avatar variant — SF Symbol or your own bundled image
variant: .avatar(
image: Image(systemName: "person.crop.circle.badge.checkmark"),
title: "Hi there!",
subtitle: "Need help finding something?"
)
// Image + text variant — asset catalog image on top of a card
variant: .imageWithText(
image: Image("concierge"), // in Assets.xcassets
title: "Chat with an expert",
subtitle: "Live styling, one tap away.",
ctaTitle: "Talk now"
)
When to pick this mode: pixel-perfect brand control over the pin's appearance, ability to ship content in the app bundle (mp4 / image / string), and no dependency on the widget's OLW rendering path.
Options (BambuserPinWidgetCustomOptions):
variant: BambuserPinWidgetCustomVariant— required. See variants below.size: BambuserPinWidgetSize—.small(80×120),.medium(108×160, default),.large(134×200), or.custom(width:height:). Applies to.video+.imageWithTextcard frames and scales the.avatarinner circle.popupTimeoutSeconds: TimeInterval— seconds to wait before animating in.0= immediate.position: BambuserPinWidgetAnchor—.bottomLeading/.bottomTrailing.padding: EdgeInsets— pull the pin away from the anchor edges (e.g. clear a bottom tab bar).isDismissible: Bool— show an×the shopper can tap to hide the pin for the rest of the session.hideWhenNoAgentsOnline: Bool— reserved; wire your own check via delegate for now.
Available variants (BambuserPinWidgetCustomVariant):
.avatar(image, title, subtitle)— circular avatar + compact text bubble. Best for concierge / clienteling UX..video(url, title, ctaTitle)— edge-to-edge looping muted mp4 with a bottom gradient scrim carrying the title + CTA. Best when motion is the hook..imageWithText(image, title, subtitle, ctaTitle)— static image on top, text + CTA below. Best when you want a simple still.
Every custom variant is draggable (SwiftUI DragGesture, soft-clamped inside the visible area) and animates in after popupTimeoutSeconds.
Size presets
BambuserPinWidgetSize (used by .custom mode):
| Preset | Dimensions | Avatar circle |
|---|---|---|
.small | 80 × 120 | 30 pt |
.medium (default) | 108 × 160 | 38 pt |
.large | 134 × 200 | 48 pt |
.custom(width:, height:) | your values | min(w, h) |
Applies to the .video and .imageWithText card frames, and scales the .avatar variant's inner circle.
UIKit apps
Mount the pin on its own passthrough window with BambuserPinWidgetWindowPresenter — the same pattern as BambuserCallWindowPresenter for the call. Both content modes work; touches outside the pin fall through to your app.
// SceneDelegate
let callPresenter = BambuserCallWindowPresenter(controller: bambuserCall)
callPresenter.attach(to: windowScene)
let pinPresenter = BambuserPinWidgetWindowPresenter(pin: pin)
pinPresenter.attach(to: windowScene)
pinAdapter = BambuserPinWidgetCallAdapter(pin: pin, call: bambuserCall)
pin.present()
Keep strong references to both presenters and the adapter (e.g. stored properties on the scene delegate).
Call pinPresenter.detach() (and callPresenter.detach()) in sceneDidDisconnect(_:).
The pin and call windows become the key window when the shopper touches them, so the WebView receives taps and drags. If your app reads UIWindow.isKeyWindow or the scene's key window, expect it to point at an SDK window right after the shopper interacts with the pin or the call.
Lifecycle
pin.present() // create the pin surface, transition state to .overlayWidget after popupTimeoutSeconds
pin.dismiss() // tear the pin down; state → .dismissed
Both are idempotent. pin.present() after a previous dismiss() spins up a fresh instance (new WebView in .bambuserWidget mode, fresh Task in .custom mode).