Improve history screen scrolling perf (#7399)

This commit is contained in:
Ivan Iskandar 2022-06-28 05:33:57 +07:00 committed by GitHub
parent 7440086ef1
commit e44bb30996
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 35 additions and 29 deletions

View File

@ -99,28 +99,6 @@ fun HistoryContent(
val scrollState = rememberLazyListState() val scrollState = rememberLazyListState()
val transition = rememberInfiniteTransition()
val translateAnimation = transition.animateFloat(
initialValue = 0f,
targetValue = 1000f,
animationSpec = infiniteRepeatable(
animation = tween(
durationMillis = 1000,
easing = LinearEasing,
),
),
)
val brush = linearGradient(
colors = shimmerGradient,
start = Offset(0f, 0f),
end = Offset(
x = translateAnimation.value,
y = 00f,
),
)
ScrollbarLazyColumn( ScrollbarLazyColumn(
modifier = Modifier modifier = Modifier
.nestedScroll(nestedScroll), .nestedScroll(nestedScroll),
@ -149,6 +127,28 @@ fun HistoryContent(
) )
} }
null -> { null -> {
val transition = rememberInfiniteTransition()
val translateAnimation = transition.animateFloat(
initialValue = 0f,
targetValue = 1000f,
animationSpec = infiniteRepeatable(
animation = tween(
durationMillis = 1000,
easing = LinearEasing,
),
),
)
val brush = remember {
linearGradient(
colors = shimmerGradient,
start = Offset(0f, 0f),
end = Offset(
x = translateAnimation.value,
y = 00f,
),
)
}
HistoryItemShimmer(brush = brush) HistoryItemShimmer(brush = brush)
} }
} }

View File

@ -4,6 +4,7 @@ import androidx.compose.foundation.layout.padding
import androidx.compose.material3.MaterialTheme import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Text import androidx.compose.material3.Text
import androidx.compose.runtime.Composable import androidx.compose.runtime.Composable
import androidx.compose.runtime.remember
import androidx.compose.ui.Modifier import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.LocalContext import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.text.font.FontWeight import androidx.compose.ui.text.font.FontWeight
@ -20,14 +21,17 @@ fun HistoryHeader(
relativeTime: Int, relativeTime: Int,
dateFormat: DateFormat, dateFormat: DateFormat,
) { ) {
val context = LocalContext.current
Text( Text(
modifier = modifier modifier = modifier
.padding(horizontal = horizontalPadding, vertical = 8.dp), .padding(horizontal = horizontalPadding, vertical = 8.dp),
text = date.toRelativeString( text = remember {
LocalContext.current, date.toRelativeString(
relativeTime, context,
dateFormat, relativeTime,
), dateFormat,
)
},
style = MaterialTheme.typography.bodyMedium.copy( style = MaterialTheme.typography.bodyMedium.copy(
color = MaterialTheme.colorScheme.onSurfaceVariant, color = MaterialTheme.colorScheme.onSurfaceVariant,
fontWeight = FontWeight.SemiBold, fontWeight = FontWeight.SemiBold,

View File

@ -17,6 +17,7 @@ import androidx.compose.material3.IconButton
import androidx.compose.material3.MaterialTheme import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Text import androidx.compose.material3.Text
import androidx.compose.runtime.Composable import androidx.compose.runtime.Composable
import androidx.compose.runtime.remember
import androidx.compose.ui.Alignment import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip import androidx.compose.ui.draw.clip
@ -68,15 +69,16 @@ fun HistoryItem(
overflow = TextOverflow.Ellipsis, overflow = TextOverflow.Ellipsis,
style = textStyle.copy(fontWeight = FontWeight.SemiBold), style = textStyle.copy(fontWeight = FontWeight.SemiBold),
) )
val readAt = remember { history.readAt?.toTimestampString() ?: "" }
Text( Text(
text = if (history.chapterNumber > -1) { text = if (history.chapterNumber > -1) {
stringResource( stringResource(
R.string.recent_manga_time, R.string.recent_manga_time,
chapterFormatter.format(history.chapterNumber), chapterFormatter.format(history.chapterNumber),
history.readAt?.toTimestampString() ?: "", readAt,
) )
} else { } else {
history.readAt?.toTimestampString() ?: "" readAt
}, },
modifier = Modifier.padding(top = 4.dp), modifier = Modifier.padding(top = 4.dp),
style = textStyle, style = textStyle,