Skip to content

Commit

Permalink
Added disableInputDuringAnimation flag
Browse files Browse the repository at this point in the history
  • Loading branch information
arkivanov committed Nov 16, 2022
1 parent 4ad2cd0 commit 4260e82
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import com.arkivanov.decompose.router.stack.ChildStack

@ExperimentalDecomposeApi
internal class DefaultStackAnimation<C : Any, T : Any>(
private val disableInputDuringAnimation: Boolean,
private val selector: (child: Child.Created<C, T>, otherChild: Child.Created<C, T>, direction: Direction) -> StackAnimator?,
) : StackAnimation<C, T> {

Expand Down Expand Up @@ -54,8 +55,8 @@ internal class DefaultStackAnimation<C : Any, T : Any>(
}

// A workaround until https://issuetracker.google.com/issues/214231672.
// Normally only the exiting child be disabled.
if (items.size > 1) {
// Normally only the exiting child should be disabled.
if (disableInputDuringAnimation && (items.size > 1)) {
Overlay(modifier = Modifier.matchParentSize())
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

package com.arkivanov.decompose.extensions.compose.jetbrains.stack.animation

import androidx.compose.foundation.layout.Box
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import com.arkivanov.decompose.Child
Expand Down Expand Up @@ -50,21 +49,28 @@ inline fun <C : Any, T : Any> StackAnimation(
/**
* Creates an implementation of [StackAnimation] that allows different [StackAnimator]s.
*
* @param disableInputDuringAnimation disables input and touch events while animating, default value is `true`.
* @param selector provides a [StackAnimator] for current [Child], other [Child] and [Direction].
*/
@ExperimentalDecomposeApi
fun <C : Any, T : Any> stackAnimation(
disableInputDuringAnimation: Boolean = true,
selector: (child: Child.Created<C, T>, otherChild: Child.Created<C, T>, direction: Direction) -> StackAnimator?,
): StackAnimation<C, T> =
DefaultStackAnimation(selector)
DefaultStackAnimation(
disableInputDuringAnimation = disableInputDuringAnimation,
selector = selector,
)

/**
* Creates an implementation of [StackAnimation] with the provided [StackAnimator].
*
* @param animator a [StackAnimator] to be used for animation, default is [fade].
* @param disableInputDuringAnimation disables input and touch events while animating, default value is `true`.
*/
@ExperimentalDecomposeApi
fun <C : Any, T : Any> stackAnimation(animator: StackAnimator = fade()): StackAnimation<C, T> =
stackAnimation { _, _, _ -> animator }


fun <C : Any, T : Any> stackAnimation(
animator: StackAnimator = fade(),
disableInputDuringAnimation: Boolean = true,
): StackAnimation<C, T> =
stackAnimation(disableInputDuringAnimation = disableInputDuringAnimation) { _, _, _ -> animator }
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import com.arkivanov.decompose.router.stack.ChildStack

@ExperimentalDecomposeApi
internal class DefaultStackAnimation<C : Any, T : Any>(
private val disableInputDuringAnimation: Boolean,
private val selector: (child: Child.Created<C, T>, otherChild: Child.Created<C, T>, direction: Direction) -> StackAnimator?,
) : StackAnimation<C, T> {

Expand Down Expand Up @@ -54,8 +55,8 @@ internal class DefaultStackAnimation<C : Any, T : Any>(
}

// A workaround until https://issuetracker.google.com/issues/214231672.
// Normally only the exiting child be disabled.
if (items.size > 1) {
// Normally only the exiting child should be disabled.
if (disableInputDuringAnimation && (items.size > 1)) {
Overlay(modifier = Modifier.matchParentSize())
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

package com.arkivanov.decompose.extensions.compose.jetpack.stack.animation

import androidx.compose.foundation.layout.Box
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import com.arkivanov.decompose.Child
Expand Down Expand Up @@ -50,19 +49,28 @@ inline fun <C : Any, T : Any> StackAnimation(
/**
* Creates an implementation of [StackAnimation] that allows different [StackAnimator]s.
*
* @param disableInputDuringAnimation disables input and touch events while animating, default value is `true`.
* @param selector provides a [StackAnimator] for current [Child], other [Child] and [Direction].
*/
@ExperimentalDecomposeApi
fun <C : Any, T : Any> stackAnimation(
disableInputDuringAnimation: Boolean = true,
selector: (child: Child.Created<C, T>, otherChild: Child.Created<C, T>, direction: Direction) -> StackAnimator?,
): StackAnimation<C, T> =
DefaultStackAnimation(selector)
DefaultStackAnimation(
disableInputDuringAnimation = disableInputDuringAnimation,
selector = selector,
)

/**
* Creates an implementation of [StackAnimation] with the provided [StackAnimator].
*
* @param animator a [StackAnimator] to be used for animation, default is [fade].
* @param disableInputDuringAnimation disables input and touch events while animating, default value is `true`.
*/
@ExperimentalDecomposeApi
fun <C : Any, T : Any> stackAnimation(animator: StackAnimator = fade()): StackAnimation<C, T> =
stackAnimation { _, _, _ -> animator }
fun <C : Any, T : Any> stackAnimation(
animator: StackAnimator = fade(),
disableInputDuringAnimation: Boolean = true,
): StackAnimation<C, T> =
stackAnimation(disableInputDuringAnimation = disableInputDuringAnimation) { _, _, _ -> animator }

0 comments on commit 4260e82

Please sign in to comment.