⌘K

Nativeblocks Core

Nativeblocks is a server-driven UI SDK that dynamically generates user interfaces and their associated functionality based on a JSON configuration received from a backend service. This framework enables flexible and dynamic application design without requiring constant app updates.


Key Features

  • Dynamic UI Rendering: Generates user interfaces dynamically based on JSON payloads.
  • Flexible Configuration: Supports multiple editions, including cloud-based and community-based configurations.
  • Actionable Components: Provides seamless integration of actions, events, and triggers.
  • Scalable: Suitable for large-scale applications with modular UI components.

Example Workflow

  1. Initialization: The SDK is initialized with either a cloud or community edition using NativeblocksManager.initialize.
  2. Scaffold Fetching: Frames are registered and scaffold metadata is retrieved.
  3. Rendering: Components such as blocks and actions are dynamically rendered and executed.
  4. Lifecycle Management: Logging, synchronization, and cleanup are handled by the SDK.

Get Started

Ensure your development environment meets the following requirements:

  • Uses Kotlin 1.9.24 or higher
  • Android API level 26 or above

Adding Nativeblocks to Your Project

Add the following dependency to your build.gradle file:

dependencies {
    implementation("io.nativeblocks:nativeblocks-android:1.2.1")
}

Initialize the SDK

Start by initializing the SDK in your main activity or application class.

1. Cloud Edition

Cloud-based configuration with an endpoint, API key, and development mode option.

NativeblocksManager.initialize(
    applicationContext = this,
    edition = NativeblocksEdition.Cloud(
        endpoint = NATIVEBLOCKS_API_URL,
        apiKey = NATIVEBLOCKS_API_KEY,
        developmentMode = true
    )
)

2. Community Edition

Community-based configuration using frame-url. The frame data is a dictionary where each key is a route and each value is the corresponding frame URL.

NativeblocksManager.initialize(
    applicationContext = this,
    edition = NativeblocksEdition.Community(
        framesData = mapOf(
            "/login" to "https://url/login.json",
            "/profile" to "https://url/profile.json"
        )
    )
)

Call the destroy function in the onDestroy method of your activity:

override fun onDestroy() {
    super.onDestroy()
    NativeblocksManager.getInstance().destroy()
}

To initialize the SDK, three parameters are required:

  • API Url: You can get the specific version from the support team.
  • API Key: Once you create a new project in Nativeblocks, you can get the API key from project information.
  • DevelopmentMode: By enabling this option, you can see changes immediately. For production, this should be set to false.

Using NativeblocksFrame

After initialization, configure your activity or fragment to load and manage blocks using NativeblocksFrame.

@Composable
fun ContentView() {
    NativeblocksFrame(
        frameRoute = "/",
        routeArguments = hashMapOf(),
        loading = { NativeblocksLoading() },
        error = { message -> NativeblocksError(message = message) }
    )
}

The core SDK itself does not have any integrations. All integrations need to be registered in the Nativeblocks integration marketplace and provided to the SDK.


Supported Integrations

Block

To provide a custom block, use the following method:

NativeblocksManager.getInstance().provideBlock(
    blockType = "INTEGRATION_UNIQUE_KEY_TYPE",
    block = CustomBlockInstance()
)

Action

To provide a custom action, use the following methods:

NativeblocksManager.getInstance().provideAction(
    actionType = "INTEGRATION_UNIQUE_KEY_TYPE",
    action = CustomActionInstance()
)

NativeblocksManager.getInstance().provideActionContractor(
    actionContractor = CustomActionContractorInstance()
)

Logger

To provide a custom logger, use the following method:

NativeblocksManager.getInstance().provideEventLogger(
    loggerType = "INTEGRATION_UNIQUE_KEY_TYPE",
    logger = CustomLoggerInstance()
)