fix(ui): avoid overhead by hoisting states
This commit is contained in:
parent
6b4b2151bc
commit
4b594badb7
@ -1,5 +1,6 @@
|
|||||||
package me.ash.reader.ui.page.home.reading
|
package me.ash.reader.ui.page.home.reading
|
||||||
|
|
||||||
|
import android.util.Log
|
||||||
import androidx.compose.animation.AnimatedContent
|
import androidx.compose.animation.AnimatedContent
|
||||||
import androidx.compose.animation.AnimatedVisibility
|
import androidx.compose.animation.AnimatedVisibility
|
||||||
import androidx.compose.animation.core.tween
|
import androidx.compose.animation.core.tween
|
||||||
@ -50,7 +51,6 @@ fun Content(
|
|||||||
publishedDate: Date,
|
publishedDate: Date,
|
||||||
listState: LazyListState,
|
listState: LazyListState,
|
||||||
isLoading: Boolean,
|
isLoading: Boolean,
|
||||||
pullToLoadState: PullToLoadState,
|
|
||||||
onImageClick: ((imgUrl: String, altText: String) -> Unit)? = null,
|
onImageClick: ((imgUrl: String, altText: String) -> Unit)? = null,
|
||||||
) {
|
) {
|
||||||
val context = LocalContext.current
|
val context = LocalContext.current
|
||||||
@ -72,8 +72,7 @@ fun Content(
|
|||||||
LazyColumn(
|
LazyColumn(
|
||||||
modifier = modifier
|
modifier = modifier
|
||||||
.fillMaxSize()
|
.fillMaxSize()
|
||||||
.drawVerticalScrollbar(listState)
|
.drawVerticalScrollbar(listState),
|
||||||
.offset(x = 0.dp, y = (pullToLoadState.offsetFraction * 80).dp),
|
|
||||||
state = listState,
|
state = listState,
|
||||||
) {
|
) {
|
||||||
item {
|
item {
|
||||||
|
@ -7,6 +7,7 @@ import androidx.compose.foundation.LocalOverscrollConfiguration
|
|||||||
import androidx.compose.foundation.layout.Box
|
import androidx.compose.foundation.layout.Box
|
||||||
import androidx.compose.foundation.layout.WindowInsets
|
import androidx.compose.foundation.layout.WindowInsets
|
||||||
import androidx.compose.foundation.layout.fillMaxSize
|
import androidx.compose.foundation.layout.fillMaxSize
|
||||||
|
import androidx.compose.foundation.layout.offset
|
||||||
import androidx.compose.foundation.layout.padding
|
import androidx.compose.foundation.layout.padding
|
||||||
import androidx.compose.foundation.lazy.LazyListState
|
import androidx.compose.foundation.lazy.LazyListState
|
||||||
import androidx.compose.material.ExperimentalMaterialApi
|
import androidx.compose.material.ExperimentalMaterialApi
|
||||||
@ -26,6 +27,7 @@ import androidx.compose.ui.hapticfeedback.HapticFeedbackType
|
|||||||
import androidx.compose.ui.input.nestedscroll.nestedScroll
|
import androidx.compose.ui.input.nestedscroll.nestedScroll
|
||||||
import androidx.compose.ui.platform.LocalContext
|
import androidx.compose.ui.platform.LocalContext
|
||||||
import androidx.compose.ui.platform.LocalHapticFeedback
|
import androidx.compose.ui.platform.LocalHapticFeedback
|
||||||
|
import androidx.compose.ui.unit.dp
|
||||||
import androidx.hilt.navigation.compose.hiltViewModel
|
import androidx.hilt.navigation.compose.hiltViewModel
|
||||||
import androidx.navigation.NavHostController
|
import androidx.navigation.NavHostController
|
||||||
import androidx.paging.compose.collectAsLazyPagingItems
|
import androidx.paging.compose.collectAsLazyPagingItems
|
||||||
@ -129,11 +131,13 @@ fun ReadingPage(
|
|||||||
}
|
}
|
||||||
materialSharedAxisY(
|
materialSharedAxisY(
|
||||||
initialOffsetY = { (it * 0.1f * direction).toInt() },
|
initialOffsetY = { (it * 0.1f * direction).toInt() },
|
||||||
targetOffsetY = { (it * -0.1f * direction).toInt() })
|
targetOffsetY = { (it * -0.1f * direction).toInt() },
|
||||||
|
durationMillis = 400
|
||||||
|
)
|
||||||
}, label = ""
|
}, label = ""
|
||||||
) {
|
) {
|
||||||
|
|
||||||
it.run {
|
remember { it }.run {
|
||||||
val state =
|
val state =
|
||||||
rememberPullToLoadState(
|
rememberPullToLoadState(
|
||||||
key = content,
|
key = content,
|
||||||
@ -177,8 +181,8 @@ fun ReadingPage(
|
|||||||
isReaderScrollingDown = f < 0f
|
isReaderScrollingDown = f < 0f
|
||||||
})
|
})
|
||||||
)
|
)
|
||||||
|
.padding(paddings)
|
||||||
.padding(paddings),
|
.offset(x = 0.dp, y = (state.offsetFraction * 80).dp),
|
||||||
content = content.text ?: "",
|
content = content.text ?: "",
|
||||||
feedName = feedName,
|
feedName = feedName,
|
||||||
title = title.toString(),
|
title = title.toString(),
|
||||||
@ -187,7 +191,6 @@ fun ReadingPage(
|
|||||||
publishedDate = publishedDate,
|
publishedDate = publishedDate,
|
||||||
isLoading = content is ReaderState.Loading,
|
isLoading = content is ReaderState.Loading,
|
||||||
listState = listState,
|
listState = listState,
|
||||||
pullToLoadState = state,
|
|
||||||
onImageClick = { imgUrl, altText ->
|
onImageClick = { imgUrl, altText ->
|
||||||
currentImageData = ImageData(imgUrl, altText)
|
currentImageData = ImageData(imgUrl, altText)
|
||||||
showFullScreenImageViewer = true
|
showFullScreenImageViewer = true
|
||||||
|
Loading…
x
Reference in New Issue
Block a user