Skip to content

Commit

Permalink
Removed isAnimating property of ComposableNavigationContainer, simp…
Browse files Browse the repository at this point in the history
…lified ComposableDestinationAnimations by removing the transition state as a property.
  • Loading branch information
isaac-udy committed Sep 16, 2024
1 parent a423926 commit b4d1a66
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 20 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
* Fixed a bug where managed flows (`registerForFlowResult`) that launch embedded flows (`deliverResultFromPush/Present`) were not correctly handling the result of the embedded flow
* Added `FragmentSharedElements` to provide a way to define shared elements for Fragment navigation, including a compatibility layer for Composable NavigationDestinations that want to use AndroidViews as shared elements with Fragments. See `FragmentsWithSharedElements.kt` in the test application for examples of how to use `FragmentSharedElements`
* Added `acceptFromFlow` as a `NavigationContainerFilter` for use on screens that build managed flows using `registerForFlowResult`. This filter will cause the `NavigationContainer` to only accept instructions that have been created as part a managed flow, and will reject instructions that are not part of a managed flow.
* Removed `isAnimating` from `ComposableNavigationContainer`, as it was unused internally, did not appear to be useful for external use cases, and was complicating Compose animation code. If this functionality *was* important to your use case, please create a Github issue to discuss your use case.

* ⚠️ Updated result channel identifiers in preparation for Kotlin 2.0 ⚠️
* Kotlin 2.0 changes the way that lambdas are compiled, which has implications for `registerForNavigationResult` and how result channels are uniquely identified. Activites, Fragments, Composables and ViewModels that use `by registerForNavigationResult` directly will not be affected by this change. However, if you are creating result channels inside of other objects, such as delegates, helper objects, or extension functions, you should verify that these cases continue to work as expected. It is not expected that there will be issues, but if this does result in bugs in your application, please raise them on the Enro GitHub repository.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import android.os.Bundle
import androidx.compose.material.ExperimentalMaterialApi
import androidx.compose.runtime.Composable
import androidx.compose.runtime.DisposableEffect
import androidx.compose.runtime.derivedStateOf
import androidx.compose.runtime.getValue
import androidx.compose.runtime.key
import androidx.compose.runtime.movableContentOf
Expand Down Expand Up @@ -71,10 +70,6 @@ public class ComposableNavigationContainer internal constructor(
override val isVisible: Boolean
get() = true

public val isAnimating: Boolean by derivedStateOf {
destinationOwners.any { it.animations.isAnimating }
}

private val onDestroyLifecycleObserver = LifecycleEventObserver { _, event ->
if (event != Lifecycle.Event.ON_DESTROY) return@LifecycleEventObserver
destroy()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,7 @@ import androidx.compose.material.ExperimentalMaterialApi
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.NonSkippableComposable
import androidx.compose.runtime.derivedStateOf
import androidx.compose.runtime.getValue
import androidx.compose.runtime.key
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
Expand All @@ -37,20 +35,11 @@ internal class ComposableDestinationAnimations(
private val owner: ComposableDestinationOwner,
) {
private var currentAnimationEvent by mutableStateOf<AnimationEvent>(AnimationEvent.SnapTo(false))
private val visibilityState = SeekableTransitionState(false)

internal var animationOverride by mutableStateOf<NavigationAnimation.Composable?>(null)

internal lateinit var enterExitTransition: Transition<EnterExitState>

val isAnimating by derivedStateOf {
when (currentAnimationEvent) {
is AnimationEvent.AnimateTo -> visibilityState.targetState != visibilityState.currentState
is AnimationEvent.SnapTo -> false
is AnimationEvent.Seek -> true
}
}

internal fun setAnimationEvent(event: AnimationEvent) {
currentAnimationEvent = event
}
Expand All @@ -59,10 +48,12 @@ internal class ComposableDestinationAnimations(
@Composable
@NonSkippableComposable
fun Animate(content: @Composable () -> Unit) {
val targetState = visibilityState.targetState
val instruction = owner.instruction
val parentContainer = owner.parentContainer

val visibilityState = remember(instruction.instructionId) { SeekableTransitionState(false) }
val targetState = visibilityState.targetState

val animation = remember(
instruction,
targetState,
Expand Down Expand Up @@ -99,9 +90,7 @@ internal class ComposableDestinationAnimations(
currentAnimationEvent = AnimationEvent.SnapTo(event.visible)
}
}
val visibleTransition = key(instruction.instructionId) {
rememberTransition(visibilityState, "ComposableDestination Visibility")
}
val visibleTransition = rememberTransition(visibilityState, "ComposableDestination Visibility")
animation.Animate(
visible = visibleTransition,
) {
Expand Down

0 comments on commit b4d1a66

Please sign in to comment.