Displaying Widgets
Use the VizcoWidget SwiftUI view to render published widgets in your iOS app.
The VizcoWidget view fetches a published widget by its slug and renders it using the appropriate layout.
Basic usage
import SwiftUI
import VizcoSDK
struct HomeView: View {
var body: some View {
VizcoWidget(slug: "hero-carousel")
}
}The SDK handles fetching the widget configuration, loading images, and rendering the correct layout.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
slug* | String | — | The slug of the published widget to display |
onAssetClick | ((ResolvedAsset) -> Void)? | — | Callback when a user taps an asset |
themeOverrides | WidgetTheme? | — | Override theme properties from the server configuration |
Handling asset taps
VizcoWidget(slug: "product-gallery") { asset in
print("Tapped asset: \(asset.filename)")
}Theme overrides
Override server-defined theme properties locally:
VizcoWidget(
slug: "hero-carousel",
themeOverrides: WidgetTheme(
backgroundColor: "#000000",
borderRadius: 16,
padding: 8
)
)Loading and error states
The widget displays a ProgressView while loading and an error message if the fetch fails. The SDK will show "VizcoSDK not configured" if neither global configuration nor an environment provider has been set up.
Supported layouts
All six layout types render natively in SwiftUI:
| Layout | View |
|---|---|
| CAROUSEL | CarouselView — Paged horizontal scrolling with dots |
| GRID | GridView — Fixed-column grid |
| MASONRY | MasonryView — Staggered grid |
| SLIDER | SliderView — Full-width slider with counter |
| LIST_VERTICAL | ListVerticalView — Vertical scroll list |
| LIST_HORIZONTAL | ListHorizontalView — Horizontal scroll list |