mirror of
https://github.com/LiveFastEatTrashRaccoon/RaccoonForLemmy.git
synced 2025-02-04 03:37:34 +01:00
fix: IllegalStateException when opening SortBottomSheet (#931)
This commit is contained in:
parent
541cf7255d
commit
fd13d1c7b8
@ -1,5 +1,6 @@
|
||||
package com.github.diegoberaldin.raccoonforlemmy.core.commonui.modals
|
||||
|
||||
import androidx.compose.animation.Crossfade
|
||||
import androidx.compose.foundation.Image
|
||||
import androidx.compose.foundation.layout.Arrangement
|
||||
import androidx.compose.foundation.layout.Box
|
||||
@ -20,14 +21,14 @@ import androidx.compose.material3.Icon
|
||||
import androidx.compose.material3.MaterialTheme
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.runtime.mutableStateOf
|
||||
import androidx.compose.runtime.remember
|
||||
import androidx.compose.runtime.setValue
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.graphics.ColorFilter
|
||||
import cafe.adriel.voyager.core.screen.Screen
|
||||
import cafe.adriel.voyager.navigator.LocalNavigator
|
||||
import cafe.adriel.voyager.navigator.Navigator
|
||||
import cafe.adriel.voyager.navigator.currentOrThrow
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.appearance.theme.Spacing
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.commonui.components.BottomSheetHeader
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.l10n.LocalXmlStrings
|
||||
@ -41,6 +42,12 @@ import com.github.diegoberaldin.raccoonforlemmy.domain.lemmy.data.toInt
|
||||
import com.github.diegoberaldin.raccoonforlemmy.domain.lemmy.data.toReadableName
|
||||
import com.github.diegoberaldin.raccoonforlemmy.domain.lemmy.data.toSortType
|
||||
|
||||
private sealed interface SortBottomSheetLevel {
|
||||
data object Main : SortBottomSheetLevel
|
||||
|
||||
data object Top : SortBottomSheetLevel
|
||||
}
|
||||
|
||||
class SortBottomSheet(
|
||||
private val values: List<Int>,
|
||||
private val comments: Boolean = false,
|
||||
@ -62,29 +69,49 @@ class SortBottomSheet(
|
||||
),
|
||||
verticalArrangement = Arrangement.spacedBy(Spacing.s),
|
||||
) {
|
||||
Navigator(
|
||||
var level by remember { mutableStateOf<SortBottomSheetLevel>(SortBottomSheetLevel.Main) }
|
||||
Crossfade(
|
||||
targetState = level,
|
||||
) { currentLevel ->
|
||||
when (currentLevel) {
|
||||
SortBottomSheetLevel.Main -> {
|
||||
SortBottomSheetMain(
|
||||
values = values,
|
||||
expandTop = expandTop,
|
||||
comments = comments,
|
||||
defaultForCommunity = defaultForCommunity,
|
||||
screenKey = screenKey,
|
||||
),
|
||||
onNavigateUp = {
|
||||
level = SortBottomSheetLevel.Top
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
SortBottomSheetLevel.Top -> {
|
||||
SortBottomSheetTop(
|
||||
comments = comments,
|
||||
defaultForCommunity = defaultForCommunity,
|
||||
screenKey = screenKey,
|
||||
onNavigateDown = {
|
||||
level = SortBottomSheetLevel.Main
|
||||
},
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
internal class SortBottomSheetMain(
|
||||
private val comments: Boolean,
|
||||
private val values: List<Int>,
|
||||
private val expandTop: Boolean = false,
|
||||
private val defaultForCommunity: Boolean = false,
|
||||
private val screenKey: String?,
|
||||
) : Screen {
|
||||
@Composable
|
||||
override fun Content() {
|
||||
val navigator = LocalNavigator.currentOrThrow
|
||||
@Composable
|
||||
private fun SortBottomSheetMain(
|
||||
comments: Boolean,
|
||||
values: List<Int>,
|
||||
expandTop: Boolean = false,
|
||||
defaultForCommunity: Boolean = false,
|
||||
screenKey: String?,
|
||||
onNavigateUp: () -> Unit,
|
||||
) {
|
||||
val navigationCoordinator = remember { getNavigationCoordinator() }
|
||||
val notificationCenter = remember { getNotificationCenter() }
|
||||
Column {
|
||||
@ -106,13 +133,7 @@ internal class SortBottomSheetMain(
|
||||
.onClick(
|
||||
onClick = {
|
||||
if (sortValue == SortType.Top.Generic && expandTop) {
|
||||
navigator.push(
|
||||
SortBottomSheetTop(
|
||||
comments = comments,
|
||||
defaultForCommunity = defaultForCommunity,
|
||||
screenKey = screenKey,
|
||||
),
|
||||
)
|
||||
onNavigateUp()
|
||||
} else {
|
||||
val event =
|
||||
if (comments) {
|
||||
@ -161,12 +182,12 @@ internal class SortBottomSheetMain(
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
internal class SortBottomSheetTop(
|
||||
private val comments: Boolean,
|
||||
private val values: List<Int> =
|
||||
@Composable
|
||||
private fun SortBottomSheetTop(
|
||||
comments: Boolean,
|
||||
values: List<Int> =
|
||||
listOf(
|
||||
SortType.Top.PastHour,
|
||||
SortType.Top.Past6Hours,
|
||||
@ -176,12 +197,10 @@ internal class SortBottomSheetTop(
|
||||
SortType.Top.Month,
|
||||
SortType.Top.Year,
|
||||
).map { it.toInt() },
|
||||
private val defaultForCommunity: Boolean = false,
|
||||
private val screenKey: String?,
|
||||
) : Screen {
|
||||
@Composable
|
||||
override fun Content() {
|
||||
val navigator = LocalNavigator.currentOrThrow
|
||||
defaultForCommunity: Boolean = false,
|
||||
screenKey: String?,
|
||||
onNavigateDown: () -> Unit,
|
||||
) {
|
||||
val navigationCoordinator = remember { getNavigationCoordinator() }
|
||||
val notificationCenter = remember { getNotificationCenter() }
|
||||
|
||||
@ -198,7 +217,7 @@ internal class SortBottomSheetTop(
|
||||
Modifier
|
||||
.onClick(
|
||||
onClick = {
|
||||
navigator.pop()
|
||||
onNavigateDown()
|
||||
},
|
||||
),
|
||||
imageVector = Icons.AutoMirrored.Default.ArrowBack,
|
||||
@ -258,5 +277,4 @@ internal class SortBottomSheetTop(
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user