Skip to content

Commit 2bdade9

Browse files
committed
Fixed crash when table had no columns
1 parent 28063c3 commit 2bdade9

File tree

4 files changed

+57
-72
lines changed

4 files changed

+57
-72
lines changed

app/src/main/java/com/nononsenseapps/feeder/ui/compose/editfeed/EditFeedScreen.kt

+2-4
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@ import androidx.compose.ui.ExperimentalComposeUiApi
4646
import androidx.compose.ui.Modifier
4747
import androidx.compose.ui.focus.FocusDirection
4848
import androidx.compose.ui.focus.FocusRequester
49-
import androidx.compose.ui.focus.FocusRequester.Companion.createRefs
5049
import androidx.compose.ui.focus.focusProperties
5150
import androidx.compose.ui.focus.focusRequester
5251
import androidx.compose.ui.focus.onFocusChanged
@@ -254,9 +253,8 @@ fun EditFeedView(
254253
) {
255254
val dimens = LocalDimens.current
256255

257-
val (leftFocusRequester, rightFocusRequester) = remember {
258-
createRefs()
259-
}
256+
val leftFocusRequester = remember { FocusRequester() }
257+
val rightFocusRequester = remember { FocusRequester() }
260258

261259
OkCancelWithContent(
262260
onOk = {

app/src/main/java/com/nononsenseapps/feeder/ui/compose/feedarticle/ArticleScreen.kt

+2-3
Original file line numberDiff line numberDiff line change
@@ -188,9 +188,8 @@ fun ArticleScreen(
188188
bottomBarVisibleState.targetState = viewState.isBottomBarVisible
189189
}
190190

191-
val (focusArticle, focusTopBar) = remember {
192-
FocusRequester.createRefs()
193-
}
191+
val focusArticle = remember { FocusRequester() }
192+
val focusTopBar = remember { FocusRequester() }
194193

195194
Scaffold(
196195
modifier = modifier

app/src/main/java/com/nononsenseapps/feeder/ui/compose/text/HtmlToComposable.kt

+53-51
Original file line numberDiff line numberDiff line change
@@ -888,7 +888,7 @@ private fun EagerComposer.tableColFirst(
888888
.filter {
889889
it.tagName() in setOf("th", "td")
890890
}.count()
891-
}.max()
891+
}.maxOrNull() ?: 0
892892
}
893893
}
894894

@@ -952,58 +952,60 @@ private fun EagerComposer.tableColFirst(
952952
}
953953

954954
key(rowCount, colCount, rowData, baseUrl, onLinkClick) {
955-
LazyRow(
956-
horizontalArrangement = Arrangement.spacedBy(32.dp),
957-
modifier = Modifier
958-
.horizontalScroll(rememberScrollState())
959-
.width(dimens.maxReaderWidth),
960-
) {
961-
items(
962-
count = colCount,
963-
) { colIndex ->
964-
Column(
965-
verticalArrangement = Arrangement.spacedBy(4.dp),
966-
modifier = Modifier,
967-
) {
968-
for (rowIndex in 0 until rowCount) {
969-
val (section, rowElement) = rowData.getOrNull(rowIndex) ?: break
970-
var emptyCell = false
971-
Surface(
972-
tonalElevation = when (section) {
973-
"thead" -> 3.dp
974-
"tbody" -> 0.dp
975-
"tfoot" -> 1.dp
976-
else -> 0.dp
977-
},
978-
) {
979-
rowElement.children()
980-
.filter { it.tagName() in setOf("th", "td") }
981-
.elementAtOrNullWithSpans(colIndex)
982-
?.let { colElement ->
983-
withParagraph {
984-
withStyle(
985-
if (colElement.tagName() == "th") {
986-
SpanStyle(fontWeight = FontWeight.Bold)
987-
} else {
988-
null
989-
},
990-
) {
991-
appendTextChildren(
992-
colElement.childNodes(),
993-
baseUrl = baseUrl,
994-
onLinkClick = onLinkClick,
995-
keyHolder = keyHolder,
996-
)
955+
if (rowCount > 0 && colCount > 0) {
956+
LazyRow(
957+
horizontalArrangement = Arrangement.spacedBy(32.dp),
958+
modifier = Modifier
959+
.horizontalScroll(rememberScrollState())
960+
.width(dimens.maxReaderWidth),
961+
) {
962+
items(
963+
count = colCount,
964+
) { colIndex ->
965+
Column(
966+
verticalArrangement = Arrangement.spacedBy(4.dp),
967+
modifier = Modifier,
968+
) {
969+
for (rowIndex in 0 until rowCount) {
970+
val (section, rowElement) = rowData.getOrNull(rowIndex) ?: break
971+
var emptyCell = false
972+
Surface(
973+
tonalElevation = when (section) {
974+
"thead" -> 3.dp
975+
"tbody" -> 0.dp
976+
"tfoot" -> 1.dp
977+
else -> 0.dp
978+
},
979+
) {
980+
rowElement.children()
981+
.filter { it.tagName() in setOf("th", "td") }
982+
.elementAtOrNullWithSpans(colIndex)
983+
?.let { colElement ->
984+
withParagraph {
985+
withStyle(
986+
if (colElement.tagName() == "th") {
987+
SpanStyle(fontWeight = FontWeight.Bold)
988+
} else {
989+
null
990+
},
991+
) {
992+
appendTextChildren(
993+
colElement.childNodes(),
994+
baseUrl = baseUrl,
995+
onLinkClick = onLinkClick,
996+
keyHolder = keyHolder,
997+
)
998+
}
997999
}
9981000
}
999-
}
1000-
emptyCell = !render()
1001-
}
1002-
if (emptyCell) {
1003-
// An empty cell looks better if it has some height - but don't want
1004-
// the surface because having one space wide surface is weird
1005-
append(' ')
1006-
render()
1001+
emptyCell = !render()
1002+
}
1003+
if (emptyCell) {
1004+
// An empty cell looks better if it has some height - but don't want
1005+
// the surface because having one space wide surface is weird
1006+
append(' ')
1007+
render()
1008+
}
10071009
}
10081010
}
10091011
}

app/src/test/java/com/nononsenseapps/feeder/ui/compose/text/HtmlToComposableKtTest.kt

-14
This file was deleted.

0 commit comments

Comments
 (0)