Sfoglia il codice sorgente

fix: RecentBooksRow 中 bookUrl 为 null 时 key 重复导致崩溃

HapeLee 4 mesi fa
parent
commit
7182b6e0e1

+ 2 - 1
app/src/main/java/io/legado/app/ui/main/home/HomeScreen.kt

@@ -27,6 +27,7 @@ import androidx.compose.foundation.layout.size
 import androidx.compose.foundation.layout.width
 import androidx.compose.foundation.layout.width
 import androidx.compose.foundation.lazy.LazyRow
 import androidx.compose.foundation.lazy.LazyRow
 import androidx.compose.foundation.lazy.items
 import androidx.compose.foundation.lazy.items
+import androidx.compose.foundation.lazy.itemsIndexed
 import androidx.compose.foundation.pager.HorizontalPager
 import androidx.compose.foundation.pager.HorizontalPager
 import androidx.compose.foundation.pager.rememberPagerState
 import androidx.compose.foundation.pager.rememberPagerState
 import androidx.compose.foundation.rememberScrollState
 import androidx.compose.foundation.rememberScrollState
@@ -994,7 +995,7 @@ private fun RecentBooksRow(
         modifier = modifier,
         modifier = modifier,
         horizontalArrangement = Arrangement.spacedBy(8.dp),
         horizontalArrangement = Arrangement.spacedBy(8.dp),
     ) {
     ) {
-        items(books, key = { it.bookUrl.orEmpty() }) { book ->
+        itemsIndexed(books, key = { index, book -> "${book.bookUrl}_$index" }) { index, book ->
             RecentHistoryBookCard(
             RecentHistoryBookCard(
                 book = book,
                 book = book,
                 onClick = { book.bookUrl?.let(onBookClick) },
                 onClick = { book.bookUrl?.let(onBookClick) },