From ac87f0b8c6823d4cd46f0361ce77fcddaa56753d Mon Sep 17 00:00:00 2001 From: RyosukeCla Date: Tue, 2 Apr 2024 17:32:06 +0900 Subject: [PATCH 1/7] [android] Fix issue with empty key in variableByPath function --- .../src/main/java/com/nativebrik/sdk/template/template.kt | 1 + 1 file changed, 1 insertion(+) diff --git a/android/nativebrik/src/main/java/com/nativebrik/sdk/template/template.kt b/android/nativebrik/src/main/java/com/nativebrik/sdk/template/template.kt index f3c00fd..2f15bd1 100644 --- a/android/nativebrik/src/main/java/com/nativebrik/sdk/template/template.kt +++ b/android/nativebrik/src/main/java/com/nativebrik/sdk/template/template.kt @@ -38,6 +38,7 @@ fun variableByPath(path: String, variable: JsonElement?): JsonElement? { if (keys.isEmpty()) return null var current = variable keys.forEach { key -> + if (key.isEmpty()) return@forEach if (key == "$") { current = variable } else { From bb035243590293e10b99e754e3c9bee4f0606a3a Mon Sep 17 00:00:00 2001 From: RyosukeCla Date: Tue, 2 Apr 2024 17:32:22 +0900 Subject: [PATCH 2/7] [android] Refactor image loading logic in Image function --- .../main/java/com/nativebrik/sdk/component/renderer/image.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/android/nativebrik/src/main/java/com/nativebrik/sdk/component/renderer/image.kt b/android/nativebrik/src/main/java/com/nativebrik/sdk/component/renderer/image.kt index bb92fe6..efd709f 100644 --- a/android/nativebrik/src/main/java/com/nativebrik/sdk/component/renderer/image.kt +++ b/android/nativebrik/src/main/java/com/nativebrik/sdk/component/renderer/image.kt @@ -71,7 +71,7 @@ internal fun Image(block: UIImageBlock, modifier: Modifier = Modifier) { AsyncImage( modifier = modifier, model = ImageRequest.Builder(LocalContext.current) - .data(block.data?.src ?: "https://example.com/image.jpg",) + .data(src) .crossfade(true) .build(), contentDescription = null, From 4c6c44dee12cee68e257ab784378a6ee77813dde Mon Sep 17 00:00:00 2001 From: RyosukeCla Date: Tue, 2 Apr 2024 17:32:33 +0900 Subject: [PATCH 3/7] [android] Fix variable declaration in Carousel function --- .../main/java/com/nativebrik/sdk/component/renderer/carousel.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/android/nativebrik/src/main/java/com/nativebrik/sdk/component/renderer/carousel.kt b/android/nativebrik/src/main/java/com/nativebrik/sdk/component/renderer/carousel.kt index f1e7ee3..ae4b416 100644 --- a/android/nativebrik/src/main/java/com/nativebrik/sdk/component/renderer/carousel.kt +++ b/android/nativebrik/src/main/java/com/nativebrik/sdk/component/renderer/carousel.kt @@ -29,7 +29,7 @@ internal fun Carousel(block: UICollectionBlock, modifier: Modifier = Modifier) { var children = block.data?.children ?: emptyList() var arrayData: JsonArray? = null if (reference != null) { - var data = variableByPath(reference, dataState.data) + val data = variableByPath(reference, dataState.data) if (data is JsonArray && children.isNotEmpty()) { arrayData = data.jsonArray children = arrayData.map { children[0] } From bf462406018ac56a5c425159ad7a3641fcca2c87 Mon Sep 17 00:00:00 2001 From: RyosukeCla Date: Tue, 2 Apr 2024 17:33:01 +0900 Subject: [PATCH 4/7] [android] support data reference for grid --- .../nativebrik/sdk/component/renderer/grid.kt | 28 ++++++++++++++++--- 1 file changed, 24 insertions(+), 4 deletions(-) diff --git a/android/nativebrik/src/main/java/com/nativebrik/sdk/component/renderer/grid.kt b/android/nativebrik/src/main/java/com/nativebrik/sdk/component/renderer/grid.kt index 3d29812..2a556b1 100644 --- a/android/nativebrik/src/main/java/com/nativebrik/sdk/component/renderer/grid.kt +++ b/android/nativebrik/src/main/java/com/nativebrik/sdk/component/renderer/grid.kt @@ -13,12 +13,16 @@ import androidx.compose.runtime.Composable import androidx.compose.ui.Modifier import androidx.compose.ui.unit.DpSize import androidx.compose.ui.unit.dp +import com.nativebrik.sdk.component.provider.data.DataContext +import com.nativebrik.sdk.component.provider.data.NestedDataProvider import com.nativebrik.sdk.schema.FlexDirection import com.nativebrik.sdk.schema.UICollectionBlock +import com.nativebrik.sdk.template.variableByPath +import kotlinx.serialization.json.JsonArray +import kotlinx.serialization.json.jsonArray @Composable internal fun Grid(block: UICollectionBlock, modifier: Modifier = Modifier) { - val children = block.data?.children ?: emptyList() val state = rememberLazyGridState(0, 0) val padding = parseFramePadding(block.data?.frame) val gridSize = block.data?.gridSize ?: 1 @@ -27,7 +31,19 @@ internal fun Grid(block: UICollectionBlock, modifier: Modifier = Modifier) { val size = DpSize((block.data?.itemWidth ?: 0).dp, (block.data?.itemHeight ?: 0).dp) val gridHeight = (block.data?.frame?.paddingTop ?: 0) + (block.data?.frame?.paddingBottom ?: 0) + (gridSize - 1) * (block.data?.gap ?: 0) + (gridSize * (block.data?.itemHeight ?: 0)) val gridWidth = (block.data?.frame?.paddingLeft ?: 0) + (block.data?.frame?.paddingRight ?: 0) + (gridSize - 1) * (block.data?.gap ?: 0) + (gridSize * (block.data?.itemWidth ?: 0)) - + + val dataState = DataContext.state + val reference = block.data?.reference + var children = block.data?.children ?: emptyList() + var arrayData: JsonArray? = null + if (reference != null) { + val data = variableByPath(reference, dataState.data) + if (data is JsonArray && children.isNotEmpty()) { + arrayData = data.jsonArray + children = arrayData.map { children[0] } + } + } + if (direction == FlexDirection.ROW) { LazyHorizontalGrid( contentPadding = padding, @@ -39,7 +55,9 @@ internal fun Grid(block: UICollectionBlock, modifier: Modifier = Modifier) { ) { items(children.size) { Box(Modifier.size(size)) { - Block(block = children[it]) + NestedDataProvider(data = if (arrayData != null) arrayData[it] else dataState.data) { + Block(block = children[it]) + } } } } @@ -54,7 +72,9 @@ internal fun Grid(block: UICollectionBlock, modifier: Modifier = Modifier) { ) { items(children.size) { Box(Modifier.size(size)) { - Block(block = children[it]) + NestedDataProvider(data = if (arrayData != null) arrayData[it] else dataState.data) { + Block(block = children[it]) + } } } } From 8461bfbda170541232e1d9b049610634747bd7c3 Mon Sep 17 00:00:00 2001 From: RyosukeCla Date: Tue, 2 Apr 2024 17:33:45 +0900 Subject: [PATCH 5/7] [android] trigger event when event.name is not empty --- .../nativebrik/src/main/java/com/nativebrik/sdk/sdk.kt | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/android/nativebrik/src/main/java/com/nativebrik/sdk/sdk.kt b/android/nativebrik/src/main/java/com/nativebrik/sdk/sdk.kt index 4c4313f..95834c2 100644 --- a/android/nativebrik/src/main/java/com/nativebrik/sdk/sdk.kt +++ b/android/nativebrik/src/main/java/com/nativebrik/sdk/sdk.kt @@ -117,7 +117,13 @@ public class NativebrikExperiment { internal constructor(config: Config, user: NativebrikUser, db: SQLiteDatabase, context: Context) { this.container = ContainerImpl( - config = config, + config = config.copy(onEvent = { event -> + val name = event.name ?: "" + if (name.isNotEmpty()) { + this.dispatch(NativebrikEvent(name)) + } + config.onEvent?.let { it(event) } + }), user = user, db = db, context = context, From 36da346714abee17d3a51c293591442d3c717703 Mon Sep 17 00:00:00 2001 From: RyosukeCla Date: Tue, 2 Apr 2024 17:35:50 +0900 Subject: [PATCH 6/7] [android] Update dependencies to latest versions --- android/nativebrik/build.gradle.kts | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/android/nativebrik/build.gradle.kts b/android/nativebrik/build.gradle.kts index 58317e6..cf35754 100644 --- a/android/nativebrik/build.gradle.kts +++ b/android/nativebrik/build.gradle.kts @@ -59,13 +59,13 @@ android { dependencies { implementation("org.jetbrains.kotlinx:kotlinx-serialization-json:1.6.0") - implementation("androidx.compose.ui:ui-tooling:1.6.2") - implementation("androidx.compose.ui:ui:1.6.2") - implementation("androidx.compose.foundation:foundation:1.6.2") - implementation("androidx.compose.runtime:runtime:1.6.2") + implementation("androidx.compose.ui:ui-tooling:1.6.4") + implementation("androidx.compose.ui:ui:1.6.4") + implementation("androidx.compose.foundation:foundation:1.6.4") + implementation("androidx.compose.runtime:runtime:1.6.4") implementation("io.coil-kt:coil:2.5.0") implementation("io.coil-kt:coil-compose:2.5.0") - implementation("androidx.compose.material3:material3:1.2.0") + implementation("androidx.compose.material3:material3:1.2.1") implementation("androidx.navigation:navigation-compose:2.7.7") implementation("androidx.core:core-ktx:1.12.0") From f3c4782986c636fd31d690481fdf1f21acae3e35 Mon Sep 17 00:00:00 2001 From: RyosukeCla Date: Tue, 2 Apr 2024 17:36:23 +0900 Subject: [PATCH 7/7] [android] Update version to 0.1.2 --- android/nativebrik/build.gradle.kts | 2 +- android/nativebrik/src/main/java/com/nativebrik/sdk/sdk.kt | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/android/nativebrik/build.gradle.kts b/android/nativebrik/build.gradle.kts index cf35754..37faab4 100644 --- a/android/nativebrik/build.gradle.kts +++ b/android/nativebrik/build.gradle.kts @@ -8,7 +8,7 @@ plugins { } group = "com.nativebrik" -version = "0.1.1" +version = "0.1.2" android { namespace = "com.nativebrik.sdk" diff --git a/android/nativebrik/src/main/java/com/nativebrik/sdk/sdk.kt b/android/nativebrik/src/main/java/com/nativebrik/sdk/sdk.kt index 95834c2..cb6f939 100644 --- a/android/nativebrik/src/main/java/com/nativebrik/sdk/sdk.kt +++ b/android/nativebrik/src/main/java/com/nativebrik/sdk/sdk.kt @@ -24,7 +24,7 @@ import com.nativebrik.sdk.data.user.NativebrikUser import com.nativebrik.sdk.remoteconfig.RemoteConfigLoadingState import com.nativebrik.sdk.schema.UIBlock -const val VERSION = "0.1.1" +const val VERSION = "0.1.2" data class Endpoint( val cdn: String = "https://cdn.nativebrik.com",