NativeblocksManager
A singleton class responsible for managing the Nativeblocks instance and its various components. The NativeblocksManager is used to initialize, provide blocks, actions, and loggers, and manage the lifecycle, configuration, type converters, frame data, localization, and global parameters of Nativeblocks.
NativeblocksEdition
Enum that defines the available editions for Nativeblocks.
The NativeblocksEdition can either be a cloud configuration or a community-based frame configuration.
-
NativeblocksEdition.cloud(endpoint: String, apiKey: String, developmentMode: Bool):
Cloud-based configuration with an endpoint, API key, and development mode option.- endpoint: The API endpoint for fetching frames/resources.
- apiKey: The API key for authentication.
- developmentMode: Enable development features.
-
NativeblocksEdition.community(frameData: [String: String]):
Community-based configuration using local frame data. The frame data is a dictionary where each key is a route and each value is the corresponding frame URL or path.- frameData: Dictionary of route keys to frame data URLs/paths.
NativeblocksManager
A singleton-class (per name/instance) responsible for managing Nativeblocks SDK configuration and component registration.
Initialization & Instance Management
initialize
Initializes the Nativeblocks framework for a given instance name.
NativeblocksManager.initialize(name: String = "default", edition: NativeblocksEdition) -> NativeblocksManager
- Throws:
errorifnamecontains invalid characters.
getInstance
Gets the shared instance of NativeblocksManager by name (default: "default").
NativeblocksManager.getInstance(name: String = "default") -> NativeblocksManager
- Throws:
errorif not initialized.
isInitialized
Checks if a NativeblocksManager instance has been initialized.
NativeblocksManager.isInitialized(name: String = "default") -> Bool
Wandkit Setup
Wandkit
Configures the Wandkit components for the Nativeblocks manager.
func wandKit(_ wandkit: WandKit...) -> NativeblocksManager
Block Registration
provideBlock
Provides a block for the specified block key type.
func provideBlock(blockKeyType: String, block: @escaping (BlockProps) -> any View) -> NativeblocksManager
provideFallbackBlock
Sets the fallback block to be used when no matching block is registered or available. The fallback block will be displayed in place of unsupported or unrecognized blocks.
func provideFallbackBlock(block: @escaping (String, String) -> any View) -> NativeblocksManager
Action Registration
provideAction
Provides an action for the specified action key type.
func provideAction(actionKeyType: String, action: any INativeAction) -> NativeblocksManager
provideFallbackAction
Sets the fallback action to be used when no matching action is registered. The fallback action will be executed in place of unsupported or unrecognized actions.
func provideFallbackAction(action: @escaping (String, String) -> Void) -> NativeblocksManager
Logger Registration
provideEventLogger
Provides an event logger for the specified logger type.
func provideEventLogger(loggerType: String, logger: any INativeLogger) -> NativeblocksManager
Type Converter Registration & Retrieval
provideTypeConverter
Registers a type converter for a given type.
func provideTypeConverter<T>(_ type: T.Type, converter: INativeType<T>) -> NativeblocksManager
getTypeConverter
Retrieves the type converter for a given type.
func getTypeConverter<T>(_ type: T.Type) -> INativeType<T>
Frame Data Management
getScaffold
Retrieves the scaffold for the frames asynchronously.
func getScaffold() async -> (NativeScaffoldModel?, String?)
syncFrame
Synchronizes the frame for the specified route asynchronously.
func syncFrame(frameRoute: String) async -> NativeblocksManager
clearAllFrames
Clears all frames from the cache.
func clearAllFrames() async -> NativeblocksManager
clearFrame
Clears a specific frame from the cache.
func clearFrame(frameRoute: String) async -> NativeblocksManager
Localization & Global Parameters
setLocalization
Sets the localization language for the Nativeblocks instance.
func setLocalization(languageCode: String) -> NativeblocksManager
setGlobalParameters
Sets global parameters for the Nativeblocks instance.
func setGlobalParameters(_ parameters: (String, String)...) -> NativeblocksManager
func setGlobalParameters(_ parameters: [String: String]) -> NativeblocksManager
Landing & Experiment
getLanding
Retrieves the landing string by the provided landing name.
func getLanding(name: String) async -> (String?, String?)
Returns a tuple containing an optional landing frameRoute on success, or an optional error message on failure.
getExperiment
Fetches an experiment value for the given key with type-safe conversion. The method validates the server-returned variable type against the expected type and returns the default value on any error or type mismatch.
Supported types:
- String: maps to
STRINGorJSONvariable type - Int, Float, Double: map to
NUMBERvariable type - Bool: maps to
BOOLEANvariable type
func getExperiment<T>(key: String, defaultValue: T) async -> T
Cleanup & Destroy
destroy
Destroys the NativeblocksManager instance and releases all associated resources.
func destroy()
NativeblocksFrame
SwiftUI view for rendering a Nativeblocks frame.
struct NativeblocksFrame: View {
var instance: String = "default"
var route: String
var routeArguments: [String: String]
var loading: () -> AnyView
var error: (String) -> AnyView
var body: some View
}
NativeblocksLoading
SwiftUI view for rendering a loading indicator.
struct NativeblocksLoading: View {
var body: some View
}
NativeblocksError
SwiftUI view for rendering error messages.
struct NativeblocksError: View {
let message: String
var body: some View
}
NativeblocksResourceManager
Handles resources such as font families.
provideFontFamily
Registers a custom font family by name.
func provideFontFamily(fontName: String, fontFamily: FontFamily) -> NativeblocksResourceManager
NativeScaffoldModel
Represents the scaffold model for Nativeblocks, containing metadata about frames and their routes.
- frames: List of frame route models (
[NativeFrameRouteModel]).
NativeFrameRouteModel
Represents a frame route model, which defines a specific UI element and its associated metadata.
- id: Unique identifier (
String?) - name: Display name (
String?) - type: Frame type (
FrameTypeModel?) - route: Route path (
String?) - isStarter: Is starter frame (
Bool?) - routeArguments: List of route arguments (
[NativeRouteArgumentsModel]?)
NativeRouteArgumentsModel
Represents an argument for a route.
- name: Argument name (
String?)
FrameTypeModel
Enum of supported frame types:
frame(FRAME)bottomSheet(BOTTOM_SHEET)dialog(DIALOG)