Use non-nullable floats to fix random crashes on some systems

This commit is contained in:
Syer10
2021-07-09 22:03:53 -04:00
parent 078e34ca0a
commit c9279a92de
5 changed files with 7 additions and 9 deletions

View File

@@ -48,7 +48,7 @@ fun KtorImage(
BoxWithConstraints {
val drawable: MutableState<ImageBitmap?> = remember { mutableStateOf(null) }
val loading: MutableState<Boolean> = remember { mutableStateOf(true) }
val progress: MutableState<Float?> = remember { mutableStateOf(null) }
val progress: MutableState<Float> = remember { mutableStateOf(0.0F) }
val error: MutableState<String?> = remember { mutableStateOf(null) }
DisposableEffect(imageUrl) {
val handler = CoroutineExceptionHandler { _, throwable ->

View File

@@ -22,7 +22,7 @@ fun LoadingScreen(
isLoading: Boolean = true,
modifier: Modifier = Modifier.fillMaxSize(),
/*@FloatRange(from = 0.0, to = 1.0)*/
progress: Float? = null,
progress: Float = 0.0F,
errorMessage: String? = null,
retryMessage: String = "Retry",
retry: (() -> Unit)? = null
@@ -33,10 +33,8 @@ fun LoadingScreen(
val size = remember(maxHeight, maxWidth) {
min(maxHeight, maxWidth) / 2
}
// Workaround for random `Cannot round NaN value.` exception
val floatProgress = progress ?: 0F
if (progress != null) {
CircularProgressIndicator(floatProgress, Modifier.align(Alignment.Center).size(size))
if (progress != 0.0F) {
CircularProgressIndicator(progress, Modifier.align(Alignment.Center).size(size))
} else {
CircularProgressIndicator(Modifier.align(Alignment.Center).size(size))
}

View File

@@ -224,7 +224,7 @@ fun ReaderMenu(chapterIndex: Int, mangaId: Long, setHotkeys: (List<KeyboardShort
fun ReaderImage(
imageIndex: Int,
drawable: ImageBitmap?,
progress: Float?,
progress: Float,
status: ReaderPage.Status,
error: String?,
imageModifier: Modifier = Modifier.fillMaxSize(),

View File

@@ -112,7 +112,7 @@ class TachideskPageLoader(
ReaderPage(
it,
MutableStateFlow(null),
MutableStateFlow(null),
MutableStateFlow(0.0F),
MutableStateFlow(ReaderPage.Status.QUEUE),
MutableStateFlow(null)
)

View File

@@ -12,7 +12,7 @@ import kotlinx.coroutines.flow.MutableStateFlow
data class ReaderPage(
val index: Int,
val bitmap: MutableStateFlow<ImageBitmap?>,
val progress: MutableStateFlow<Float?>,
val progress: MutableStateFlow<Float>,
val status: MutableStateFlow<Status>,
val error: MutableStateFlow<String?>
) {