feat(InstallOptions): make screen scrollable
This commit is contained in:
parent
abefe7c37c
commit
40fd1b262c
2 changed files with 57 additions and 3 deletions
|
|
@ -1,6 +1,8 @@
|
|||
package com.aliucord.manager.ui.screens.installopts
|
||||
|
||||
import androidx.compose.foundation.layout.*
|
||||
import androidx.compose.foundation.rememberScrollState
|
||||
import androidx.compose.foundation.verticalScroll
|
||||
import androidx.compose.material3.*
|
||||
import androidx.compose.runtime.*
|
||||
import androidx.compose.ui.Alignment
|
||||
|
|
@ -22,8 +24,7 @@ import com.aliucord.manager.ui.screens.installopts.components.InstallOptionsAppB
|
|||
import com.aliucord.manager.ui.screens.installopts.components.PackageNameState
|
||||
import com.aliucord.manager.ui.screens.installopts.components.options.SwitchInstallOption
|
||||
import com.aliucord.manager.ui.screens.installopts.components.options.TextInstallOption
|
||||
import com.aliucord.manager.ui.util.DiscordVersion
|
||||
import com.aliucord.manager.ui.util.thenIf
|
||||
import com.aliucord.manager.ui.util.*
|
||||
|
||||
class InstallOptionsScreen(
|
||||
private val supportedVersion: DiscordVersion = DiscordVersion.None,
|
||||
|
|
@ -39,9 +40,10 @@ class InstallOptionsScreen(
|
|||
topBar = { InstallOptionsAppBar() },
|
||||
) { paddingValues ->
|
||||
Column(
|
||||
verticalArrangement = Arrangement.spacedBy(20.dp),
|
||||
verticalArrangement = Arrangement.spacedByLastAtBottom(20.dp),
|
||||
modifier = Modifier
|
||||
.fillMaxSize()
|
||||
.verticalScroll(rememberScrollState())
|
||||
.padding(paddingValues)
|
||||
.padding(horizontal = 20.dp, vertical = 10.dp)
|
||||
) {
|
||||
|
|
|
|||
|
|
@ -0,0 +1,52 @@
|
|||
package com.aliucord.manager.ui.util
|
||||
|
||||
import androidx.compose.foundation.layout.Arrangement
|
||||
import androidx.compose.runtime.Immutable
|
||||
import androidx.compose.runtime.Stable
|
||||
import androidx.compose.ui.unit.*
|
||||
import kotlin.math.min
|
||||
|
||||
/**
|
||||
* Arranges all the elements with [spacing] except for the last element which is
|
||||
* spaced to the very bottom of the viewable component.
|
||||
*
|
||||
* ref: https://stackoverflow.com/a/69196765/13964629
|
||||
*/
|
||||
@Immutable
|
||||
class ArrangementLastAtBottom(
|
||||
override val spacing: Dp = 0.dp,
|
||||
) : Arrangement.Vertical {
|
||||
override fun Density.arrange(
|
||||
totalSize: Int,
|
||||
sizes: IntArray,
|
||||
outPositions: IntArray,
|
||||
) {
|
||||
if (sizes.isEmpty()) return
|
||||
|
||||
val spacingPx = spacing.roundToPx()
|
||||
var occupied = 0
|
||||
var lastSpace = 0
|
||||
|
||||
sizes.forEachIndexed { index, size ->
|
||||
if (index == sizes.lastIndex) {
|
||||
outPositions[index] = totalSize - size
|
||||
} else {
|
||||
outPositions[index] = min(occupied, totalSize - size)
|
||||
}
|
||||
|
||||
lastSpace = min(spacingPx, totalSize - outPositions[index] - size)
|
||||
occupied = outPositions[index] + size + lastSpace
|
||||
}
|
||||
|
||||
occupied -= lastSpace
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Arranges all the elements vertically with [space] except for the last element
|
||||
* which is drawn at the very bottom of the viewable bounds of the component.
|
||||
*/
|
||||
@Stable
|
||||
@Suppress("UnusedReceiverParameter")
|
||||
fun Arrangement.spacedByLastAtBottom(space: Dp) =
|
||||
ArrangementLastAtBottom(space)
|
||||
Loading…
Add table
Reference in a new issue