Removing unnecessary modifiers and remember calls

This commit is contained in:
Vitor Pamplona 2024-06-14 08:22:38 -04:00
parent ca8d32b837
commit 52a24d5223
4 changed files with 25 additions and 37 deletions

View File

@ -41,7 +41,6 @@ import androidx.compose.runtime.Composable
import androidx.compose.runtime.Immutable import androidx.compose.runtime.Immutable
import androidx.compose.runtime.LaunchedEffect import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.MutableState import androidx.compose.runtime.MutableState
import androidx.compose.runtime.derivedStateOf
import androidx.compose.runtime.getValue import androidx.compose.runtime.getValue
import androidx.compose.runtime.livedata.observeAsState import androidx.compose.runtime.livedata.observeAsState
import androidx.compose.runtime.mutableStateOf import androidx.compose.runtime.mutableStateOf
@ -118,15 +117,15 @@ fun MultiSetCompose(
val columnModifier = val columnModifier =
remember(backgroundColor.value) { remember(backgroundColor.value) {
Modifier.fillMaxWidth() Modifier
.fillMaxWidth()
.background(backgroundColor.value) .background(backgroundColor.value)
.combinedClickable( .combinedClickable(
onClick = { onClick = {
scope.launch { routeFor(baseNote, accountViewModel.userProfile())?.let { nav(it) } } scope.launch { routeFor(baseNote, accountViewModel.userProfile())?.let { nav(it) } }
}, },
onLongClick = enablePopup, onLongClick = enablePopup,
) ).padding(
.padding(
start = 12.dp, start = 12.dp,
end = 12.dp, end = 12.dp,
top = 10.dp, top = 10.dp,
@ -163,13 +162,9 @@ private fun Galeries(
accountViewModel: AccountViewModel, accountViewModel: AccountViewModel,
nav: (String) -> Unit, nav: (String) -> Unit,
) { ) {
val hasZapEvents by remember { derivedStateOf { multiSetCard.zapEvents.isNotEmpty() } } if (multiSetCard.zapEvents.isNotEmpty()) {
val hasBoostEvents by remember { derivedStateOf { multiSetCard.boostEvents.isNotEmpty() } }
val hasLikeEvents by remember { derivedStateOf { multiSetCard.likeEvents.isNotEmpty() } }
if (hasZapEvents) {
var zapEvents by var zapEvents by
remember(multiSetCard.zapEvents) { remember(multiSetCard) {
mutableStateOf( mutableStateOf(
accountViewModel.cachedDecryptAmountMessageInGroup(multiSetCard.zapEvents), accountViewModel.cachedDecryptAmountMessageInGroup(multiSetCard.zapEvents),
) )
@ -182,11 +177,11 @@ private fun Galeries(
RenderZapGallery(zapEvents, backgroundColor, nav, accountViewModel) RenderZapGallery(zapEvents, backgroundColor, nav, accountViewModel)
} }
if (hasBoostEvents) { if (multiSetCard.boostEvents.isNotEmpty()) {
RenderBoostGallery(multiSetCard.boostEvents, nav, accountViewModel) RenderBoostGallery(multiSetCard.boostEvents, nav, accountViewModel)
} }
if (hasLikeEvents) { if (multiSetCard.likeEvents.isNotEmpty()) {
multiSetCard.likeEventsByType.forEach { multiSetCard.likeEventsByType.forEach {
RenderLikeGallery(it.key, it.value, nav, accountViewModel) RenderLikeGallery(it.key, it.value, nav, accountViewModel)
} }

View File

@ -137,7 +137,6 @@ import kotlinx.collections.immutable.ImmutableList
import kotlinx.collections.immutable.ImmutableSet import kotlinx.collections.immutable.ImmutableSet
import kotlinx.collections.immutable.persistentListOf import kotlinx.collections.immutable.persistentListOf
import kotlinx.collections.immutable.toImmutableList import kotlinx.collections.immutable.toImmutableList
import kotlinx.collections.immutable.toImmutableMap
import kotlinx.collections.immutable.toImmutableSet import kotlinx.collections.immutable.toImmutableSet
import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch import kotlinx.coroutines.launch
@ -270,7 +269,10 @@ private fun LoadAndDisplayZapraiser(
} }
} }
@Immutable data class ZapraiserStatus(val progress: Float, val left: String) @Immutable data class ZapraiserStatus(
val progress: Float,
val left: String,
)
@Composable @Composable
fun RenderZapRaiser( fun RenderZapRaiser(
@ -453,12 +455,11 @@ private fun WatchReactionsAndRenderGallery(
accountViewModel: AccountViewModel, accountViewModel: AccountViewModel,
) { ) {
val reactionsState by baseNote.live().reactions.observeAsState() val reactionsState by baseNote.live().reactions.observeAsState()
val reactionEvents by val reactionEvents = reactionsState?.note?.reactions ?: return
remember(reactionsState) { derivedStateOf { baseNote.reactions.toImmutableMap() } }
if (reactionEvents.isNotEmpty()) { if (reactionEvents.isNotEmpty()) {
reactionEvents.forEach { reactionEvents.forEach {
val reactions = remember(it.value) { it.value.toImmutableList() } val reactions = remember(it.key) { it.value.toImmutableList() }
RenderLikeGallery( RenderLikeGallery(
it.key, it.key,
reactions, reactions,
@ -636,9 +637,7 @@ private fun SlidingAnimationCount(
} }
@OptIn(ExperimentalAnimationApi::class) @OptIn(ExperimentalAnimationApi::class)
private fun <S> AnimatedContentTransitionScope<S>.transitionSpec(): ContentTransform { private fun <S> AnimatedContentTransitionScope<S>.transitionSpec(): ContentTransform = slideAnimation
return slideAnimation
}
@ExperimentalAnimationApi @ExperimentalAnimationApi
val slideAnimation: ContentTransform = val slideAnimation: ContentTransform =
@ -647,13 +646,12 @@ val slideAnimation: ContentTransform =
fadeIn( fadeIn(
animationSpec = tween(durationMillis = 100), animationSpec = tween(durationMillis = 100),
) )
).togetherWith(
slideOutVertically(animationSpec = tween(durationMillis = 100)) { height -> -height } +
fadeOut(
animationSpec = tween(durationMillis = 100),
),
) )
.togetherWith(
slideOutVertically(animationSpec = tween(durationMillis = 100)) { height -> -height } +
fadeOut(
animationSpec = tween(durationMillis = 100),
),
)
@Composable @Composable
fun TextCount( fun TextCount(
@ -744,10 +742,9 @@ fun ObserveBoostIcon(
.boosts .boosts
.map { it.note.isBoostedBy(accountViewModel.userProfile()) } .map { it.note.isBoostedBy(accountViewModel.userProfile()) }
.distinctUntilChanged() .distinctUntilChanged()
} }.observeAsState(
.observeAsState( baseNote.isBoostedBy(accountViewModel.userProfile()),
baseNote.isBoostedBy(accountViewModel.userProfile()), )
)
inner(hasBoosted) inner(hasBoosted)
} }
@ -1066,8 +1063,7 @@ fun ZapReaction(
targetValue = zappingProgress, targetValue = zappingProgress,
animationSpec = ProgressIndicatorDefaults.ProgressAnimationSpec, animationSpec = ProgressIndicatorDefaults.ProgressAnimationSpec,
label = "ZapIconIndicator", label = "ZapIconIndicator",
) ).value,
.value,
modifier = remember { Modifier.size(animationSize) }, modifier = remember { Modifier.size(animationSize) },
strokeWidth = 2.dp, strokeWidth = 2.dp,
) )
@ -1210,7 +1206,8 @@ private fun DrawViewCount(
AsyncImage( AsyncImage(
model = model =
remember(note) { remember(note) {
ImageRequest.Builder(context) ImageRequest
.Builder(context)
.data("https://counter.amethyst.social/${note.idHex}.svg?label=+&color=00000000") .data("https://counter.amethyst.social/${note.idHex}.svg?label=+&color=00000000")
.diskCachePolicy(CachePolicy.DISABLED) .diskCachePolicy(CachePolicy.DISABLED)
.memoryCachePolicy(CachePolicy.ENABLED) .memoryCachePolicy(CachePolicy.ENABLED)

View File

@ -60,7 +60,6 @@ fun RenderNIP90ContentDiscoveryResponse(
nav: (String) -> Unit, nav: (String) -> Unit,
) { ) {
val noteEvent = note.event val noteEvent = note.event
val modifier = remember(note) { Modifier.fillMaxWidth() }
val showReply by val showReply by
remember(note) { remember(note) {

View File

@ -20,7 +20,6 @@
*/ */
package com.vitorpamplona.amethyst.ui.note.types package com.vitorpamplona.amethyst.ui.note.types
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.material3.Text import androidx.compose.material3.Text
import androidx.compose.runtime.Composable import androidx.compose.runtime.Composable
import androidx.compose.runtime.MutableState import androidx.compose.runtime.MutableState
@ -28,7 +27,6 @@ import androidx.compose.runtime.State
import androidx.compose.runtime.derivedStateOf import androidx.compose.runtime.derivedStateOf
import androidx.compose.runtime.getValue import androidx.compose.runtime.getValue
import androidx.compose.runtime.remember import androidx.compose.runtime.remember
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color import androidx.compose.ui.graphics.Color
import com.vitorpamplona.amethyst.model.Note import com.vitorpamplona.amethyst.model.Note
import com.vitorpamplona.amethyst.ui.components.GenericLoadable import com.vitorpamplona.amethyst.ui.components.GenericLoadable
@ -51,7 +49,6 @@ fun RenderNIP90Status(
nav: (String) -> Unit, nav: (String) -> Unit,
) { ) {
val noteEvent = note.event val noteEvent = note.event
val modifier = remember(note) { Modifier.fillMaxWidth() }
val showReply by val showReply by
remember(note) { remember(note) {