Fix media viewer not being dismissed with reduced motion enabled (#5555)
This is also called 'remove animations' in some Android versions. It seems like the associated coroutine dispatcher never allows the `delay` calls to complete, or maybe they take too long and the coroutine is cancelled before they finish.
This commit is contained in:
parent
597c9b473a
commit
b90dc081b7
2 changed files with 26 additions and 1 deletions
|
|
@ -16,7 +16,9 @@ import androidx.compose.runtime.getValue
|
|||
import androidx.compose.runtime.rememberUpdatedState
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.graphics.Color
|
||||
import androidx.compose.ui.platform.LocalContext
|
||||
import io.element.android.compound.theme.ElementTheme
|
||||
import io.element.android.libraries.androidutils.system.areAnimationsEnabled
|
||||
import kotlinx.coroutines.delay
|
||||
import me.saket.telephoto.ExperimentalTelephotoApi
|
||||
import me.saket.telephoto.flick.FlickToDismiss
|
||||
|
|
@ -34,10 +36,14 @@ fun MediaViewerFlickToDismiss(
|
|||
content: @Composable BoxScope.() -> Unit,
|
||||
) {
|
||||
val flickState = rememberFlickToDismissState(dismissThresholdRatio = 0.1f, rotateOnDrag = false)
|
||||
val context = LocalContext.current
|
||||
DismissFlickEffects(
|
||||
flickState = flickState,
|
||||
onDismissing = { animationDuration ->
|
||||
delay(animationDuration / 3)
|
||||
// Only add the delay if an animation should be played, otherwise `onDismiss` will never be called
|
||||
if (context.areAnimationsEnabled()) {
|
||||
delay(animationDuration / 3)
|
||||
}
|
||||
onDismiss()
|
||||
},
|
||||
onDragging = onDragging,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue