Apply gradient to focused Event.
This commit is contained in:
parent
5541ca7427
commit
bcc01d5007
4 changed files with 46 additions and 31 deletions
|
|
@ -37,11 +37,11 @@ import io.element.android.features.messages.impl.timeline.model.event.TimelineIt
|
||||||
import io.element.android.features.messages.impl.timeline.model.event.TimelineItemVoiceContent
|
import io.element.android.features.messages.impl.timeline.model.event.TimelineItemVoiceContent
|
||||||
import io.element.android.features.messages.impl.timeline.protection.TimelineProtectionEvent
|
import io.element.android.features.messages.impl.timeline.protection.TimelineProtectionEvent
|
||||||
import io.element.android.features.messages.impl.timeline.protection.TimelineProtectionState
|
import io.element.android.features.messages.impl.timeline.protection.TimelineProtectionState
|
||||||
|
import io.element.android.libraries.designsystem.modifiers.subtleColorStops
|
||||||
import io.element.android.libraries.designsystem.preview.ElementPreview
|
import io.element.android.libraries.designsystem.preview.ElementPreview
|
||||||
import io.element.android.libraries.designsystem.preview.PreviewsDayNight
|
import io.element.android.libraries.designsystem.preview.PreviewsDayNight
|
||||||
import io.element.android.libraries.designsystem.text.toPx
|
import io.element.android.libraries.designsystem.text.toPx
|
||||||
import io.element.android.libraries.designsystem.theme.LocalBuildMeta
|
import io.element.android.libraries.designsystem.theme.LocalBuildMeta
|
||||||
import io.element.android.libraries.designsystem.theme.highlightedMessageBackgroundColor
|
|
||||||
import io.element.android.libraries.matrix.api.core.EventId
|
import io.element.android.libraries.matrix.api.core.EventId
|
||||||
import io.element.android.libraries.matrix.api.user.MatrixUser
|
import io.element.android.libraries.matrix.api.user.MatrixUser
|
||||||
import io.element.android.libraries.ui.strings.CommonStrings
|
import io.element.android.libraries.ui.strings.CommonStrings
|
||||||
|
|
@ -206,23 +206,20 @@ internal fun TimelineItemRow(
|
||||||
@Suppress("ModifierComposable")
|
@Suppress("ModifierComposable")
|
||||||
@Composable
|
@Composable
|
||||||
private fun Modifier.focusedEvent(
|
private fun Modifier.focusedEvent(
|
||||||
focusedEventOffset: Dp
|
focusedEventOffset: Dp,
|
||||||
|
isEnterpriseBuild: Boolean = LocalBuildMeta.current.isEnterpriseBuild,
|
||||||
): Modifier {
|
): Modifier {
|
||||||
val highlightedLineColor = ElementTheme.colors.textActionAccent
|
val highlightedLineColor = if (isEnterpriseBuild) {
|
||||||
val gradientFirstColor = if (LocalBuildMeta.current.isEnterpriseBuild) {
|
ElementTheme.colors.textActionAccent
|
||||||
ElementTheme.colors.textActionAccent.copy(alpha = 0.125f)
|
|
||||||
} else {
|
} else {
|
||||||
ElementTheme.colors.highlightedMessageBackgroundColor
|
ElementTheme.colors.borderAccentSubtle
|
||||||
}
|
}
|
||||||
val gradientColors = listOf(
|
val gradientColors = subtleColorStops(isEnterpriseBuild)
|
||||||
gradientFirstColor,
|
|
||||||
ElementTheme.colors.bgCanvasDefault,
|
|
||||||
)
|
|
||||||
val verticalOffset = focusedEventOffset.toPx()
|
val verticalOffset = focusedEventOffset.toPx()
|
||||||
val verticalRatio = 0.7f
|
val verticalRatio = 0.7f
|
||||||
return drawWithCache {
|
return drawWithCache {
|
||||||
val brush = Brush.verticalGradient(
|
val brush = Brush.verticalGradient(
|
||||||
colors = gradientColors,
|
colorStops = gradientColors,
|
||||||
endY = size.height * verticalRatio,
|
endY = size.height * verticalRatio,
|
||||||
)
|
)
|
||||||
onDrawBehind {
|
onDrawBehind {
|
||||||
|
|
@ -251,3 +248,18 @@ internal fun FocusedEventPreview() = ElementPreview {
|
||||||
.focusedEvent(0.dp),
|
.focusedEvent(0.dp),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@PreviewsDayNight
|
||||||
|
@Composable
|
||||||
|
internal fun FocusedEventEnterprisePreview() = ElementPreview {
|
||||||
|
Box(
|
||||||
|
modifier = Modifier
|
||||||
|
.padding(16.dp)
|
||||||
|
.fillMaxWidth()
|
||||||
|
.height(160.dp)
|
||||||
|
.focusedEvent(
|
||||||
|
focusedEventOffset = 0.dp,
|
||||||
|
isEnterpriseBuild = true,
|
||||||
|
),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -34,26 +34,33 @@ fun Modifier.backgroundVerticalGradient(
|
||||||
if (!isVisible) return this
|
if (!isVisible) return this
|
||||||
return background(
|
return background(
|
||||||
brush = Brush.verticalGradient(
|
brush = Brush.verticalGradient(
|
||||||
colorStops = buildList {
|
colorStops = subtleColorStops(isEnterpriseBuild),
|
||||||
if (isEnterpriseBuild) {
|
|
||||||
// For enterprise builds, ensure that we are theming the gradient
|
|
||||||
add(0f to ElementTheme.colors.textActionAccent.copy(alpha = 0.5f))
|
|
||||||
add(0.75f to ElementTheme.colors.bgCanvasDefault)
|
|
||||||
add(1f to Color.Transparent)
|
|
||||||
} else {
|
|
||||||
add(0f to ElementTheme.colors.gradientSubtleStop1)
|
|
||||||
add(1 / 5f to ElementTheme.colors.gradientSubtleStop2)
|
|
||||||
add(2 / 5f to ElementTheme.colors.gradientSubtleStop3)
|
|
||||||
add(3 / 5f to ElementTheme.colors.gradientSubtleStop4)
|
|
||||||
add(4 / 5f to ElementTheme.colors.gradientSubtleStop5)
|
|
||||||
add(1f to ElementTheme.colors.gradientSubtleStop6)
|
|
||||||
}
|
|
||||||
}.toTypedArray(),
|
|
||||||
),
|
),
|
||||||
alpha = 0.75f,
|
alpha = 0.75f,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Composable
|
||||||
|
fun subtleColorStops(
|
||||||
|
isEnterpriseBuild: Boolean = LocalBuildMeta.current.isEnterpriseBuild,
|
||||||
|
): Array<Pair<Float, Color>> {
|
||||||
|
return buildList {
|
||||||
|
if (isEnterpriseBuild) {
|
||||||
|
// For enterprise builds, ensure that we are theming the gradient
|
||||||
|
add(0f to ElementTheme.colors.textActionAccent.copy(alpha = 0.5f))
|
||||||
|
add(0.75f to ElementTheme.colors.bgCanvasDefault)
|
||||||
|
add(1f to Color.Transparent)
|
||||||
|
} else {
|
||||||
|
add(0f to ElementTheme.colors.gradientSubtleStop1)
|
||||||
|
add(1 / 5f to ElementTheme.colors.gradientSubtleStop2)
|
||||||
|
add(2 / 5f to ElementTheme.colors.gradientSubtleStop3)
|
||||||
|
add(3 / 5f to ElementTheme.colors.gradientSubtleStop4)
|
||||||
|
add(4 / 5f to ElementTheme.colors.gradientSubtleStop5)
|
||||||
|
add(1f to ElementTheme.colors.gradientSubtleStop6)
|
||||||
|
}
|
||||||
|
}.toTypedArray()
|
||||||
|
}
|
||||||
|
|
||||||
@PreviewsDayNight
|
@PreviewsDayNight
|
||||||
@Composable
|
@Composable
|
||||||
internal fun BackgroundVerticalGradientPreview() = ElementPreview {
|
internal fun BackgroundVerticalGradientPreview() = ElementPreview {
|
||||||
|
|
|
||||||
|
|
@ -100,10 +100,6 @@ val SemanticColors.mentionPillBackground
|
||||||
val SemanticColors.bigCheckmarkBorderColor
|
val SemanticColors.bigCheckmarkBorderColor
|
||||||
get() = if (isLight) LightColorTokens.colorGray400 else DarkColorTokens.colorGray400
|
get() = if (isLight) LightColorTokens.colorGray400 else DarkColorTokens.colorGray400
|
||||||
|
|
||||||
@OptIn(CoreColorToken::class)
|
|
||||||
val SemanticColors.highlightedMessageBackgroundColor
|
|
||||||
get() = if (isLight) LightColorTokens.colorGreen300 else DarkColorTokens.colorGreen300
|
|
||||||
|
|
||||||
// Badge colors
|
// Badge colors
|
||||||
|
|
||||||
@OptIn(CoreColorToken::class)
|
@OptIn(CoreColorToken::class)
|
||||||
|
|
@ -148,7 +144,6 @@ internal fun ColorAliasesPreview() = ElementPreview {
|
||||||
"temporaryColorBgSpecial" to ElementTheme.colors.temporaryColorBgSpecial,
|
"temporaryColorBgSpecial" to ElementTheme.colors.temporaryColorBgSpecial,
|
||||||
"iconSuccessPrimaryBackground" to ElementTheme.colors.iconSuccessPrimaryBackground,
|
"iconSuccessPrimaryBackground" to ElementTheme.colors.iconSuccessPrimaryBackground,
|
||||||
"bigCheckmarkBorderColor" to ElementTheme.colors.bigCheckmarkBorderColor,
|
"bigCheckmarkBorderColor" to ElementTheme.colors.bigCheckmarkBorderColor,
|
||||||
"highlightedMessageBackgroundColor" to ElementTheme.colors.highlightedMessageBackgroundColor,
|
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -64,6 +64,7 @@ class KonsistPreviewTest {
|
||||||
"ColorAliasesPreview",
|
"ColorAliasesPreview",
|
||||||
"DefaultRoomListTopBarWithIndicatorPreview",
|
"DefaultRoomListTopBarWithIndicatorPreview",
|
||||||
"FocusedEventPreview",
|
"FocusedEventPreview",
|
||||||
|
"FocusedEventEnterprisePreview",
|
||||||
"GradientFloatingActionButtonCircleShapePreview",
|
"GradientFloatingActionButtonCircleShapePreview",
|
||||||
"HeaderFooterPageScrollablePreview",
|
"HeaderFooterPageScrollablePreview",
|
||||||
"IconsCompoundPreview",
|
"IconsCompoundPreview",
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue