Kotlin + Compose SDK
Nativeblocks supports Kotlin and Compose, for SDUI and SDA
Get started
Install or update Android Studio to its latest version
Make sure that your project meets these requirements:
- Uses Android API level 26 or higher
- Uses Jetpack (AndroidX)
Adding Nativeblocks to Your Project
Root gradle
repositories {
mavenCentral()
}
Module gradle
dependencies {
implementation ("io.nativeblocks:nativeblocks-android:1.2.1")
}
Let's get started by initializing the SDK, it can be inside of the onCreate's Activity or provide via dependency injection
NativeblocksManager.initialize(
applicationContext = this,
edition = NativeblocksEdition.Cloud(
endpoint = NATIVEBLOCKS_API_URL,
apiKey = NATIVEBLOCKS_API_KEY,
developmentMode = true
)
)
And call destroy function on Activity's onDestroy
override fun onDestroy() {
super.onDestroy()
NativeblocksManager.getInstance().destroy()
}
To initialize the SDK three parameters needed:
- AndroidContext (we recommend to initialize SDK in an Android Activity)
- API Url (you can get specific version from support team)
- API Key (Once you created a new project in the Nativeblocks, you can get the API key from project information)
- DevelopmentMode (by enabling this option you can see the changes immediately, but for the production usage, this should be false)
And in setContent of the Activity use NativeblocksProvider
setContent {
NativeblocksFrame(
frameRoute = "/",
loading = {
NativeblocksLoading()
},
error = { message ->
NativeblocksError(message)
},
)
}
ResourceManager
With the helps of NativeblocksResourceManager, provide font family, by default the SDK is using android default font, if you wish to use custom font here is the instruction for example:
private val font = FontFamily(
Font(R.font.inter_regular),
Font(R.font.inter_medium),
Font(R.font.inter_semibold),
Font(R.font.inter_bold)
)
NativeblocksResourceManager.provideFontFamily("inter", font)
The core SDK by itself does not have any integrations, All integrations need to register on the Nativeblocks integration marketplace and provide to the SDK,
Current version of SDK supports following integration
- Block
- Action & ActionContractor
- Logger
Here is the Nativeblocks API how you can connect your integration with it.
Block
NativeblocksManager.getInstance().provideBlock(
blockType = "INTEGRATION_UNIQUE_KEY_TYPE",
block = CustomBlockInstance()
)
Action
NativeblocksManager.getInstance().provideAction(
actionType = "INTEGRATION_UNIQUE_KEY_TYPE",
action = CustomActionInstance()
)
NativeblocksManager.getInstance().provideActionContractor(
actionContractor = CustomActionContractorInstance()
)
Logger
NativeblocksManager.getInstance().provideLogger(
loggerType = "INTEGRATION_UNIQUE_KEY_TYPE",
logger = CustomLoggerInstance()
)