diff --git a/toolkit/featureforms/api/featureforms.api b/toolkit/featureforms/api/featureforms.api index 25ba5c19a..1101cfb56 100644 --- a/toolkit/featureforms/api/featureforms.api +++ b/toolkit/featureforms/api/featureforms.api @@ -16,6 +16,44 @@ public final class com/arcgismaps/toolkit/featureforms/ValidationErrorVisibility public static final field INSTANCE Lcom/arcgismaps/toolkit/featureforms/ValidationErrorVisibility$Visible; } +public final class com/arcgismaps/toolkit/featureforms/theme/AttachmentsElementColors { + public static final field $stable I + public final fun component1-0d7_KjU ()J + public final fun component2-0d7_KjU ()J + public final fun component3-0d7_KjU ()J + public final fun component4-0d7_KjU ()J + public final fun component5-0d7_KjU ()J + public final fun component6-0d7_KjU ()J + public final fun component7-0d7_KjU ()J + public final fun copy-4JmcsL4 (JJJJJJJ)Lcom/arcgismaps/toolkit/featureforms/theme/AttachmentsElementColors; + public static synthetic fun copy-4JmcsL4$default (Lcom/arcgismaps/toolkit/featureforms/theme/AttachmentsElementColors;JJJJJJJILjava/lang/Object;)Lcom/arcgismaps/toolkit/featureforms/theme/AttachmentsElementColors; + public fun equals (Ljava/lang/Object;)Z + public final fun getContainerColor-0d7_KjU ()J + public final fun getLabelColor-0d7_KjU ()J + public final fun getOutlineColor-0d7_KjU ()J + public final fun getScrollBarColor-0d7_KjU ()J + public final fun getSupportingTextColor-0d7_KjU ()J + public final fun getTileBorderColor-0d7_KjU ()J + public final fun getTileTextColor-0d7_KjU ()J + public fun hashCode ()I + public fun toString ()Ljava/lang/String; +} + +public final class com/arcgismaps/toolkit/featureforms/theme/AttachmentsElementTypography { + public static final field $stable I + public final fun component1 ()Landroidx/compose/ui/text/TextStyle; + public final fun component2 ()Landroidx/compose/ui/text/TextStyle; + public final fun component3 ()Landroidx/compose/ui/text/TextStyle; + public final fun copy (Landroidx/compose/ui/text/TextStyle;Landroidx/compose/ui/text/TextStyle;Landroidx/compose/ui/text/TextStyle;)Lcom/arcgismaps/toolkit/featureforms/theme/AttachmentsElementTypography; + public static synthetic fun copy$default (Lcom/arcgismaps/toolkit/featureforms/theme/AttachmentsElementTypography;Landroidx/compose/ui/text/TextStyle;Landroidx/compose/ui/text/TextStyle;Landroidx/compose/ui/text/TextStyle;ILjava/lang/Object;)Lcom/arcgismaps/toolkit/featureforms/theme/AttachmentsElementTypography; + public fun equals (Ljava/lang/Object;)Z + public final fun getLabelStyle ()Landroidx/compose/ui/text/TextStyle; + public final fun getSupportingTextStyle ()Landroidx/compose/ui/text/TextStyle; + public final fun getTileTextStyle ()Landroidx/compose/ui/text/TextStyle; + public fun hashCode ()I + public fun toString ()Ljava/lang/String; +} + public final class com/arcgismaps/toolkit/featureforms/theme/EditableTextFieldColors { public static final field $stable I public final fun component1-0d7_KjU ()J @@ -112,9 +150,11 @@ public final class com/arcgismaps/toolkit/featureforms/theme/FeatureFormColorSch public final fun component2 ()Lcom/arcgismaps/toolkit/featureforms/theme/ReadOnlyFieldColors; public final fun component3 ()Lcom/arcgismaps/toolkit/featureforms/theme/RadioButtonFieldColors; public final fun component4 ()Lcom/arcgismaps/toolkit/featureforms/theme/GroupElementColors; - public final fun copy (Lcom/arcgismaps/toolkit/featureforms/theme/EditableTextFieldColors;Lcom/arcgismaps/toolkit/featureforms/theme/ReadOnlyFieldColors;Lcom/arcgismaps/toolkit/featureforms/theme/RadioButtonFieldColors;Lcom/arcgismaps/toolkit/featureforms/theme/GroupElementColors;)Lcom/arcgismaps/toolkit/featureforms/theme/FeatureFormColorScheme; - public static synthetic fun copy$default (Lcom/arcgismaps/toolkit/featureforms/theme/FeatureFormColorScheme;Lcom/arcgismaps/toolkit/featureforms/theme/EditableTextFieldColors;Lcom/arcgismaps/toolkit/featureforms/theme/ReadOnlyFieldColors;Lcom/arcgismaps/toolkit/featureforms/theme/RadioButtonFieldColors;Lcom/arcgismaps/toolkit/featureforms/theme/GroupElementColors;ILjava/lang/Object;)Lcom/arcgismaps/toolkit/featureforms/theme/FeatureFormColorScheme; + public final fun component5 ()Lcom/arcgismaps/toolkit/featureforms/theme/AttachmentsElementColors; + public final fun copy (Lcom/arcgismaps/toolkit/featureforms/theme/EditableTextFieldColors;Lcom/arcgismaps/toolkit/featureforms/theme/ReadOnlyFieldColors;Lcom/arcgismaps/toolkit/featureforms/theme/RadioButtonFieldColors;Lcom/arcgismaps/toolkit/featureforms/theme/GroupElementColors;Lcom/arcgismaps/toolkit/featureforms/theme/AttachmentsElementColors;)Lcom/arcgismaps/toolkit/featureforms/theme/FeatureFormColorScheme; + public static synthetic fun copy$default (Lcom/arcgismaps/toolkit/featureforms/theme/FeatureFormColorScheme;Lcom/arcgismaps/toolkit/featureforms/theme/EditableTextFieldColors;Lcom/arcgismaps/toolkit/featureforms/theme/ReadOnlyFieldColors;Lcom/arcgismaps/toolkit/featureforms/theme/RadioButtonFieldColors;Lcom/arcgismaps/toolkit/featureforms/theme/GroupElementColors;Lcom/arcgismaps/toolkit/featureforms/theme/AttachmentsElementColors;ILjava/lang/Object;)Lcom/arcgismaps/toolkit/featureforms/theme/FeatureFormColorScheme; public fun equals (Ljava/lang/Object;)Z + public final fun getAttachmentsElementColors ()Lcom/arcgismaps/toolkit/featureforms/theme/AttachmentsElementColors; public final fun getEditableTextFieldColors ()Lcom/arcgismaps/toolkit/featureforms/theme/EditableTextFieldColors; public final fun getGroupElementColors ()Lcom/arcgismaps/toolkit/featureforms/theme/GroupElementColors; public final fun getRadioButtonFieldColors ()Lcom/arcgismaps/toolkit/featureforms/theme/RadioButtonFieldColors; @@ -126,7 +166,9 @@ public final class com/arcgismaps/toolkit/featureforms/theme/FeatureFormColorSch public final class com/arcgismaps/toolkit/featureforms/theme/FeatureFormDefaults { public static final field $stable I public static final field INSTANCE Lcom/arcgismaps/toolkit/featureforms/theme/FeatureFormDefaults; - public final fun colorScheme (Lcom/arcgismaps/toolkit/featureforms/theme/EditableTextFieldColors;Lcom/arcgismaps/toolkit/featureforms/theme/ReadOnlyFieldColors;Lcom/arcgismaps/toolkit/featureforms/theme/RadioButtonFieldColors;Lcom/arcgismaps/toolkit/featureforms/theme/GroupElementColors;Landroidx/compose/runtime/Composer;II)Lcom/arcgismaps/toolkit/featureforms/theme/FeatureFormColorScheme; + public final fun attachmentsElementColors-69fazGs (JJJJJJJLandroidx/compose/runtime/Composer;II)Lcom/arcgismaps/toolkit/featureforms/theme/AttachmentsElementColors; + public final fun attachmentsElementTypography (Landroidx/compose/ui/text/TextStyle;Landroidx/compose/ui/text/TextStyle;Landroidx/compose/ui/text/TextStyle;Landroidx/compose/runtime/Composer;II)Lcom/arcgismaps/toolkit/featureforms/theme/AttachmentsElementTypography; + public final fun colorScheme (Lcom/arcgismaps/toolkit/featureforms/theme/EditableTextFieldColors;Lcom/arcgismaps/toolkit/featureforms/theme/ReadOnlyFieldColors;Lcom/arcgismaps/toolkit/featureforms/theme/RadioButtonFieldColors;Lcom/arcgismaps/toolkit/featureforms/theme/GroupElementColors;Lcom/arcgismaps/toolkit/featureforms/theme/AttachmentsElementColors;Landroidx/compose/runtime/Composer;II)Lcom/arcgismaps/toolkit/featureforms/theme/FeatureFormColorScheme; public final fun editableTextFieldColors-s9joTbY (JJJJJJJJLandroidx/compose/foundation/text/selection/TextSelectionColors;JJJJJJJJJJJJJJJJJJJJJJJJLandroidx/compose/runtime/Composer;IIIIII)Lcom/arcgismaps/toolkit/featureforms/theme/EditableTextFieldColors; public final fun editableTextFieldTypography (Landroidx/compose/ui/text/TextStyle;Landroidx/compose/ui/text/TextStyle;Landroidx/compose/ui/text/TextStyle;Landroidx/compose/runtime/Composer;II)Lcom/arcgismaps/toolkit/featureforms/theme/EditableTextFieldTypography; public final fun groupElementColors-zjMxDiM (JJJJJLandroidx/compose/runtime/Composer;II)Lcom/arcgismaps/toolkit/featureforms/theme/GroupElementColors; @@ -135,11 +177,12 @@ public final class com/arcgismaps/toolkit/featureforms/theme/FeatureFormDefaults public final fun radioButtonFieldTypography (Landroidx/compose/ui/text/TextStyle;Landroidx/compose/ui/text/TextStyle;Landroidx/compose/ui/text/TextStyle;Landroidx/compose/runtime/Composer;II)Lcom/arcgismaps/toolkit/featureforms/theme/RadioButtonFieldTypography; public final fun readOnlyFieldColors-ro_MJ88 (JJJJLandroidx/compose/runtime/Composer;II)Lcom/arcgismaps/toolkit/featureforms/theme/ReadOnlyFieldColors; public final fun readOnlyFieldTypography (Landroidx/compose/ui/text/TextStyle;Landroidx/compose/ui/text/TextStyle;Landroidx/compose/ui/text/TextStyle;Landroidx/compose/runtime/Composer;II)Lcom/arcgismaps/toolkit/featureforms/theme/ReadOnlyFieldTypography; - public final fun typography (Lcom/arcgismaps/toolkit/featureforms/theme/EditableTextFieldTypography;Lcom/arcgismaps/toolkit/featureforms/theme/ReadOnlyFieldTypography;Lcom/arcgismaps/toolkit/featureforms/theme/GroupElementTypography;Lcom/arcgismaps/toolkit/featureforms/theme/RadioButtonFieldTypography;Landroidx/compose/runtime/Composer;II)Lcom/arcgismaps/toolkit/featureforms/theme/FeatureFormTypography; + public final fun typography (Lcom/arcgismaps/toolkit/featureforms/theme/EditableTextFieldTypography;Lcom/arcgismaps/toolkit/featureforms/theme/ReadOnlyFieldTypography;Lcom/arcgismaps/toolkit/featureforms/theme/GroupElementTypography;Lcom/arcgismaps/toolkit/featureforms/theme/RadioButtonFieldTypography;Lcom/arcgismaps/toolkit/featureforms/theme/AttachmentsElementTypography;Landroidx/compose/runtime/Composer;II)Lcom/arcgismaps/toolkit/featureforms/theme/FeatureFormTypography; } public final class com/arcgismaps/toolkit/featureforms/theme/FeatureFormTypography { public static final field $stable I + public final fun getAttachmentsElementTypography ()Lcom/arcgismaps/toolkit/featureforms/theme/AttachmentsElementTypography; public final fun getEditableTextFieldTypography ()Lcom/arcgismaps/toolkit/featureforms/theme/EditableTextFieldTypography; public final fun getGroupElementTypography ()Lcom/arcgismaps/toolkit/featureforms/theme/GroupElementTypography; public final fun getRadioButtonFieldTypography ()Lcom/arcgismaps/toolkit/featureforms/theme/RadioButtonFieldTypography; diff --git a/toolkit/featureforms/src/androidTest/java/com/arcgismaps/toolkit/featureforms/ThemingTests.kt b/toolkit/featureforms/src/androidTest/java/com/arcgismaps/toolkit/featureforms/ThemingTests.kt index 681f7c721..ba485b14a 100644 --- a/toolkit/featureforms/src/androidTest/java/com/arcgismaps/toolkit/featureforms/ThemingTests.kt +++ b/toolkit/featureforms/src/androidTest/java/com/arcgismaps/toolkit/featureforms/ThemingTests.kt @@ -18,11 +18,15 @@ package com.arcgismaps.toolkit.featureforms import androidx.compose.ui.graphics.Color import androidx.compose.ui.test.assertIsDisplayed +import androidx.compose.ui.test.hasText import androidx.compose.ui.test.junit4.createComposeRule +import androidx.compose.ui.test.onNodeWithContentDescription import androidx.compose.ui.test.onNodeWithText import androidx.compose.ui.test.performClick import androidx.compose.ui.test.performImeAction +import androidx.compose.ui.test.performScrollToNode import androidx.compose.ui.test.performTextInput +import androidx.compose.ui.test.printToLog import androidx.compose.ui.text.TextStyle import androidx.compose.ui.text.font.FontWeight import com.arcgismaps.toolkit.featureforms.theme.FeatureFormColorScheme @@ -266,4 +270,62 @@ class ThemingTests : FeatureFormTestRunner( supportingText.assertIsDisplayed() supportingText.assertTextColor(Color.Green) } + + /** + * Given a FeatureForm with a custom color scheme and typography for attachments elements + * When the FeatureForm is displayed + * Then the custom color scheme and typography are applied to the attachments form elements + */ + @Test + fun testAttachmentsElementTheming() { + var colorScheme: FeatureFormColorScheme + var typography: FeatureFormTypography + composeTestRule.setContent { + colorScheme = FeatureFormDefaults.colorScheme( + attachmentsElementColors = FeatureFormDefaults.attachmentsElementColors( + labelColor = Color.Red, + tileTextColor = Color.Green + ) + ) + typography = FeatureFormDefaults.typography( + attachmentsElementTypography = FeatureFormDefaults.attachmentsElementTypography( + labelStyle = TextStyle( + fontWeight = FontWeight.ExtraBold + ), + tileTextStyle = TextStyle( + fontWeight = FontWeight.ExtraBold, + ), + ) + ) + FeatureForm( + featureForm = featureForm, + colorScheme = colorScheme, + typography = typography + ) + } + val attachmentsElement = featureForm.defaultAttachmentsElement + assertThat(attachmentsElement).isNotNull() + // find the scrollable container + val lazyColumn = composeTestRule.onNodeWithContentDescription("lazy column") + lazyColumn.performScrollToNode(hasText(attachmentsElement!!.label)) + // scroll until the attachments element is visible + val attachmentsField = composeTestRule.onNodeWithText(attachmentsElement.label) + attachmentsField.printToLog("label") + attachmentsField.assertIsDisplayed() + attachmentsField.assertTextStyle( + TextStyle( + fontWeight = FontWeight.ExtraBold, + color = Color.Red + ) + ) + // get the first attachment tile + val tile = attachmentsField.onChildWithText(attachmentsElement.attachments.first().name) + tile.assertIsDisplayed() + tile.assertTextStyle( + TextStyle( + fontWeight = FontWeight.ExtraBold, + color = Color.Green + ) + ) + } } diff --git a/toolkit/featureforms/src/main/java/com/arcgismaps/toolkit/featureforms/internal/components/attachment/AttachmentElementDefaults.kt b/toolkit/featureforms/src/main/java/com/arcgismaps/toolkit/featureforms/internal/components/attachment/AttachmentElementDefaults.kt deleted file mode 100644 index 3e80305db..000000000 --- a/toolkit/featureforms/src/main/java/com/arcgismaps/toolkit/featureforms/internal/components/attachment/AttachmentElementDefaults.kt +++ /dev/null @@ -1,46 +0,0 @@ -/* - * Copyright 2024 Esri - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.arcgismaps.toolkit.featureforms.internal.components.attachment - -import androidx.compose.foundation.shape.RoundedCornerShape -import androidx.compose.material3.MaterialTheme -import androidx.compose.runtime.Composable -import androidx.compose.ui.graphics.Color -import androidx.compose.ui.unit.dp - -internal object AttachmentElementDefaults { - - val buttonBorderThickness = 2.dp - val borderThickness = 1.dp - val containerShape = RoundedCornerShape(5.dp) - val attachmentDetailShape = RoundedCornerShape(10.dp) - val attachmentShape = RoundedCornerShape(10.dp) - - @Composable - fun colors() : AttachmentElementColors = AttachmentElementColors( - containerColor = MaterialTheme.colorScheme.background, - carouselContainerColor = MaterialTheme.colorScheme.onBackground, - borderColor = MaterialTheme.colorScheme.outline.copy(alpha = 0.6f) - ) -} - -internal data class AttachmentElementColors( - val containerColor : Color, - val carouselContainerColor: Color, - val borderColor : Color, -) - diff --git a/toolkit/featureforms/src/main/java/com/arcgismaps/toolkit/featureforms/internal/components/attachment/AttachmentFormElement.kt b/toolkit/featureforms/src/main/java/com/arcgismaps/toolkit/featureforms/internal/components/attachment/AttachmentFormElement.kt index 713557474..f5e0d5871 100644 --- a/toolkit/featureforms/src/main/java/com/arcgismaps/toolkit/featureforms/internal/components/attachment/AttachmentFormElement.kt +++ b/toolkit/featureforms/src/main/java/com/arcgismaps/toolkit/featureforms/internal/components/attachment/AttachmentFormElement.kt @@ -35,12 +35,14 @@ import androidx.compose.foundation.layout.wrapContentHeight import androidx.compose.foundation.lazy.LazyListState import androidx.compose.foundation.lazy.LazyRow import androidx.compose.foundation.lazy.items +import androidx.compose.foundation.shape.RoundedCornerShape import androidx.compose.material.icons.Icons import androidx.compose.material.icons.rounded.Add import androidx.compose.material.icons.rounded.Folder import androidx.compose.material.icons.rounded.Photo import androidx.compose.material.icons.rounded.PhotoCamera import androidx.compose.material3.Card +import androidx.compose.material3.CardDefaults import androidx.compose.material3.CircularProgressIndicator import androidx.compose.material3.DropdownMenu import androidx.compose.material3.DropdownMenuItem @@ -68,6 +70,7 @@ import androidx.compose.ui.geometry.Offset import androidx.compose.ui.graphics.Color import androidx.compose.ui.platform.LocalContext import androidx.compose.ui.res.stringResource +import androidx.compose.ui.text.TextStyle import androidx.compose.ui.semantics.semantics import androidx.compose.ui.text.style.TextOverflow import androidx.compose.ui.tooling.preview.Preview @@ -80,6 +83,10 @@ import com.arcgismaps.toolkit.featureforms.R import com.arcgismaps.toolkit.featureforms.internal.utils.AttachmentsFileProvider import com.arcgismaps.toolkit.featureforms.internal.utils.DialogType import com.arcgismaps.toolkit.featureforms.internal.utils.LocalDialogRequester +import com.arcgismaps.toolkit.featureforms.theme.AttachmentsElementColors +import com.arcgismaps.toolkit.featureforms.theme.AttachmentsElementTypography +import com.arcgismaps.toolkit.featureforms.theme.LocalColorScheme +import com.arcgismaps.toolkit.featureforms.theme.LocalTypography import kotlinx.coroutines.flow.MutableSharedFlow import kotlinx.coroutines.launch import java.time.Instant @@ -115,12 +122,16 @@ internal fun AttachmentFormElement( lazyListState: LazyListState, hasCameraPermission: Boolean, modifier: Modifier = Modifier, - colors: AttachmentElementColors = AttachmentElementDefaults.colors() + colors: AttachmentsElementColors = LocalColorScheme.current.attachmentsElementColors, + typography: AttachmentsElementTypography = LocalTypography.current.attachmentsElementTypography ) { Card( modifier = modifier.semantics(mergeDescendants = true) {}, - shape = AttachmentElementDefaults.containerShape, - border = BorderStroke(AttachmentElementDefaults.borderThickness, colors.borderColor) + shape = RoundedCornerShape(5.dp), + border = BorderStroke(1.dp, colors.outlineColor), + colors = CardDefaults.cardColors( + containerColor = colors.containerColor + ) ) { Column( modifier = Modifier.padding(15.dp) @@ -128,7 +139,11 @@ internal fun AttachmentFormElement( Row { Header( title = label, - description = description + description = description, + titleColor = colors.labelColor, + titleTextStyle = typography.labelStyle, + descriptionColor = colors.supportingTextColor, + descriptionTextStyle = typography.supportingTextStyle ) Spacer(modifier = Modifier.weight(1f)) if (editable) { @@ -141,20 +156,24 @@ internal fun AttachmentFormElement( } } Spacer(modifier = Modifier.height(20.dp)) - Carousel(lazyListState, attachments) + Carousel(lazyListState, attachments, colors.scrollBarColor) } } } @Composable -private fun Carousel(state: LazyListState, attachments: List) { +private fun Carousel( + state: LazyListState, + attachments: List, + scrollBarColor: Color, +) { LazyRow( modifier = Modifier .fillMaxWidth() .horizontalScrollbar( state = state, - trackColor = MaterialTheme.colorScheme.onSurface.copy(alpha = 0.1f), - color = MaterialTheme.colorScheme.onSurface.copy(alpha = 0.5f), + trackColor = scrollBarColor.copy(alpha = 0.1f), + color = scrollBarColor, height = 4.dp, offsetY = 5.dp, autoHide = false @@ -173,6 +192,10 @@ private fun Carousel(state: LazyListState, attachments: List