Skip to main content

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.

note

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) or lcx-eu.bambuser.com (EU)
  • Info.plist keys (required for the call flow after the shopper taps the pin — the pin itself needs no permissions):
    • NSCameraUsageDescription
    • NSMicrophoneUsageDescription
  • For .bambuserWidget mode: OLW variants configured on your BamHub theme.
  • For .custom mode: image assets in Assets.xcassets and/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. nil uses whichever variant the merchant selected in BamHub (the "smart" default).
  • popupTimeoutSeconds: TimeInterval? — seconds to wait before the OLW appears. nil uses 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 + .imageWithText card frames and scales the .avatar inner 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):

PresetDimensionsAvatar circle
.small80 × 12030 pt
.medium (default)108 × 16038 pt
.large134 × 20048 pt
.custom(width:, height:)your valuesmin(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(_:).

note

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).

Observing state​

BambuserPinWidgetState:

  • .idle — created, present() not yet called
  • .overlayWidget — pin visible
  • .overlayWidgetMaximised — widget's expanded OLW filling the screen (.bambuserWidget mode)
  • .pendingCall — shopper tapped, adapter is about to hand off
  • .dismissed — pin surface torn down

Two ways to observe:

// SwiftUI
Text("Pin: \(String(describing: pin.state))") // @Published

// UIKit / anywhere
class MyDelegate: BambuserPinWidgetDelegate {
func pinWidget(_ pin: BambuserPinWidget, didChangeState from: BambuserPinWidgetState, to next: BambuserPinWidgetState) { … }
func pinWidgetDidRequestOpenCall(_ pin: BambuserPinWidget) { … }
func pinWidgetDidDismiss(_ pin: BambuserPinWidget) { … }
}
pin.delegate = myDelegate

All delegate methods have no-op defaults — implement only what you care about.

Wiring to the call — the adapter​

BambuserPinWidgetCallAdapter is a small glue class that observes both the pin and a BambuserCallController and handles the transitions:

  • Pin fires pinWidgetDidRequestOpenCall (shopper tapped) → adapter calls pin.dismiss() then call.show().
  • A call opened any other way (e.g. a "Talk to expert" button) → adapter dismisses a visible pin so only one WebView is alive.
  • Call ends (call.isVisible flips false) → adapter calls pin.present() again if the pin was showing before the call (unless representAfterCallEnds is false).
let adapter = BambuserPinWidgetCallAdapter(
pin: pin,
call: bambuserCall,
representAfterCallEnds: true // default
)

The adapter keeps weak references to both, so it doesn't extend their lifetime. Retain the adapter in your host (a @State or a stored property).

Custom wiring (no adapter)​

If you want full control of the handoff:

pin.delegate = self
// …
func pinWidgetDidRequestOpenCall(_ pin: BambuserPinWidget) {
pin.dismiss()
bambuserCall.show()
}

You're then responsible for calling pin.present() again after the call ends (subscribe to bambuserCall.$isVisible).

FAQ​

Do I have to use the adapter? No. It's a convenience; you can implement BambuserPinWidgetDelegate yourself and do whatever the pin → call transition should look like in your app.

Can I run more than one pin at a time? Yes — nothing in the SDK stops you from creating multiple BambuserPinWidget instances. Each owns its own WebView (in .bambuserWidget mode) so RAM cost is real; use with care.

What happens if I present() while the pin is already presenting? No-op. present() guards on state == .idle || .dismissed.

How is this different from BambuserCallOverlay's .native(...) mode? BambuserCallOverlay.overlayMode = .native(...) shows a companion SwiftUI overlay tied to the same BambuserCallController that hosts the full call. BambuserPinWidget is fully independent — has its own state machine, its own WebView (or none, in .custom mode), and hands off via a delegate. Use the pin for shopper-invited call flows; use the older overlay mode for host-driven prompts embedded in specific screens.