Skip to content

TopTips

A tip banner shown at the top of a page, mirroring ColorOS's COUIDefaultTopTips: a rounded card holding an optional 24dp start icon, a 14sp message and one trailing element — either an accent colored action label or a round close button. Toggling visibility plays the COUI 250ms vertical scale animation.

Import

kotlin
import io.github.suqi8.coui.kmp.basic.TopTips
import io.github.suqi8.coui.kmp.basic.TopTipsDefaults

Basic Usage

kotlin
TopTips(
    text = "New security update available",
    actionText = "Update",
    onAction = { /* handle action */ },
    modifier = Modifier.fillMaxWidth(),
)

Closable Tips with a Start Icon

kotlin
var visible by remember { mutableStateOf(true) }

TopTips(
    text = "Closable tips with a start icon",
    visible = visible,
    startIcon = {
        Icon(
            imageVector = COUIIcons.Basic.Search,
            contentDescription = null,
            modifier = Modifier.size(24.dp),
        )
    },
    onClose = { visible = false },
    modifier = Modifier.fillMaxWidth(),
)

Properties

TopTips

PropertyTypeDescriptionDefault ValueRequired
textStringThe message of the banner-Yes
modifierModifierModifier applied to the bannerModifierNo
visibleBooleanWhether the banner is visible (animated in/out)trueNo
startIcon(@Composable () -> Unit)?Optional leading iconnullNo
actionTextString?Optional label of the trailing action buttonnullNo
onAction(() -> Unit)?Callback when the action button is clickednullNo
onClose(() -> Unit)?Callback of the close button (shown without action)nullNo
cornerRadiusDpCorner radius of the bannerTopTipsDefaults.CornerRadiusNo
colorsTopTipsColorsColor configurationTopTipsDefaults.topTipsColors()No

TopTipsDefaults

ConstantTypeDefault ValueCOUI Source
CornerRadiusDp12.dpcouiRoundCornerM
ContentPaddingDp12.dpcoui_toptips_view_btn_margin
VerticalPaddingDp12.dpcoui_toptips_view_title_top_margin
IconSizeDp24.dpcoui_toptips_view_icon_btn_size
IconSpacingDp8.dpcoui_toptips_view_title_start_margin
TextMinHeightDp20.dpcoui_toptips_view_title_min_height

Methods

Method NameTypeDescription
textStyle()TextStyleDefault text style of the message (14sp, coui_toptips_view_default_text_size)
actionTextStyle()TextStyleDefault text style of the action button (14sp medium)
topTipsColors()TopTipsColorsCreates the default color configuration (see below)

topTipsColors() factory

ParameterTypeDefaultCOUI Attribute
containerColorColor#0A000000 light / #14FFFFFF darkcouiColorContainer4
contentColorColorCOUITheme.colorScheme.onSurfaceSecondarycouiColorSecondNeutral
actionColorColorCOUITheme.colorScheme.primarycouiColorPrimaryText
closeButtonColorColor#29000000 light / #40FFFFFF darkcouiColorControls
closeIconColorColorColor.Whitecoui_ic_toptips_close

Behavior

  • The trailing element is exclusive, matching COUIDefaultTopTipsView's button types: actionText shows the accent text button; otherwise onClose shows the round close button.
  • When the single-line message would collide with the action label, the label drops to its own end-aligned row below the text (COUIDefaultTopTipsView.isNeedMultiText); in that layout the start icon aligns with the first text line.
  • Toggling visible plays the COUICustomTopTips show/dismiss animation: a 250ms vertical scale pivoting at the center; the banner leaves the composition once the dismiss animation finishes.
  • The message uses 14sp (coui_toptips_view_default_text_size); the action label is 14sp medium.

Changelog

Released under the Apache-2.0 License