Moves away from drawBehind and uses background color instead. It feels faster at first glance.

pull/484/head
Vitor Pamplona 2023-07-01 16:57:45 -04:00
rodzic d2a22f4ca0
commit 56d9c9a50f
10 zmienionych plików z 36 dodań i 86 usunięć

Wyświetl plik

@ -1,5 +1,6 @@
package com.vitorpamplona.amethyst.ui.components
import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.PaddingValues
@ -19,13 +20,12 @@ import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.drawBehind
import androidx.compose.ui.graphics.Brush
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.unit.dp
import com.vitorpamplona.amethyst.R
import com.vitorpamplona.amethyst.ui.actions.ImmutableListOfLists
import com.vitorpamplona.amethyst.ui.note.getGradient
import com.vitorpamplona.amethyst.ui.screen.loggedIn.AccountViewModel
import com.vitorpamplona.amethyst.ui.theme.ButtonBorder
import com.vitorpamplona.amethyst.ui.theme.secondaryButtonBackground
@ -80,16 +80,7 @@ fun ExpandableRichTextViewer(
modifier = Modifier
.align(Alignment.BottomCenter)
.fillMaxWidth()
.drawBehind {
drawRect(
Brush.verticalGradient(
colors = listOf(
backgroundColor.value.copy(alpha = 0f),
backgroundColor.value
)
)
)
}
.background(getGradient(backgroundColor))
) {
ShowMoreButton() {
showFullText = !showFullText

Wyświetl plik

@ -1,6 +1,7 @@
package com.vitorpamplona.amethyst.ui.note
import androidx.compose.foundation.ExperimentalFoundationApi
import androidx.compose.foundation.background
import androidx.compose.foundation.combinedClickable
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
@ -26,7 +27,6 @@ import androidx.compose.runtime.rememberCoroutineScope
import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.drawBehind
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.compositeOver
import androidx.compose.ui.platform.LocalContext
@ -79,9 +79,7 @@ fun BadgeCompose(likeSetCard: BadgeCard, isInnerNote: Boolean = false, routeForL
Column(
modifier = Modifier
.drawBehind {
drawRect(backgroundColor.value)
}
.background(backgroundColor.value)
.combinedClickable(
onClick = {
scope.launch {

Wyświetl plik

@ -2,6 +2,7 @@ package com.vitorpamplona.amethyst.ui.note
import androidx.compose.animation.Crossfade
import androidx.compose.foundation.ExperimentalFoundationApi
import androidx.compose.foundation.background
import androidx.compose.foundation.clickable
import androidx.compose.foundation.combinedClickable
import androidx.compose.foundation.interaction.MutableInteractionSource
@ -40,7 +41,6 @@ import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
import androidx.compose.ui.draw.drawBehind
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.Shape
import androidx.compose.ui.graphics.compositeOver
@ -923,7 +923,7 @@ private fun RenderRelayIcon(iconUrl: String) {
Modifier
.size(Size13dp)
.clip(shape = CircleShape)
.drawBehind { drawRect(backgroundColor) }
.background(backgroundColor)
}
RobohashFallbackAsyncImage(

Wyświetl plik

@ -22,7 +22,6 @@ import androidx.compose.runtime.rememberCoroutineScope
import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.drawBehind
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.compositeOver
import androidx.compose.ui.res.painterResource
@ -70,11 +69,7 @@ fun MessageSetCompose(messageSetCard: MessageSetCard, routeForLastRead: String,
val columnModifier = remember(backgroundColor.value) {
Modifier
.drawBehind {
drawRect(
backgroundColor.value
)
}
.background(backgroundColor.value)
.padding(
start = 12.dp,
end = 12.dp,

Wyświetl plik

@ -3,6 +3,7 @@ package com.vitorpamplona.amethyst.ui.note
import android.util.Log
import androidx.compose.animation.Crossfade
import androidx.compose.foundation.ExperimentalFoundationApi
import androidx.compose.foundation.background
import androidx.compose.foundation.clickable
import androidx.compose.foundation.combinedClickable
import androidx.compose.foundation.layout.Box
@ -35,7 +36,6 @@ import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
import androidx.compose.ui.draw.drawBehind
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.compositeOver
import androidx.compose.ui.layout.ContentScale
@ -114,9 +114,7 @@ fun MultiSetCompose(multiSetCard: MultiSetCard, routeForLastRead: String, accoun
val columnModifier = remember(backgroundColor.value) {
Modifier
.drawBehind {
drawRect(backgroundColor.value)
}
.background(backgroundColor.value)
.padding(
start = 12.dp,
end = 12.dp,
@ -440,7 +438,7 @@ fun CrossfadeToDisplayAmount(authorComment: MutableState<ZapAmountCommentNotific
modifier = remember {
Modifier
.width(Size35dp)
.drawBehind { drawRect(backgroundColor) }
.background(backgroundColor)
},
contentAlignment = Alignment.BottomCenter
) {

Wyświetl plik

@ -61,7 +61,6 @@ import androidx.compose.ui.Alignment.Companion.CenterVertically
import androidx.compose.ui.Alignment.Companion.TopEnd
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
import androidx.compose.ui.draw.drawBehind
import androidx.compose.ui.graphics.Brush
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.compositeOver
@ -563,9 +562,7 @@ private fun ClickableNote(
},
onLongClick = showPopup
)
.drawBehind {
drawRect(backgroundColor.value)
}
.background(backgroundColor.value)
}
Column(modifier = updatedModifier) {
@ -1293,16 +1290,7 @@ fun DisplayRelaySet(
modifier = Modifier
.align(Alignment.BottomCenter)
.fillMaxWidth()
.drawBehind {
drawRect(
Brush.verticalGradient(
colors = listOf(
backgroundColor.value.copy(alpha = 0f),
backgroundColor.value
)
)
)
}
.background(getGradient(backgroundColor))
) {
ShowMoreButton {
expanded = !expanded
@ -1409,16 +1397,7 @@ fun DisplayPeopleList(
modifier = Modifier
.align(Alignment.BottomCenter)
.fillMaxWidth()
.drawBehind {
drawRect(
Brush.verticalGradient(
colors = listOf(
backgroundColor.value.copy(alpha = 0f),
backgroundColor.value
)
)
)
}
.background(getGradient(backgroundColor))
) {
ShowMoreButton {
expanded = !expanded
@ -1618,16 +1597,7 @@ fun PinListHeader(
modifier = Modifier
.align(Alignment.BottomCenter)
.fillMaxWidth()
.drawBehind {
drawRect(
Brush.verticalGradient(
colors = listOf(
backgroundColor.value.copy(alpha = 0f),
backgroundColor.value
)
)
)
}
.background(getGradient(backgroundColor))
) {
ShowMoreButton {
expanded = !expanded
@ -1637,6 +1607,15 @@ fun PinListHeader(
}
}
fun getGradient(backgroundColor: MutableState<Color>): Brush {
return Brush.verticalGradient(
colors = listOf(
backgroundColor.value.copy(alpha = 0f),
backgroundColor.value
)
)
}
@Composable
private fun RenderAudioTrack(
note: Note,
@ -2017,7 +1996,7 @@ private fun ChannelNotePicture(baseChannel: Channel) {
.width(30.dp)
.height(30.dp)
.clip(shape = CircleShape)
.drawBehind { drawRect(backgroundColor) }
.background(backgroundColor)
.border(
2.dp,
backgroundColor,
@ -3049,7 +3028,7 @@ fun DisplayBlankAuthor(size: Dp, modifier: Modifier = Modifier) {
modifier
.size(size)
.clip(shape = CircleShape)
.drawBehind { drawRect(backgroundColor) }
.background(backgroundColor)
}
RobohashAsyncImage(

Wyświetl plik

@ -21,7 +21,6 @@ import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.drawBehind
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.compositeOver
import androidx.compose.ui.res.stringResource
@ -60,9 +59,7 @@ fun ZapUserSetCompose(zapSetCard: ZapUserSetCard, isInnerNote: Boolean = false,
Column(
modifier = Modifier
.drawBehind {
drawRect(backgroundColor.value)
}
.background(backgroundColor.value)
.clickable {
nav("User/${zapSetCard.user.pubkeyHex}")
}

Wyświetl plik

@ -53,7 +53,6 @@ import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
import androidx.compose.ui.draw.drawBehind
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.Shape
import androidx.compose.ui.graphics.SolidColor
@ -734,7 +733,7 @@ fun LiveFlag() {
modifier = remember {
Modifier
.clip(SmallBorder)
.drawBehind { drawRect(Color.Red) }
.background(Color.Red)
.padding(horizontal = 5.dp)
}
)
@ -749,7 +748,7 @@ fun EndedFlag() {
modifier = remember {
Modifier
.clip(SmallBorder)
.drawBehind { drawRect(Color.Black) }
.background(Color.Black)
.padding(horizontal = 5.dp)
}
)
@ -764,7 +763,7 @@ fun OfflineFlag() {
modifier = remember {
Modifier
.clip(SmallBorder)
.drawBehind { drawRect(Color.Black) }
.background(Color.Black)
.padding(horizontal = 5.dp)
}
)
@ -779,7 +778,7 @@ fun ScheduledFlag() {
modifier = remember {
Modifier
.clip(SmallBorder)
.drawBehind { drawRect(Color.Black) }
.background(Color.Black)
.padding(horizontal = 5.dp)
}
)

Wyświetl plik

@ -25,7 +25,6 @@ import androidx.compose.runtime.livedata.observeAsState
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
import androidx.compose.ui.draw.drawBehind
import androidx.compose.ui.geometry.Offset
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.input.nestedscroll.NestedScrollConnection
@ -1189,7 +1188,7 @@ private fun WatchAndRenderBadgeImage(
pictureModifier
.width(size)
.height(size)
.drawBehind { drawRect(bgColor) }
.background(bgColor)
}
)
} else {
@ -1202,7 +1201,7 @@ private fun WatchAndRenderBadgeImage(
.width(size)
.height(size)
.clip(shape = CircleShape)
.drawBehind { drawRect(bgColor) }
.background(bgColor)
.run {
if (onClick != null) {
this.clickable(onClick = { onClick(eventId) })

Wyświetl plik

@ -1,6 +1,7 @@
package com.vitorpamplona.amethyst.ui.theme
import android.app.Activity
import androidx.compose.foundation.background
import androidx.compose.foundation.border
import androidx.compose.foundation.isSystemInDarkTheme
import androidx.compose.foundation.layout.fillMaxWidth
@ -15,7 +16,6 @@ import androidx.compose.runtime.Composable
import androidx.compose.runtime.SideEffect
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
import androidx.compose.ui.draw.drawBehind
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.ColorFilter
import androidx.compose.ui.graphics.compositeOver
@ -123,12 +123,10 @@ val LightImageModifier = Modifier
val DarkProfile35dpModifier = Modifier
.size(Size35dp)
.clip(shape = CircleShape)
.drawBehind { drawRect(DarkColorPalette.background) }
val LightProfile35dpModifier = Modifier
.fillMaxWidth()
.clip(shape = CircleShape)
.drawBehind { drawRect(LightColorPalette.background) }
val DarkReplyBorderModifier = Modifier
.padding(top = 5.dp)
@ -189,9 +187,7 @@ val MarkDownStyleOnDark = RichTextDefaults.copy(
DarkSubtleBorder,
QuoteBorder
)
.drawBehind {
drawRect(DarkColorPalette.onSurface.copy(alpha = 0.05f))
}
.background(DarkColorPalette.onSurface.copy(alpha = 0.05f))
),
stringStyle = RichTextDefaults.stringStyle?.copy(
linkStyle = SpanStyle(
@ -222,9 +218,7 @@ val MarkDownStyleOnLight = RichTextDefaults.copy(
LightSubtleBorder,
QuoteBorder
)
.drawBehind {
drawRect(LightColorPalette.onSurface.copy(alpha = 0.05f))
}
.background(DarkColorPalette.onSurface.copy(alpha = 0.05f))
),
stringStyle = RichTextDefaults.stringStyle?.copy(
linkStyle = SpanStyle(