From bc885ec05e81ad79f8314f825e330620be5bf55b Mon Sep 17 00:00:00 2001 From: Gerard Paligot Date: Sun, 26 Nov 2023 22:09:14 +0100 Subject: [PATCH] feat(openfeedback-m3): support ios target. --- openfeedback-m3/build.gradle.kts | 31 +++++++- openfeedback-m3/openfeedback_m3.podspec | 51 ++++++++++++ .../io/openfeedback/m3/CommentInputPreview.kt | 17 ++++ .../openfeedback/m3/CommentItemsPreview.kt} | 33 +------- .../io/openfeedback/m3/CommentPreview.kt | 26 +++++++ .../io/openfeedback/m3/LoadingPreview.kt | 10 +++ .../m3/OpenFeedbackLayoutPreview.kt | 77 +++++++++++++++++++ .../io/openfeedback/m3/VoteCardPreview.kt | 29 +++++++ .../io/openfeedback/m3/VoteItemsPreview.kt} | 34 -------- .../kotlin/io/openfeedback/m3/Comment.kt | 21 ----- .../kotlin/io/openfeedback/m3/CommentInput.kt | 14 ---- .../kotlin/io/openfeedback/m3/CommentItems.kt | 36 +++++++++ .../kotlin/io/openfeedback/m3/DotModifier.kt | 0 .../kotlin/io/openfeedback/m3/Loading.kt | 7 -- .../io/openfeedback/m3/OpenFeedbackLayout.kt | 65 ---------------- .../kotlin/io/openfeedback/m3/PoweredBy.kt | 1 - .../kotlin/io/openfeedback/m3/VoteCard.kt | 21 ----- .../kotlin/io/openfeedback/m3/VoteItems.kt | 42 ++++++++++ .../android/sample/MainActivity.kt | 4 +- 19 files changed, 319 insertions(+), 200 deletions(-) create mode 100644 openfeedback-m3/openfeedback_m3.podspec create mode 100644 openfeedback-m3/src/androidMain/kotlin/io/openfeedback/m3/CommentInputPreview.kt rename openfeedback-m3/src/{main/kotlin/io/openfeedback/m3/CommentItems.kt => androidMain/kotlin/io/openfeedback/m3/CommentItemsPreview.kt} (55%) create mode 100644 openfeedback-m3/src/androidMain/kotlin/io/openfeedback/m3/CommentPreview.kt create mode 100644 openfeedback-m3/src/androidMain/kotlin/io/openfeedback/m3/LoadingPreview.kt create mode 100644 openfeedback-m3/src/androidMain/kotlin/io/openfeedback/m3/OpenFeedbackLayoutPreview.kt create mode 100644 openfeedback-m3/src/androidMain/kotlin/io/openfeedback/m3/VoteCardPreview.kt rename openfeedback-m3/src/{main/kotlin/io/openfeedback/m3/VoteItems.kt => androidMain/kotlin/io/openfeedback/m3/VoteItemsPreview.kt} (59%) rename openfeedback-m3/src/{main => commonMain}/kotlin/io/openfeedback/m3/Comment.kt (80%) rename openfeedback-m3/src/{main => commonMain}/kotlin/io/openfeedback/m3/CommentInput.kt (82%) create mode 100644 openfeedback-m3/src/commonMain/kotlin/io/openfeedback/m3/CommentItems.kt rename openfeedback-m3/src/{main => commonMain}/kotlin/io/openfeedback/m3/DotModifier.kt (100%) rename openfeedback-m3/src/{main => commonMain}/kotlin/io/openfeedback/m3/Loading.kt (80%) rename openfeedback-m3/src/{main => commonMain}/kotlin/io/openfeedback/m3/OpenFeedbackLayout.kt (65%) rename openfeedback-m3/src/{main => commonMain}/kotlin/io/openfeedback/m3/PoweredBy.kt (99%) rename openfeedback-m3/src/{main => commonMain}/kotlin/io/openfeedback/m3/VoteCard.kt (73%) create mode 100644 openfeedback-m3/src/commonMain/kotlin/io/openfeedback/m3/VoteItems.kt diff --git a/openfeedback-m3/build.gradle.kts b/openfeedback-m3/build.gradle.kts index c4bcf20..65a97ad 100644 --- a/openfeedback-m3/build.gradle.kts +++ b/openfeedback-m3/build.gradle.kts @@ -1,7 +1,7 @@ - plugins { id("io.openfeedback.plugins.lib.multiplatform") id("io.openfeedback.plugins.publishing") + kotlin("native.cocoapods") alias(libs.plugins.jetbrains.compose) } @@ -14,8 +14,32 @@ openfeedback { } kotlin { + applyDefaultHierarchyTemplate() + androidTarget() + listOf( + iosX64(), + iosArm64(), + iosSimulatorArm64() + ).forEach { iosTarget -> + iosTarget.binaries.framework { + baseName = "OpenFeedbackM3Kit" + isStatic = true + } + } + + cocoapods { + version = "1.0" + ios.deploymentTarget = "14.1" + pod("FirebaseAuth") { + linkOnly = true + } + pod("FirebaseFirestore") { + linkOnly = true + } + } + sourceSets { val commonMain by getting { dependencies { @@ -27,9 +51,12 @@ kotlin { implementation(compose.material3) implementation(compose.ui) + } + } + val androidMain by getting { + dependencies { implementation(compose.uiTooling) } } - val androidMain by getting } } diff --git a/openfeedback-m3/openfeedback_m3.podspec b/openfeedback-m3/openfeedback_m3.podspec new file mode 100644 index 0000000..beffb8b --- /dev/null +++ b/openfeedback-m3/openfeedback_m3.podspec @@ -0,0 +1,51 @@ +Pod::Spec.new do |spec| + spec.name = 'openfeedback_m3' + spec.version = '1.0' + spec.homepage = '' + spec.source = { :http=> ''} + spec.authors = '' + spec.license = '' + spec.summary = '' + spec.vendored_frameworks = 'build/cocoapods/framework/openfeedback_m3.framework' + spec.libraries = 'c++' + spec.ios.deployment_target = '14.1' + spec.dependency 'FirebaseAuth' + spec.dependency 'FirebaseFirestore' + + if !Dir.exist?('build/cocoapods/framework/openfeedback_m3.framework') || Dir.empty?('build/cocoapods/framework/openfeedback_m3.framework') + raise " + + Kotlin framework 'openfeedback_m3' doesn't exist yet, so a proper Xcode project can't be generated. + 'pod install' should be executed after running ':generateDummyFramework' Gradle task: + + ./gradlew :openfeedback-m3:generateDummyFramework + + Alternatively, proper pod installation is performed during Gradle sync in the IDE (if Podfile location is set)" + end + + spec.pod_target_xcconfig = { + 'KOTLIN_PROJECT_PATH' => ':openfeedback-m3', + 'PRODUCT_MODULE_NAME' => 'openfeedback_m3', + } + + spec.script_phases = [ + { + :name => 'Build openfeedback_m3', + :execution_position => :before_compile, + :shell_path => '/bin/sh', + :script => <<-SCRIPT + if [ "YES" = "$OVERRIDE_KOTLIN_BUILD_IDE_SUPPORTED" ]; then + echo "Skipping Gradle build task invocation due to OVERRIDE_KOTLIN_BUILD_IDE_SUPPORTED environment variable set to \"YES\"" + exit 0 + fi + set -ev + REPO_ROOT="$PODS_TARGET_SRCROOT" + "$REPO_ROOT/../gradlew" -p "$REPO_ROOT" $KOTLIN_PROJECT_PATH:syncFramework \ + -Pkotlin.native.cocoapods.platform=$PLATFORM_NAME \ + -Pkotlin.native.cocoapods.archs="$ARCHS" \ + -Pkotlin.native.cocoapods.configuration="$CONFIGURATION" + SCRIPT + } + ] + spec.resources = ['build/compose/ios/openfeedback_m3/compose-resources'] +end \ No newline at end of file diff --git a/openfeedback-m3/src/androidMain/kotlin/io/openfeedback/m3/CommentInputPreview.kt b/openfeedback-m3/src/androidMain/kotlin/io/openfeedback/m3/CommentInputPreview.kt new file mode 100644 index 0000000..706a085 --- /dev/null +++ b/openfeedback-m3/src/androidMain/kotlin/io/openfeedback/m3/CommentInputPreview.kt @@ -0,0 +1,17 @@ +package io.openfeedback.m3 + +import androidx.compose.material3.MaterialTheme +import androidx.compose.runtime.Composable +import androidx.compose.ui.tooling.preview.Preview + +@Preview +@Composable +private fun CommentInputPreview() { + MaterialTheme { + CommentInput( + value = "My comment", + onValueChange = {}, + onSubmit = {} + ) + } +} diff --git a/openfeedback-m3/src/main/kotlin/io/openfeedback/m3/CommentItems.kt b/openfeedback-m3/src/androidMain/kotlin/io/openfeedback/m3/CommentItemsPreview.kt similarity index 55% rename from openfeedback-m3/src/main/kotlin/io/openfeedback/m3/CommentItems.kt rename to openfeedback-m3/src/androidMain/kotlin/io/openfeedback/m3/CommentItemsPreview.kt index 9784092..45f71d1 100644 --- a/openfeedback-m3/src/main/kotlin/io/openfeedback/m3/CommentItems.kt +++ b/openfeedback-m3/src/androidMain/kotlin/io/openfeedback/m3/CommentItemsPreview.kt @@ -1,45 +1,14 @@ package io.openfeedback.m3 -import androidx.compose.foundation.layout.Arrangement -import androidx.compose.foundation.layout.Column -import androidx.compose.foundation.layout.ColumnScope import androidx.compose.material3.MaterialTheme -import androidx.compose.material3.Text import androidx.compose.runtime.Composable -import androidx.compose.ui.Modifier import androidx.compose.ui.tooling.preview.Preview -import androidx.compose.ui.unit.dp -import dev.icerock.moko.resources.compose.stringResource -import io.openfeedback.MR import io.openfeedback.viewmodels.models.UIComment import io.openfeedback.viewmodels.models.UIDot -@Composable -internal fun CommentItems( - comments: List, - modifier: Modifier = Modifier, - verticalArrangement: Arrangement.Vertical = Arrangement.spacedBy(8.dp), - commentInput: @Composable ColumnScope.() -> Unit, - comment: @Composable ColumnScope.(UIComment) -> Unit -) { - Column( - modifier = modifier, - verticalArrangement = verticalArrangement - ) { - Text( - text = stringResource(MR.strings.openfeedback_comments_title), - style = MaterialTheme.typography.titleMedium - ) - commentInput() - comments.forEach { uiComment -> - comment(uiComment) - } - } -} - @Preview @Composable -private fun VoteItemsPreview() { +private fun CommentItemsPreview() { MaterialTheme { CommentItems( comments = listOf( diff --git a/openfeedback-m3/src/androidMain/kotlin/io/openfeedback/m3/CommentPreview.kt b/openfeedback-m3/src/androidMain/kotlin/io/openfeedback/m3/CommentPreview.kt new file mode 100644 index 0000000..816618c --- /dev/null +++ b/openfeedback-m3/src/androidMain/kotlin/io/openfeedback/m3/CommentPreview.kt @@ -0,0 +1,26 @@ +package io.openfeedback.m3 + +import androidx.compose.material3.MaterialTheme +import androidx.compose.runtime.Composable +import androidx.compose.ui.tooling.preview.Preview +import io.openfeedback.viewmodels.models.UIComment +import io.openfeedback.viewmodels.models.UIDot + +@Preview +@Composable +private fun CommentPreview() { + MaterialTheme { + Comment( + comment = UIComment( + id = "", + voteItemId = "", + message = "Super talk and great speakers!", + createdAt = "08 August 2023", + upVotes = 8, + dots = listOf(UIDot(x = .5f, y = .5f, color = "FF00CC")), + votedByUser = true + ), + onClick = {} + ) + } +} diff --git a/openfeedback-m3/src/androidMain/kotlin/io/openfeedback/m3/LoadingPreview.kt b/openfeedback-m3/src/androidMain/kotlin/io/openfeedback/m3/LoadingPreview.kt new file mode 100644 index 0000000..0e3210f --- /dev/null +++ b/openfeedback-m3/src/androidMain/kotlin/io/openfeedback/m3/LoadingPreview.kt @@ -0,0 +1,10 @@ +package io.openfeedback.m3 + +import androidx.compose.runtime.Composable +import androidx.compose.ui.tooling.preview.Preview + +@Preview +@Composable +internal fun LoadingPreview() { + Loading() +} diff --git a/openfeedback-m3/src/androidMain/kotlin/io/openfeedback/m3/OpenFeedbackLayoutPreview.kt b/openfeedback-m3/src/androidMain/kotlin/io/openfeedback/m3/OpenFeedbackLayoutPreview.kt new file mode 100644 index 0000000..efd4c82 --- /dev/null +++ b/openfeedback-m3/src/androidMain/kotlin/io/openfeedback/m3/OpenFeedbackLayoutPreview.kt @@ -0,0 +1,77 @@ +package io.openfeedback.m3 + +import androidx.compose.foundation.layout.Arrangement +import androidx.compose.foundation.layout.fillMaxWidth +import androidx.compose.foundation.layout.height +import androidx.compose.material3.ExperimentalMaterial3Api +import androidx.compose.material3.MaterialTheme +import androidx.compose.runtime.Composable +import androidx.compose.ui.Modifier +import androidx.compose.ui.tooling.preview.Preview +import androidx.compose.ui.unit.dp +import io.openfeedback.viewmodels.models.UIComment +import io.openfeedback.viewmodels.models.UIDot +import io.openfeedback.viewmodels.models.UISessionFeedback +import io.openfeedback.viewmodels.models.UIVoteItem + +@OptIn(ExperimentalMaterial3Api::class) +@Preview +@Composable +private fun OpenFeedbackLayoutPreview() { + MaterialTheme { + OpenFeedbackLayout( + sessionFeedback = UISessionFeedback( + commentValue = "", + commentVoteItemId = "", + comments = listOf( + UIComment( + id = "", + voteItemId = "", + message = "Nice comment", + createdAt = "08 August 2023", + upVotes = 8, + dots = listOf(UIDot(x = .5f, y = .5f, color = "FF00CC")), + votedByUser = true + ), + UIComment( + id = "", + voteItemId = "", + message = "Another one", + createdAt = "08 August 2023", + upVotes = 0, + dots = listOf(UIDot(x = .5f, y = .5f, color = "FF00CC")), + votedByUser = true + ) + ), + voteItem = listOf( + UIVoteItem( + id = "", + text = "Fun", + dots = listOf(UIDot(x = .5f, y = .5f, color = "FF00CC")), + votedByUser = true + ), + UIVoteItem( + id = "", + text = "Fun", + dots = listOf(UIDot(x = .5f, y = .5f, color = "FF00CC")), + votedByUser = true + ) + ) + ), + horizontalArrangement = Arrangement.spacedBy(8.dp), + verticalArrangement = Arrangement.spacedBy(8.dp), + commentInput = { + CommentInput(value = "", onValueChange = {}, onSubmit = {}) + }, + comment = { Comment(comment = it, onClick = {}) } + ) { + VoteCard( + voteModel = it, + onClick = {}, + modifier = Modifier + .height(100.dp) + .fillMaxWidth() + ) + } + } +} diff --git a/openfeedback-m3/src/androidMain/kotlin/io/openfeedback/m3/VoteCardPreview.kt b/openfeedback-m3/src/androidMain/kotlin/io/openfeedback/m3/VoteCardPreview.kt new file mode 100644 index 0000000..596e0e0 --- /dev/null +++ b/openfeedback-m3/src/androidMain/kotlin/io/openfeedback/m3/VoteCardPreview.kt @@ -0,0 +1,29 @@ +package io.openfeedback.m3 + +import androidx.compose.foundation.layout.size +import androidx.compose.material3.ExperimentalMaterial3Api +import androidx.compose.material3.MaterialTheme +import androidx.compose.runtime.Composable +import androidx.compose.ui.Modifier +import androidx.compose.ui.tooling.preview.Preview +import androidx.compose.ui.unit.dp +import io.openfeedback.viewmodels.models.UIDot +import io.openfeedback.viewmodels.models.UIVoteItem + +@OptIn(ExperimentalMaterial3Api::class) +@Preview +@Composable +private fun VoteCardPreview() { + MaterialTheme { + VoteCard( + voteModel = UIVoteItem( + id = "", + text = "Fun", + dots = listOf(UIDot(x = .5f, y = .5f, color = "FF00CC")), + votedByUser = true + ), + onClick = {}, + modifier = Modifier.size(height = 100.dp, width = 200.dp) + ) + } +} diff --git a/openfeedback-m3/src/main/kotlin/io/openfeedback/m3/VoteItems.kt b/openfeedback-m3/src/androidMain/kotlin/io/openfeedback/m3/VoteItemsPreview.kt similarity index 59% rename from openfeedback-m3/src/main/kotlin/io/openfeedback/m3/VoteItems.kt rename to openfeedback-m3/src/androidMain/kotlin/io/openfeedback/m3/VoteItemsPreview.kt index 560ecdb..d98ba52 100644 --- a/openfeedback-m3/src/main/kotlin/io/openfeedback/m3/VoteItems.kt +++ b/openfeedback-m3/src/androidMain/kotlin/io/openfeedback/m3/VoteItemsPreview.kt @@ -1,9 +1,6 @@ package io.openfeedback.m3 import androidx.compose.foundation.layout.Arrangement -import androidx.compose.foundation.layout.Column -import androidx.compose.foundation.layout.ColumnScope -import androidx.compose.foundation.layout.Row import androidx.compose.foundation.layout.fillMaxWidth import androidx.compose.foundation.layout.height import androidx.compose.material3.ExperimentalMaterial3Api @@ -15,37 +12,6 @@ import androidx.compose.ui.unit.dp import io.openfeedback.viewmodels.models.UIDot import io.openfeedback.viewmodels.models.UIVoteItem -@ExperimentalMaterial3Api -@Composable -internal fun VoteItems( - voteItems: List, - modifier: Modifier = Modifier, - columnCount: Int = 2, - horizontalArrangement: Arrangement.Horizontal = Arrangement.spacedBy(8.dp), - verticalArrangement: Arrangement.Vertical = Arrangement.spacedBy(8.dp), - content: @Composable ColumnScope.(UIVoteItem) -> Unit -) { - Row( - modifier = modifier, - horizontalArrangement = horizontalArrangement - ) { - 0.until(columnCount).forEach { column -> - Column( - verticalArrangement = verticalArrangement, - modifier = Modifier.weight(1f) - ) { - voteItems - .filterIndexed { index, _ -> - index % columnCount == column - } - .forEach { voteItem -> - content(voteItem) - } - } - } - } -} - @OptIn(ExperimentalMaterial3Api::class) @Preview @Composable diff --git a/openfeedback-m3/src/main/kotlin/io/openfeedback/m3/Comment.kt b/openfeedback-m3/src/commonMain/kotlin/io/openfeedback/m3/Comment.kt similarity index 80% rename from openfeedback-m3/src/main/kotlin/io/openfeedback/m3/Comment.kt rename to openfeedback-m3/src/commonMain/kotlin/io/openfeedback/m3/Comment.kt index c0f918e..bc0138a 100644 --- a/openfeedback-m3/src/main/kotlin/io/openfeedback/m3/Comment.kt +++ b/openfeedback-m3/src/commonMain/kotlin/io/openfeedback/m3/Comment.kt @@ -14,12 +14,10 @@ import androidx.compose.ui.Modifier import androidx.compose.ui.graphics.Color import androidx.compose.ui.graphics.Shape import androidx.compose.ui.text.TextStyle -import androidx.compose.ui.tooling.preview.Preview import androidx.compose.ui.unit.dp import dev.icerock.moko.resources.compose.stringResource import io.openfeedback.MR import io.openfeedback.viewmodels.models.UIComment -import io.openfeedback.viewmodels.models.UIDot @Composable fun Comment( @@ -69,22 +67,3 @@ fun Comment( } } } - -@Preview -@Composable -private fun CommentPreview() { - MaterialTheme { - Comment( - comment = UIComment( - id = "", - voteItemId = "", - message = "Super talk and great speakers!", - createdAt = "08 August 2023", - upVotes = 8, - dots = listOf(UIDot(x = .5f, y = .5f, color = "FF00CC")), - votedByUser = true - ), - onClick = {} - ) - } -} diff --git a/openfeedback-m3/src/main/kotlin/io/openfeedback/m3/CommentInput.kt b/openfeedback-m3/src/commonMain/kotlin/io/openfeedback/m3/CommentInput.kt similarity index 82% rename from openfeedback-m3/src/main/kotlin/io/openfeedback/m3/CommentInput.kt rename to openfeedback-m3/src/commonMain/kotlin/io/openfeedback/m3/CommentInput.kt index 2d45c9c..9b75c34 100644 --- a/openfeedback-m3/src/main/kotlin/io/openfeedback/m3/CommentInput.kt +++ b/openfeedback-m3/src/commonMain/kotlin/io/openfeedback/m3/CommentInput.kt @@ -6,13 +6,11 @@ import androidx.compose.material.icons.Icons import androidx.compose.material.icons.outlined.Send import androidx.compose.material3.Icon import androidx.compose.material3.IconButton -import androidx.compose.material3.MaterialTheme import androidx.compose.material3.Text import androidx.compose.material3.TextField import androidx.compose.runtime.Composable import androidx.compose.ui.Modifier import androidx.compose.ui.text.input.ImeAction -import androidx.compose.ui.tooling.preview.Preview import dev.icerock.moko.resources.compose.stringResource import io.openfeedback.MR @@ -43,15 +41,3 @@ fun CommentInput( maxLines = 5 ) } - -@Preview -@Composable -private fun CommentInputPreview() { - MaterialTheme { - CommentInput( - value = "My comment", - onValueChange = {}, - onSubmit = {} - ) - } -} diff --git a/openfeedback-m3/src/commonMain/kotlin/io/openfeedback/m3/CommentItems.kt b/openfeedback-m3/src/commonMain/kotlin/io/openfeedback/m3/CommentItems.kt new file mode 100644 index 0000000..6f64938 --- /dev/null +++ b/openfeedback-m3/src/commonMain/kotlin/io/openfeedback/m3/CommentItems.kt @@ -0,0 +1,36 @@ +package io.openfeedback.m3 + +import androidx.compose.foundation.layout.Arrangement +import androidx.compose.foundation.layout.Column +import androidx.compose.foundation.layout.ColumnScope +import androidx.compose.material3.MaterialTheme +import androidx.compose.material3.Text +import androidx.compose.runtime.Composable +import androidx.compose.ui.Modifier +import androidx.compose.ui.unit.dp +import dev.icerock.moko.resources.compose.stringResource +import io.openfeedback.MR +import io.openfeedback.viewmodels.models.UIComment + +@Composable +internal fun CommentItems( + comments: List, + modifier: Modifier = Modifier, + verticalArrangement: Arrangement.Vertical = Arrangement.spacedBy(8.dp), + commentInput: @Composable ColumnScope.() -> Unit, + comment: @Composable ColumnScope.(UIComment) -> Unit +) { + Column( + modifier = modifier, + verticalArrangement = verticalArrangement + ) { + Text( + text = stringResource(MR.strings.openfeedback_comments_title), + style = MaterialTheme.typography.titleMedium + ) + commentInput() + comments.forEach { uiComment -> + comment(uiComment) + } + } +} diff --git a/openfeedback-m3/src/main/kotlin/io/openfeedback/m3/DotModifier.kt b/openfeedback-m3/src/commonMain/kotlin/io/openfeedback/m3/DotModifier.kt similarity index 100% rename from openfeedback-m3/src/main/kotlin/io/openfeedback/m3/DotModifier.kt rename to openfeedback-m3/src/commonMain/kotlin/io/openfeedback/m3/DotModifier.kt diff --git a/openfeedback-m3/src/main/kotlin/io/openfeedback/m3/Loading.kt b/openfeedback-m3/src/commonMain/kotlin/io/openfeedback/m3/Loading.kt similarity index 80% rename from openfeedback-m3/src/main/kotlin/io/openfeedback/m3/Loading.kt rename to openfeedback-m3/src/commonMain/kotlin/io/openfeedback/m3/Loading.kt index cfb48fa..5422a79 100644 --- a/openfeedback-m3/src/main/kotlin/io/openfeedback/m3/Loading.kt +++ b/openfeedback-m3/src/commonMain/kotlin/io/openfeedback/m3/Loading.kt @@ -6,7 +6,6 @@ import androidx.compose.material3.CircularProgressIndicator import androidx.compose.runtime.Composable import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier -import androidx.compose.ui.tooling.preview.Preview @Composable fun Loading(modifier: Modifier = Modifier) { @@ -17,9 +16,3 @@ fun Loading(modifier: Modifier = Modifier) { CircularProgressIndicator() } } - -@Preview -@Composable -internal fun LoadingPreview() { - Loading() -} diff --git a/openfeedback-m3/src/main/kotlin/io/openfeedback/m3/OpenFeedbackLayout.kt b/openfeedback-m3/src/commonMain/kotlin/io/openfeedback/m3/OpenFeedbackLayout.kt similarity index 65% rename from openfeedback-m3/src/main/kotlin/io/openfeedback/m3/OpenFeedbackLayout.kt rename to openfeedback-m3/src/commonMain/kotlin/io/openfeedback/m3/OpenFeedbackLayout.kt index 1e56bc7..a9e7c7f 100644 --- a/openfeedback-m3/src/main/kotlin/io/openfeedback/m3/OpenFeedbackLayout.kt +++ b/openfeedback-m3/src/commonMain/kotlin/io/openfeedback/m3/OpenFeedbackLayout.kt @@ -8,12 +8,10 @@ import androidx.compose.foundation.layout.Spacer import androidx.compose.foundation.layout.fillMaxWidth import androidx.compose.foundation.layout.height import androidx.compose.material3.ExperimentalMaterial3Api -import androidx.compose.material3.MaterialTheme import androidx.compose.runtime.Composable import androidx.compose.runtime.collectAsState import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier -import androidx.compose.ui.tooling.preview.Preview import androidx.compose.ui.unit.dp import com.vanniktech.locale.Locale import com.vanniktech.locale.Locales @@ -23,7 +21,6 @@ import io.openfeedback.viewmodels.OpenFeedbackFirebaseConfig import io.openfeedback.viewmodels.OpenFeedbackUiState import io.openfeedback.viewmodels.OpenFeedbackViewModel import io.openfeedback.viewmodels.models.UIComment -import io.openfeedback.viewmodels.models.UIDot import io.openfeedback.viewmodels.models.UISessionFeedback import io.openfeedback.viewmodels.models.UIVoteItem @@ -127,65 +124,3 @@ fun OpenFeedbackLayout( } } } - -@OptIn(ExperimentalMaterial3Api::class) -@Preview -@Composable -private fun OpenFeedbackLayoutPreview() { - MaterialTheme { - OpenFeedbackLayout( - sessionFeedback = UISessionFeedback( - commentValue = "", - commentVoteItemId = "", - comments = listOf( - UIComment( - id = "", - voteItemId = "", - message = "Nice comment", - createdAt = "08 August 2023", - upVotes = 8, - dots = listOf(UIDot(x = .5f, y = .5f, color = "FF00CC")), - votedByUser = true - ), - UIComment( - id = "", - voteItemId = "", - message = "Another one", - createdAt = "08 August 2023", - upVotes = 0, - dots = listOf(UIDot(x = .5f, y = .5f, color = "FF00CC")), - votedByUser = true - ) - ), - voteItem = listOf( - UIVoteItem( - id = "", - text = "Fun", - dots = listOf(UIDot(x = .5f, y = .5f, color = "FF00CC")), - votedByUser = true - ), - UIVoteItem( - id = "", - text = "Fun", - dots = listOf(UIDot(x = .5f, y = .5f, color = "FF00CC")), - votedByUser = true - ) - ) - ), - horizontalArrangement = Arrangement.spacedBy(8.dp), - verticalArrangement = Arrangement.spacedBy(8.dp), - commentInput = { - CommentInput(value = "", onValueChange = {}, onSubmit = {}) - }, - comment = { Comment(comment = it, onClick = {}) } - ) { - VoteCard( - voteModel = it, - onClick = {}, - modifier = Modifier - .height(100.dp) - .fillMaxWidth() - ) - } - } -} diff --git a/openfeedback-m3/src/main/kotlin/io/openfeedback/m3/PoweredBy.kt b/openfeedback-m3/src/commonMain/kotlin/io/openfeedback/m3/PoweredBy.kt similarity index 99% rename from openfeedback-m3/src/main/kotlin/io/openfeedback/m3/PoweredBy.kt rename to openfeedback-m3/src/commonMain/kotlin/io/openfeedback/m3/PoweredBy.kt index 673933a..951e6c3 100644 --- a/openfeedback-m3/src/main/kotlin/io/openfeedback/m3/PoweredBy.kt +++ b/openfeedback-m3/src/commonMain/kotlin/io/openfeedback/m3/PoweredBy.kt @@ -25,7 +25,6 @@ internal fun PoweredBy( style: TextStyle = MaterialTheme.typography.bodyMedium, color: Color = MaterialTheme.colorScheme.onBackground ) { - val logo = if (MaterialTheme.colorScheme.background.luminance() > 0.5) MR.images.openfeedback_light else MR.images.openfeedback_dark diff --git a/openfeedback-m3/src/main/kotlin/io/openfeedback/m3/VoteCard.kt b/openfeedback-m3/src/commonMain/kotlin/io/openfeedback/m3/VoteCard.kt similarity index 73% rename from openfeedback-m3/src/main/kotlin/io/openfeedback/m3/VoteCard.kt rename to openfeedback-m3/src/commonMain/kotlin/io/openfeedback/m3/VoteCard.kt index 694a1b6..14aeb5e 100644 --- a/openfeedback-m3/src/main/kotlin/io/openfeedback/m3/VoteCard.kt +++ b/openfeedback-m3/src/commonMain/kotlin/io/openfeedback/m3/VoteCard.kt @@ -3,7 +3,6 @@ package io.openfeedback.m3 import androidx.compose.foundation.BorderStroke import androidx.compose.foundation.layout.Box import androidx.compose.foundation.layout.padding -import androidx.compose.foundation.layout.size import androidx.compose.material3.ExperimentalMaterial3Api import androidx.compose.material3.MaterialTheme import androidx.compose.material3.Surface @@ -14,9 +13,7 @@ import androidx.compose.ui.Modifier import androidx.compose.ui.graphics.Color import androidx.compose.ui.graphics.Shape import androidx.compose.ui.text.TextStyle -import androidx.compose.ui.tooling.preview.Preview import androidx.compose.ui.unit.dp -import io.openfeedback.viewmodels.models.UIDot import io.openfeedback.viewmodels.models.UIVoteItem @ExperimentalMaterial3Api @@ -50,21 +47,3 @@ fun VoteCard( } } } - -@OptIn(ExperimentalMaterial3Api::class) -@Preview -@Composable -private fun VoteCardPreview() { - MaterialTheme { - VoteCard( - voteModel = UIVoteItem( - id = "", - text = "Fun", - dots = listOf(UIDot(x = .5f, y = .5f, color = "FF00CC")), - votedByUser = true - ), - onClick = {}, - modifier = Modifier.size(height = 100.dp, width = 200.dp) - ) - } -} diff --git a/openfeedback-m3/src/commonMain/kotlin/io/openfeedback/m3/VoteItems.kt b/openfeedback-m3/src/commonMain/kotlin/io/openfeedback/m3/VoteItems.kt new file mode 100644 index 0000000..f4773ce --- /dev/null +++ b/openfeedback-m3/src/commonMain/kotlin/io/openfeedback/m3/VoteItems.kt @@ -0,0 +1,42 @@ +package io.openfeedback.m3 + +import androidx.compose.foundation.layout.Arrangement +import androidx.compose.foundation.layout.Column +import androidx.compose.foundation.layout.ColumnScope +import androidx.compose.foundation.layout.Row +import androidx.compose.material3.ExperimentalMaterial3Api +import androidx.compose.runtime.Composable +import androidx.compose.ui.Modifier +import androidx.compose.ui.unit.dp +import io.openfeedback.viewmodels.models.UIVoteItem + +@ExperimentalMaterial3Api +@Composable +internal fun VoteItems( + voteItems: List, + modifier: Modifier = Modifier, + columnCount: Int = 2, + horizontalArrangement: Arrangement.Horizontal = Arrangement.spacedBy(8.dp), + verticalArrangement: Arrangement.Vertical = Arrangement.spacedBy(8.dp), + content: @Composable ColumnScope.(UIVoteItem) -> Unit +) { + Row( + modifier = modifier, + horizontalArrangement = horizontalArrangement + ) { + 0.until(columnCount).forEach { column -> + Column( + verticalArrangement = verticalArrangement, + modifier = Modifier.weight(1f) + ) { + voteItems + .filterIndexed { index, _ -> + index % columnCount == column + } + .forEach { voteItem -> + content(voteItem) + } + } + } + } +} diff --git a/sample-app/src/main/java/io/openfeedback/android/sample/MainActivity.kt b/sample-app/src/main/java/io/openfeedback/android/sample/MainActivity.kt index c608550..de9b8b0 100644 --- a/sample-app/src/main/java/io/openfeedback/android/sample/MainActivity.kt +++ b/sample-app/src/main/java/io/openfeedback/android/sample/MainActivity.kt @@ -41,9 +41,7 @@ class MainActivity : AppCompatActivity() { Scaffold { LazyColumn(contentPadding = it) { item { - ThemeSwitcher( - isLight = isLight - ) { isLight = it } + ThemeSwitcher(isLight = isLight) { isLight = it } } item { OpenFeedback(