Performance: Improving the use or remember, less jittering when scrolling.

This commit is contained in:
Vitor Pamplona
2023-12-23 15:28:04 -05:00
parent e9285fdac0
commit 2d5be92f34
3 changed files with 44 additions and 30 deletions

View File

@ -153,10 +153,13 @@ import com.vitorpamplona.amethyst.ui.theme.StdVertSpacer
import com.vitorpamplona.amethyst.ui.theme.UserNameMaxRowHeight import com.vitorpamplona.amethyst.ui.theme.UserNameMaxRowHeight
import com.vitorpamplona.amethyst.ui.theme.UserNameRowHeight import com.vitorpamplona.amethyst.ui.theme.UserNameRowHeight
import com.vitorpamplona.amethyst.ui.theme.WidthAuthorPictureModifier import com.vitorpamplona.amethyst.ui.theme.WidthAuthorPictureModifier
import com.vitorpamplona.amethyst.ui.theme.boostedNoteModifier
import com.vitorpamplona.amethyst.ui.theme.channelNotePictureModifier import com.vitorpamplona.amethyst.ui.theme.channelNotePictureModifier
import com.vitorpamplona.amethyst.ui.theme.grayText import com.vitorpamplona.amethyst.ui.theme.grayText
import com.vitorpamplona.amethyst.ui.theme.mediumImportanceLink import com.vitorpamplona.amethyst.ui.theme.mediumImportanceLink
import com.vitorpamplona.amethyst.ui.theme.newItemBackgroundColor import com.vitorpamplona.amethyst.ui.theme.newItemBackgroundColor
import com.vitorpamplona.amethyst.ui.theme.normalNoteModifier
import com.vitorpamplona.amethyst.ui.theme.normalWithTopMarginNoteModifier
import com.vitorpamplona.amethyst.ui.theme.placeholderText import com.vitorpamplona.amethyst.ui.theme.placeholderText
import com.vitorpamplona.amethyst.ui.theme.replyBackground import com.vitorpamplona.amethyst.ui.theme.replyBackground
import com.vitorpamplona.amethyst.ui.theme.replyModifier import com.vitorpamplona.amethyst.ui.theme.replyModifier
@ -277,7 +280,7 @@ fun CheckHiddenNoteCompose(
) { ) {
if (showHidden) { if (showHidden) {
// Ignores reports as well // Ignores reports as well
val state by remember { val state by remember(note) {
mutableStateOf( mutableStateOf(
AccountViewModel.NoteComposeReportState() AccountViewModel.NoteComposeReportState()
) )
@ -338,7 +341,7 @@ fun LoadedNoteCompose(
accountViewModel: AccountViewModel, accountViewModel: AccountViewModel,
nav: (String) -> Unit nav: (String) -> Unit
) { ) {
var state by remember { var state by remember(note) {
mutableStateOf( mutableStateOf(
AccountViewModel.NoteComposeReportState() AccountViewModel.NoteComposeReportState()
) )
@ -383,7 +386,7 @@ fun RenderReportState(
accountViewModel: AccountViewModel, accountViewModel: AccountViewModel,
nav: (String) -> Unit nav: (String) -> Unit
) { ) {
var showReportedNote by remember { mutableStateOf(false) } var showReportedNote by remember(note) { mutableStateOf(false) }
Crossfade(targetState = !state.isAcceptable && !showReportedNote, label = "RenderReportState") { showHiddenNote -> Crossfade(targetState = !state.isAcceptable && !showReportedNote, label = "RenderReportState") { showHiddenNote ->
if (showHiddenNote) { if (showHiddenNote) {
@ -941,15 +944,12 @@ fun InnerNoteWithReactions(
val notBoostedNorQuote = !isBoostedNote && !isQuotedNote val notBoostedNorQuote = !isBoostedNote && !isQuotedNote
Row( Row(
modifier = remember { modifier = if (!isBoostedNote && addMarginTop) {
Modifier normalWithTopMarginNoteModifier
.fillMaxWidth() } else if (!isBoostedNote) {
.padding( normalNoteModifier
start = if (!isBoostedNote) 12.dp else 0.dp, } else {
end = if (!isBoostedNote) 12.dp else 0.dp, boostedNoteModifier
top = if (addMarginTop && !isBoostedNote) 10.dp else 0.dp
// Don't add margin to the bottom because of the Divider down below
)
} }
) { ) {
if (notBoostedNorQuote) { if (notBoostedNorQuote) {
@ -2671,31 +2671,24 @@ private fun RenderAuthorImages(
nav: (String) -> Unit, nav: (String) -> Unit,
accountViewModel: AccountViewModel accountViewModel: AccountViewModel
) { ) {
val baseRepost by remember {
derivedStateOf {
baseNote.replyTo?.lastOrNull()
}
}
val isRepost = baseNote.event is RepostEvent || baseNote.event is GenericRepostEvent val isRepost = baseNote.event is RepostEvent || baseNote.event is GenericRepostEvent
if (isRepost && baseRepost != null) { if (isRepost) {
RepostNoteAuthorPicture(baseNote, baseRepost!!, accountViewModel, nav) val baseRepost = baseNote.replyTo?.lastOrNull()
if (baseRepost != null) {
RepostNoteAuthorPicture(baseNote, baseRepost, accountViewModel, nav)
} else {
NoteAuthorPicture(baseNote, nav, accountViewModel, Size55dp)
}
} else { } else {
NoteAuthorPicture(baseNote, nav, accountViewModel, Size55dp) NoteAuthorPicture(baseNote, nav, accountViewModel, Size55dp)
} }
val isChannel = baseNote.event is ChannelMessageEvent && baseNote.channelHex() != null if (baseNote.event is ChannelMessageEvent) {
val baseChannelHex = remember(baseNote) { baseNote.channelHex() }
val automaticallyShowProfilePicture = remember {
accountViewModel.settings.showProfilePictures.value
}
if (isChannel) {
val baseChannelHex = remember { baseNote.channelHex() }
if (baseChannelHex != null) { if (baseChannelHex != null) {
LoadChannel(baseChannelHex, accountViewModel) { channel -> LoadChannel(baseChannelHex, accountViewModel) { channel ->
ChannelNotePicture(channel, loadProfilePicture = automaticallyShowProfilePicture) ChannelNotePicture(channel, loadProfilePicture = accountViewModel.settings.showProfilePictures.value)
} }
} }
} }

View File

@ -126,7 +126,7 @@ fun ReactionsRow(
accountViewModel: AccountViewModel, accountViewModel: AccountViewModel,
nav: (String) -> Unit nav: (String) -> Unit
) { ) {
val wantsToSeeReactions = remember { val wantsToSeeReactions = remember(baseNote) {
mutableStateOf(false) mutableStateOf(false)
} }

View File

@ -161,3 +161,24 @@ val IconRowModifier = Modifier
.padding(vertical = 15.dp, horizontal = 25.dp) .padding(vertical = 15.dp, horizontal = 25.dp)
val emptyLineItemModifier = Modifier.height(Size75dp).fillMaxWidth() val emptyLineItemModifier = Modifier.height(Size75dp).fillMaxWidth()
val normalNoteModifier = Modifier.fillMaxWidth()
.padding(
start = 12.dp,
end = 12.dp,
top = 0.dp
)
val normalWithTopMarginNoteModifier = Modifier.fillMaxWidth()
.padding(
start = 12.dp,
end = 12.dp,
top = 10.dp
)
val boostedNoteModifier = Modifier.fillMaxWidth()
.padding(
start = 0.dp,
end = 0.dp,
top = 0.dp
)