mirror of
https://github.com/vitorpamplona/amethyst.git
synced 2026-08-08 23:54:39 +00:00
NEEDS testing:
Swapped the local var orientation by remember { mutableStateOf(...) } for an explicit MutableState: we now create orientationState = remember(firstImage) { mutableStateOf(...) }, update it with
orientationState.value = …, and return orientationState.value.
This commit is contained in:
@@ -35,10 +35,8 @@ import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.foundation.layout.width
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.LaunchedEffect
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.runtime.mutableStateOf
|
||||
import androidx.compose.runtime.remember
|
||||
import androidx.compose.runtime.setValue
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.layout.ContentScale
|
||||
import androidx.compose.ui.unit.Dp
|
||||
@@ -90,13 +88,11 @@ private fun MediaUrlImage?.resolveOrientation(
|
||||
|
||||
@Composable
|
||||
private fun rememberFirstImageOrientation(firstImage: MediaUrlImage?): FirstImageOrientation {
|
||||
val initialOrientation =
|
||||
val orientationState =
|
||||
remember(firstImage) {
|
||||
firstImage.resolveOrientation(ASPECT_RATIO, PORTRAIT_ASPECT_RATIO)
|
||||
mutableStateOf(firstImage.resolveOrientation(ASPECT_RATIO, PORTRAIT_ASPECT_RATIO))
|
||||
}
|
||||
|
||||
var orientation by remember(firstImage) { mutableStateOf(initialOrientation) }
|
||||
|
||||
LaunchedEffect(firstImage) {
|
||||
if (firstImage == null) return@LaunchedEffect
|
||||
if (firstImage.dim?.hasSize() == true) return@LaunchedEffect
|
||||
@@ -104,14 +100,14 @@ private fun rememberFirstImageOrientation(firstImage: MediaUrlImage?): FirstImag
|
||||
while (isActive) {
|
||||
val ratio = firstImage.resolvedAspectRatio()
|
||||
if (ratio != null && ratio > 0f) {
|
||||
orientation = FirstImageOrientation(ratio, ratio >= 1f)
|
||||
orientationState.value = FirstImageOrientation(ratio, ratio >= 1f)
|
||||
break
|
||||
}
|
||||
delay(200)
|
||||
}
|
||||
}
|
||||
|
||||
return orientation
|
||||
return orientationState.value
|
||||
}
|
||||
|
||||
@Composable
|
||||
|
||||
Reference in New Issue
Block a user