Skip to content

Commit

Permalink
fix(ui): avoid overhead by hoisting states
Browse files Browse the repository at this point in the history
  • Loading branch information
JunkFood02 committed Feb 19, 2024
1 parent 6b4b215 commit 4b594ba
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package me.ash.reader.ui.page.home.reading

import android.util.Log
import androidx.compose.animation.AnimatedContent
import androidx.compose.animation.AnimatedVisibility
import androidx.compose.animation.core.tween
Expand Down Expand Up @@ -50,7 +51,6 @@ fun Content(
publishedDate: Date,
listState: LazyListState,
isLoading: Boolean,
pullToLoadState: PullToLoadState,
onImageClick: ((imgUrl: String, altText: String) -> Unit)? = null,
) {
val context = LocalContext.current
Expand All @@ -72,8 +72,7 @@ fun Content(
LazyColumn(
modifier = modifier
.fillMaxSize()
.drawVerticalScrollbar(listState)
.offset(x = 0.dp, y = (pullToLoadState.offsetFraction * 80).dp),
.drawVerticalScrollbar(listState),
state = listState,
) {
item {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import androidx.compose.foundation.LocalOverscrollConfiguration
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.WindowInsets
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.offset
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.lazy.LazyListState
import androidx.compose.material.ExperimentalMaterialApi
Expand All @@ -26,6 +27,7 @@ import androidx.compose.ui.hapticfeedback.HapticFeedbackType
import androidx.compose.ui.input.nestedscroll.nestedScroll
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.platform.LocalHapticFeedback
import androidx.compose.ui.unit.dp
import androidx.hilt.navigation.compose.hiltViewModel
import androidx.navigation.NavHostController
import androidx.paging.compose.collectAsLazyPagingItems
Expand Down Expand Up @@ -129,11 +131,13 @@ fun ReadingPage(
}
materialSharedAxisY(
initialOffsetY = { (it * 0.1f * direction).toInt() },
targetOffsetY = { (it * -0.1f * direction).toInt() })
targetOffsetY = { (it * -0.1f * direction).toInt() },
durationMillis = 400
)
}, label = ""
) {

it.run {
remember { it }.run {
val state =
rememberPullToLoadState(
key = content,
Expand Down Expand Up @@ -177,8 +181,8 @@ fun ReadingPage(
isReaderScrollingDown = f < 0f
})
)

.padding(paddings),
.padding(paddings)
.offset(x = 0.dp, y = (state.offsetFraction * 80).dp),
content = content.text ?: "",
feedName = feedName,
title = title.toString(),
Expand All @@ -187,7 +191,6 @@ fun ReadingPage(
publishedDate = publishedDate,
isLoading = content is ReaderState.Loading,
listState = listState,
pullToLoadState = state,
onImageClick = { imgUrl, altText ->
currentImageData = ImageData(imgUrl, altText)
showFullScreenImageViewer = true
Expand Down

0 comments on commit 4b594ba

Please sign in to comment.