🛠️ More precise control over text entry visibility

This commit is contained in:
Acclorite 2025-01-08 13:20:52 +02:00
parent 092bbfd10b
commit b1f7e6176f
2 changed files with 52 additions and 47 deletions

View file

@ -10,7 +10,6 @@ import androidx.compose.foundation.layout.displayCutout
import androidx.compose.foundation.layout.fillMaxSize import androidx.compose.foundation.layout.fillMaxSize
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.foundation.lazy.itemsIndexed
import androidx.compose.runtime.Composable import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier import androidx.compose.ui.Modifier
@ -150,13 +149,11 @@ fun ReaderLayout(
.coerceAtLeast(18.dp), .coerceAtLeast(18.dp),
) )
) { ) {
itemsIndexed( for (entry in text) {
text, key = { index, _ -> index }
) { index, textEntry ->
ReaderLayoutText( ReaderLayoutText(
activity = activity, activity = activity,
showMenu = showMenu, showMenu = showMenu,
entry = textEntry, entry = entry,
fontFamily = fontFamily, fontFamily = fontFamily,
fontColor = fontColor, fontColor = fontColor,
lineHeight = lineHeight, lineHeight = lineHeight,

View file

@ -1,8 +1,9 @@
@file:Suppress("FunctionName")
package ua.acclorite.book_story.presentation.reader package ua.acclorite.book_story.presentation.reader
import androidx.activity.ComponentActivity import androidx.activity.ComponentActivity
import androidx.compose.foundation.lazy.LazyItemScope import androidx.compose.foundation.lazy.LazyListScope
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment import androidx.compose.ui.Alignment
import androidx.compose.ui.graphics.Color import androidx.compose.ui.graphics.Color
import androidx.compose.ui.text.font.FontStyle import androidx.compose.ui.text.font.FontStyle
@ -14,8 +15,7 @@ import ua.acclorite.book_story.domain.reader.ReaderText
import ua.acclorite.book_story.domain.reader.ReaderTextAlignment import ua.acclorite.book_story.domain.reader.ReaderTextAlignment
import ua.acclorite.book_story.ui.reader.ReaderEvent import ua.acclorite.book_story.ui.reader.ReaderEvent
@Composable fun LazyListScope.ReaderLayoutText(
fun LazyItemScope.ReaderLayoutText(
activity: ComponentActivity, activity: ComponentActivity,
showMenu: Boolean, showMenu: Boolean,
entry: ReaderText, entry: ReaderText,
@ -40,53 +40,61 @@ fun LazyItemScope.ReaderLayoutText(
) { ) {
when (entry) { when (entry) {
is ReaderText.Image -> { is ReaderText.Image -> {
ReaderLayoutTextImage( item {
entry = entry, ReaderLayoutTextImage(
sidePadding = sidePadding entry = entry,
) sidePadding = sidePadding
)
}
} }
is ReaderText.Separator -> { is ReaderText.Separator -> {
ReaderLayoutTextSeparator( item {
sidePadding = sidePadding, ReaderLayoutTextSeparator(
fontColor = fontColor sidePadding = sidePadding,
) fontColor = fontColor
)
}
} }
is ReaderText.Chapter -> { is ReaderText.Chapter -> {
ReaderLayoutTextChapter( item {
chapter = entry, ReaderLayoutTextChapter(
chapterTitleAlignment = chapterTitleAlignment, chapter = entry,
fontColor = fontColor, chapterTitleAlignment = chapterTitleAlignment,
sidePadding = sidePadding, fontColor = fontColor,
highlightedReading = highlightedReading, sidePadding = sidePadding,
highlightedReadingThickness = highlightedReadingThickness highlightedReading = highlightedReading,
) highlightedReadingThickness = highlightedReadingThickness
)
}
} }
is ReaderText.Text -> { is ReaderText.Text -> {
ReaderLayoutTextParagraph( item {
paragraph = entry, ReaderLayoutTextParagraph(
activity = activity, paragraph = entry,
showMenu = showMenu, activity = activity,
fontFamily = fontFamily, showMenu = showMenu,
fontColor = fontColor, fontFamily = fontFamily,
lineHeight = lineHeight, fontColor = fontColor,
fontStyle = fontStyle, lineHeight = lineHeight,
textAlignment = textAlignment, fontStyle = fontStyle,
horizontalAlignment = horizontalAlignment, textAlignment = textAlignment,
fontSize = fontSize, horizontalAlignment = horizontalAlignment,
letterSpacing = letterSpacing, fontSize = fontSize,
sidePadding = sidePadding, letterSpacing = letterSpacing,
paragraphIndentation = paragraphIndentation, sidePadding = sidePadding,
fullscreenMode = fullscreenMode, paragraphIndentation = paragraphIndentation,
doubleClickTranslation = doubleClickTranslation, fullscreenMode = fullscreenMode,
highlightedReading = highlightedReading, doubleClickTranslation = doubleClickTranslation,
highlightedReadingThickness = highlightedReadingThickness, highlightedReading = highlightedReading,
toolbarHidden = toolbarHidden, highlightedReadingThickness = highlightedReadingThickness,
openTranslator = openTranslator, toolbarHidden = toolbarHidden,
menuVisibility = menuVisibility openTranslator = openTranslator,
) menuVisibility = menuVisibility
)
}
} }
} }
} }