Skip to content

RecommendedPreference

RecommendedPreference is a standalone rounded card that recommends related settings, mirroring ColorOS's COUIRecommendedPreference (the "You might be looking for:" card at the bottom of ColorOS settings pages). The card is a 12dp rounded container (COUI couiRoundCornerM) filled with couiColorContainer4, holding a small secondary header followed by one tappable text row per item. Rows draw the standard COUI press overlay while pressed.

Nothing is rendered when items is empty, matching COUIRecommendedPreference.setData() hiding the preference for an empty list.

Import

kotlin
import io.github.suqi8.coui.kmp.preference.RecommendedPreference
import io.github.suqi8.coui.kmp.preference.RecommendedItem
import io.github.suqi8.coui.kmp.preference.RecommendedPreferenceDefaults

Basic Usage

Build the item list inside a remember block to keep it stable across recompositions. Place the card like any other card block, e.g. with 16dp horizontal outer margins:

kotlin
val items = remember {
    listOf(
        RecommendedItem(text = "Display & brightness", onClick = { /* navigate */ }),
        RecommendedItem(text = "Wallpapers & style", onClick = { /* navigate */ }),
        RecommendedItem(text = "Battery", onClick = { /* navigate */ })
    )
}

RecommendedPreference(
    title = "You might be looking for:",
    items = items,
    modifier = Modifier.padding(horizontal = 16.dp)
)

Properties

RecommendedPreference Properties

Property NameTypeDescriptionDefault ValueRequired
titleStringHeader text of the card-Yes
itemsList<RecommendedItem>Recommended entries; empty renders nothing-Yes
modifierModifierComponent modifierModifierNo
cornerRadiusDpCorner radius of the cardRecommendedPreferenceDefaults.CornerRadiusNo
colorsRecommendedPreferenceColorsCard color configurationRecommendedPreferenceDefaults.recommendedPreferenceColors()No
insideMarginPaddingValuesHorizontal margin between card edge and textsRecommendedPreferenceDefaults.InsideMarginNo

RecommendedItem Properties

Property NameTypeDescriptionDefault ValueRequired
textStringRow text-Yes
onClick(() -> Unit)?Callback when the row is clicked; null renders an inert rownullNo

RecommendedPreferenceDefaults Object

ConstantTypeDefault ValueDescription
CornerRadiusDp12.dpCOUI couiRoundCornerM
InsideMarginPaddingValuesPaddingValues(horizontal = 16.dp)In-card text inset (COUI 32dp minus the 16dp card margin)
HeaderTopPaddingDp16.dpCOUI recommended_recyclerView_padding_top
HeaderBottomSpacingDp8.dpCOUI recommended_preference_list_item_head_bottom_margin
HeaderMinHeightDp20.dpCOUI recommended_preference_list_item_height_head
ItemVerticalPaddingDp10.dpCOUI recommended_preference_list_item_common_margin_vertical
BottomPaddingDp8.dpCOUI recommended_recyclerView_padding_bottom

recommendedPreferenceColors() factory

ParameterTypeDefault
containerColorColorcouiColorContainer4 (#0A000000 light / #14FFFFFF dark, theme-aware)
titleColorColorCOUITheme.colorScheme.onSurfaceSecondary
itemColorColorCOUITheme.colorScheme.onSurface

Advanced Usage

Custom Colors

kotlin
RecommendedPreference(
    title = "You might be looking for:",
    items = items,
    colors = RecommendedPreferenceDefaults.recommendedPreferenceColors(
        containerColor = COUITheme.colorScheme.surfaceContainer,
        itemColor = COUITheme.colorScheme.primary
    )
)

At the Bottom of a Settings Page

kotlin
LazyColumn {
    // ... other preference cards ...
    item {
        RecommendedPreference(
            title = "You might be looking for:",
            items = items,
            modifier = Modifier
                .padding(horizontal = 16.dp)
                .padding(bottom = 16.dp)
        )
    }
}

Changelog

Released under the Apache-2.0 License