Moving more variables to remember clauses

This commit is contained in:
Vitor Pamplona 2023-05-22 20:04:23 -04:00
parent a3fc22a04a
commit 0bf94f316f
5 changed files with 26 additions and 13 deletions

View File

@ -84,8 +84,8 @@ private fun DisplayEvent(
noteBase?.let {
val noteState by it.live().metadata.observeAsState()
val note = noteState?.note ?: return
val channel = note.channel()
val note = remember(noteState) { noteState?.note } ?: return
val channel = remember(noteState) { note.channel() }
if (note.event is ChannelCreateEvent) {
CreateClickableText(
@ -105,7 +105,7 @@ private fun DisplayEvent(
CreateClickableText(
clickablePart = channel.toBestDisplayName(),
suffix = "${nip19.additionalChars} ",
route = "Channel/${note.channel()?.idHex}",
route = "Channel/${channel.idHex}",
navController = navController
)
} else {
@ -196,7 +196,7 @@ private fun DisplayAddress(
noteBase?.let {
val noteState by it.live().metadata.observeAsState()
val note = noteState?.note ?: return
val note = remember(noteState) { noteState?.note } ?: return
CreateClickableText(
clickablePart = "@${note.idDisplayNote()}",

View File

@ -82,10 +82,15 @@ fun MultiSetCompose(multiSetCard: MultiSetCard, routeForLastRead: String, accoun
}
}
val backgroundColor = if (isNew) {
MaterialTheme.colors.primary.copy(0.12f).compositeOver(MaterialTheme.colors.background)
} else {
MaterialTheme.colors.background
val primaryColor = MaterialTheme.colors.primary.copy(0.12f)
val defaultBackgroundColor = MaterialTheme.colors.background
val backgroundColor = remember(isNew) {
if (isNew) {
primaryColor.compositeOver(defaultBackgroundColor)
} else {
defaultBackgroundColor
}
}
val columnModifier = remember(isNew) {

View File

@ -19,6 +19,7 @@ import androidx.compose.runtime.getValue
import androidx.compose.runtime.livedata.observeAsState
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.rememberCoroutineScope
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
@ -34,7 +35,7 @@ import com.vitorpamplona.amethyst.model.UserMetadata
import com.vitorpamplona.amethyst.service.Nip05Verifier
import com.vitorpamplona.amethyst.ui.theme.Nip05
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.withContext
import kotlinx.coroutines.launch
import java.util.Date
@Composable
@ -50,9 +51,11 @@ fun nip05VerificationAsAState(user: UserMetadata, pubkeyHex: String): State<Bool
mutableStateOf(default)
}
val scope = rememberCoroutineScope()
LaunchedEffect(key1 = user) {
if (nip05Verified.value == null) {
withContext(Dispatchers.IO) {
scope.launch(Dispatchers.IO) {
user.nip05?.ifBlank { null }?.let { nip05 ->
Nip05Verifier().verifyNip05(
nip05,

View File

@ -1169,12 +1169,14 @@ private fun FirstUserInfoRow(
@Composable
fun TimeAgo(time: Long) {
val context = LocalContext.current
var timeStr by remember { mutableStateOf("") }
LaunchedEffect(key1 = time) {
withContext(Dispatchers.IO) {
timeStr = timeAgo(time, context = context)
val newTimeStr = timeAgo(time, context = context)
if (newTimeStr != timeStr) {
timeStr = newTimeStr
}
}
}

View File

@ -352,10 +352,13 @@ fun ZapReaction(
scope.launch(Dispatchers.IO) {
if (!wasZappedByLoggedInUser) {
wasZappedByLoggedInUser = accountViewModel.calculateIfNoteWasZappedByAccount(zappedNote)
zappingProgress = 1f
}
zapAmountTxt = showAmount(account.calculateZappedAmount(zappedNote))
if (wasZappedByLoggedInUser) {
zappingProgress = 1f
}
}
}