Skip to content

Commit

Permalink
Merge pull request #409 from arkivanov/fix-back-gesture-1
Browse files Browse the repository at this point in the history
Wrap the child content slot in PredictiveBackAnimation with movableContentOf
  • Loading branch information
arkivanov authored Jun 8, 2023
2 parents e5db98d + 2549ea2 commit a94b71a
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import androidx.compose.runtime.DisposableEffect
import androidx.compose.runtime.MutableState
import androidx.compose.runtime.getValue
import androidx.compose.runtime.key
import androidx.compose.runtime.movableContentOf
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
Expand Down Expand Up @@ -75,6 +76,15 @@ private class PredictiveBackAnimation<C : Any, T : Any>(

@Composable
override fun invoke(stack: ChildStack<C, T>, modifier: Modifier, content: @Composable (child: Child.Created<C, T>) -> Unit) {
val childContent =
remember(content) {
movableContentOf<Child.Created<C, T>> { child ->
key(child.configuration) {
content(child)
}
}
}

val currentKey = remember { Holder(value = 0) }

var items: List<Item<C, T>> by rememberMutableStateWithLatest(
Expand All @@ -89,7 +99,7 @@ private class PredictiveBackAnimation<C : Any, T : Any>(
animation(
stack = item.stack,
modifier = Modifier.fillMaxSize().then(item.progressData?.toProgressModifier() ?: Modifier),
content = content,
content = childContent,
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import androidx.compose.runtime.DisposableEffect
import androidx.compose.runtime.MutableState
import androidx.compose.runtime.getValue
import androidx.compose.runtime.key
import androidx.compose.runtime.movableContentOf
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
Expand Down Expand Up @@ -77,6 +78,15 @@ private class PredictiveBackAnimation<C : Any, T : Any>(

@Composable
override fun invoke(stack: ChildStack<C, T>, modifier: Modifier, content: @Composable (child: Child.Created<C, T>) -> Unit) {
val childContent =
remember(content) {
movableContentOf<Child.Created<C, T>> { child ->
key(child.configuration) {
content(child)
}
}
}

val currentKey = remember { Holder(value = 0) }

var items: List<Item<C, T>> by rememberMutableStateWithLatest(
Expand All @@ -91,7 +101,7 @@ private class PredictiveBackAnimation<C : Any, T : Any>(
animation(
stack = item.stack,
modifier = Modifier.fillMaxSize().then(item.progressData?.toProgressModifier() ?: Modifier),
content = content,
content = childContent,
)
}
}
Expand Down

0 comments on commit a94b71a

Please sign in to comment.